Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0bb1e6b
feat: add locale command
chrisberthe Jan 23, 2025
591abc8
consolidate object-related utilities
chrisberthe Jan 24, 2025
70bd5c3
add support for t_with_fallback references
chrisberthe Jan 25, 2025
83cb32e
add flags to locales clean command
chrisberthe Jan 25, 2025
781df7b
get sync command working
chrisberthe Jan 25, 2025
e6c7ebb
chore: update clean command text
chrisberthe Jan 26, 2025
7e9d420
refactor: minor changes in translations.ts
chrisberthe Jan 26, 2025
e7b757a
refactor: sync, locales, and translations files
chrisberthe Jan 26, 2025
2e5aaa6
refactor: remove logging in sync (for now)
chrisberthe Jan 26, 2025
168d0ee
chore: capitalization FTW
chrisberthe Jan 26, 2025
8f7b046
chore: remove unnecessary code
chrisberthe Jan 26, 2025
e51606c
refactor: locale sync mode
chrisberthe Jan 26, 2025
10df25e
refactor: add format flag for syncing locales
chrisberthe Jan 26, 2025
7846161
chore: move sortObjectKeys to objects.ts
chrisberthe Jan 26, 2025
179c8b0
refactor: replace schema and storefront flags with target flag
chrisberthe Jan 26, 2025
8404082
remove allowNo from clean flag
chrisberthe Jan 30, 2025
6c1583d
refactor: replaceContent method, wasn't preserving locale object stru…
chrisberthe Feb 24, 2025
afdaf3b
chore: rename methods in locales.ts
chrisberthe Feb 24, 2025
0d4e323
refactor: replaceTranslations method
chrisberthe Feb 24, 2025
f6dd71a
refactor: update sync mode option names for clarity
chrisberthe Feb 24, 2025
bf26e17
refactor: rename sync mode to just mode
chrisberthe Feb 24, 2025
674714c
refactor: change the default for sync mode for safety
chrisberthe Feb 24, 2025
8552fec
chore: update sync flag descriptions
chrisberthe Feb 24, 2025
42df8a7
chore: only clean after syncing
chrisberthe Feb 25, 2025
b187e29
chore: ensure target flag works without clean flag in sync
chrisberthe Feb 25, 2025
74eef65
chore: ensure last line in locale files are preserved on write
chrisberthe Feb 25, 2025
8194b61
chore: fix formatting in dev.ts and git.ts
chrisberthe Feb 25, 2025
41d4fc1
chore: baseline tests for locale command
chrisberthe Feb 25, 2025
c06608a
chore: update unused_schema key to unused for consistency
chrisberthe Feb 25, 2025
1839669
refactor: format flag for clean command
chrisberthe Feb 25, 2025
d84cbad
chore: add format tests for sync command
chrisberthe Feb 25, 2025
12c8e11
chore: rename variables in locale tests for consistency
chrisberthe Feb 25, 2025
0b802c5
chore: remove unnecessary backupDir reference in clean.test.ts
chrisberthe Feb 25, 2025
07b0a23
chore: ensure we're testing for t_with_fallback references
chrisberthe Feb 25, 2025
9a56e56
chore: use locale fixture data to test for added keys
chrisberthe Feb 26, 2025
434e173
fix: ensure missing keys are added in add-missing and add-and-overrid…
chrisberthe Feb 26, 2025
b1c441e
refactor: standardize locale options and centralize types
chrisberthe Feb 26, 2025
e072f30
refactor: remove translations.ts
chrisberthe Feb 26, 2025
c9a00f4
chore: locale method in logical order
chrisberthe Feb 26, 2025
409e5c7
chore: rename some locale methods
chrisberthe Feb 26, 2025
203fdd9
chore: add checks to see if folders/files exist
chrisberthe Feb 26, 2025
91006f4
chore: update README.md
chrisberthe Feb 26, 2025
b18b111
chore: minor formatting and add docs to import/template-map command
chrisberthe Feb 26, 2025
bc411b9
chore: remove '(default)' from flags, oclif does this already
chrisberthe Feb 26, 2025
d4879b5
chore: fix regression in bd66d39
chrisberthe Feb 26, 2025
4a284f0
chore: rename methods in locales.ts
chrisberthe Feb 26, 2025
3360b74
chore: rename more methods in locales.ts
chrisberthe Feb 26, 2025
9e66488
chore: update README.md
chrisberthe Feb 26, 2025
7b56cc4
fix: dynamic translation key handling for prefixed keys
chrisberthe Feb 26, 2025
2c249b7
fix: dynamic translation key with prefixes and add tests
chrisberthe Feb 26, 2025
bef40b0
chore: move and rename writeJsonFile to files.ts
chrisberthe Feb 27, 2025
8406078
chore: rename locales-dir to locales-source, amongst other things
chrisberthe Feb 27, 2025
720a2c3
chore: update README.md
chrisberthe Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 106 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ You'll need to ensure you have the following installed on your local development
### Installation

Install the Shopify CLI plugin:

```bash
shopify plugins install plugin-theme-component
```


## List of commands

<!-- commands -->
Expand All @@ -36,6 +36,8 @@ shopify plugins install plugin-theme-component
* [`shopify theme component map THEMEDIR [COMPONENTSELECTOR]`](#shopify-theme-component-map-themedir-componentselector)
* [`shopify theme generate import-map [THEMEDIR]`](#shopify-theme-generate-import-map-themedir)
* [`shopify theme generate template-map [THEMEDIR]`](#shopify-theme-generate-template-map-themedir)
* [`shopify theme locale clean [THEMEDIR]`](#shopify-theme-locale-clean-themedir)
* [`shopify theme locale sync [THEMEDIR]`](#shopify-theme-locale-sync-themedir)

## `shopify theme component`

Expand Down Expand Up @@ -66,7 +68,7 @@ ARGUMENTS
THEMEDIR [default: .] path to theme directory

FLAGS
-q, --[no-]quiet suppress non-essential output
-q, --[no-]quiet Suppress non-essential output

DESCRIPTION
Remove unused component files in a theme
Expand All @@ -89,8 +91,8 @@ ARGUMENTS
THEMEDIR path to theme directory

FLAGS
-n, --collection-name=<value> name of the component collection
-v, --collection-version=<value> version of the component collection
-n, --collection-name=<value> Name of the component collection
-v, --collection-version=<value> Version of the component collection

DESCRIPTION
Copy files from a component collection into a theme
Expand All @@ -115,15 +117,15 @@ ARGUMENTS
COMPONENTSELECTOR [default: *] component name or names (comma-separated) or "*" for all components

FLAGS
-i, --generate-import-map generate import map
-m, --generate-template-map generate template map
-n, --collection-name=<value> name of the component collection
-s, --[no-]setup-files copy setup files to theme directory
-t, --theme-dir=<value> [default: https://github.com/archetype-themes/explorer] directory that contains
-i, --generate-import-map Generate import map
-m, --generate-template-map Generate template map
-n, --collection-name=<value> Name of the component collection
-s, --[no-]setup-files Copy setup files to theme directory
-t, --theme-dir=<value> [default: https://github.com/archetype-themes/explorer] Directory that contains
theme files for development
-v, --collection-version=<value> version of the component collection
-w, --[no-]watch watch for changes in theme and component directories
-y, --[no-]preview sync changes to theme directory
-v, --collection-version=<value> Version of the component collection
-w, --[no-]watch Watch for changes in theme and component directories
-y, --[no-]preview Sync changes to theme directory
--environment=<value> The environment to apply to the current command.
--host=<value> Set which network interface the web server listens on. The default value is
127.0.0.1.
Expand Down Expand Up @@ -160,8 +162,8 @@ ARGUMENTS
COMPONENTSELECTOR [default: *] component name or names (comma-separated) or "*" for all components

FLAGS
-n, --collection-name=<value> name of the component collection
-v, --collection-version=<value> version of the component collection
-n, --collection-name=<value> Name of the component collection
-v, --collection-version=<value> Version of the component collection

DESCRIPTION
Runs the map, copy, clean, and generate import-map commands in sequence
Expand Down Expand Up @@ -189,10 +191,10 @@ ARGUMENTS
COMPONENTSELECTOR [default: *] component name or names (comma-separated) or "*" for all components

FLAGS
-f, --ignore-conflicts ignore conflicts when mapping components
-n, --collection-name=<value> name of the component collection
-o, --ignore-overrides ignore overrides when mapping components
-v, --collection-version=<value> version of the component collection
-f, --ignore-conflicts Ignore conflicts when mapping components
-n, --collection-name=<value> Name of the component collection
-o, --ignore-overrides Ignore overrides when mapping components
-v, --collection-version=<value> Version of the component collection

DESCRIPTION
Generates or updates a component.manifest.json file with the component collection details and a file map
Expand All @@ -219,7 +221,7 @@ ARGUMENTS
THEMEDIR [default: .] path to theme directory

FLAGS
-q, --[no-]quiet suppress non-essential output
-q, --[no-]quiet Suppress non-essential output

DESCRIPTION
Generate an import map for JavaScript files in the assets directory
Expand All @@ -239,13 +241,96 @@ ARGUMENTS
THEMEDIR [default: .] path to theme directory

FLAGS
-q, --[no-]quiet suppress non-essential output
-q, --[no-]quiet Suppress non-essential output

DESCRIPTION
Generate a template map for component routes in the templates directory
```

_See code: [src/commands/theme/generate/template-map.ts](https://github.com/archetype-themes/plugin-theme-component/blob/v5.0.8/src/commands/theme/generate/template-map.ts)_

## `shopify theme locale clean [THEMEDIR]`

Remove unreferenced translations from theme locale files

```
USAGE
$ shopify theme locale clean [THEMEDIR] [--format] [--target all|schema|storefront]

ARGUMENTS
THEMEDIR [default: .] path to theme directory

FLAGS
--format Format locale files by sorting keys alphabetically
--target=<option> [default: all] Target locale files to process:
- all: Process all locale files
- schema: Process only schema translations (*.schema.json)
- storefront: Process only storefront translations
<options: all|schema|storefront>

DESCRIPTION
Remove unreferenced translations from theme locale files

EXAMPLES
$ shopify theme locale clean theme-directory

$ shopify theme locale clean theme-directory --target=schema

$ shopify theme locale clean theme-directory --target=storefront
```

_See code: [src/commands/theme/locale/clean.ts](https://github.com/archetype-themes/plugin-theme-component/blob/v5.0.8/src/commands/theme/locale/clean.ts)_

## `shopify theme locale sync [THEMEDIR]`

Sync theme locale files with source translations

```
USAGE
$ shopify theme locale sync [THEMEDIR] [-c] [--format] [-l <value>] [-m
add-missing|add-and-override|replace-existing] [--target all|schema|storefront]

ARGUMENTS
THEMEDIR [default: .] path to theme directory

FLAGS
-c, --clean
Remove unreferenced translations from theme locale files

-l, --locales-source=<value>
[default: https://github.com/archetype-themes/locales] Directory that contains a "locales" folder with locale files

-m, --mode=<option>
[default: add-missing] Sync mode for locale files (only translations used in the theme will be processed):
- add-missing: Only add new translations that do not exist in theme locale files
- add-and-override: Add new translations and override existing ones with source values
- replace-existing: Replace values of existing translations with source values
<options: add-missing|add-and-override|replace-existing>

--format
Format locale files by sorting keys alphabetically

--target=<option>
[default: all] Target locale files to process:
- all: Process all locale files
- schema: Process only schema translations (*.schema.json)
- storefront: Process only storefront translations
<options: all|schema|storefront>

DESCRIPTION
Sync theme locale files with source translations

EXAMPLES
$ shopify theme locale sync theme-directory

$ shopify theme locale sync theme-directory --clean

$ shopify theme locale sync theme-directory --clean --target=schema

$ shopify theme locale sync theme-directory --locales-source=path/to/directory
```

_See code: [src/commands/theme/locale/sync.ts](https://github.com/archetype-themes/plugin-theme-component/blob/v5.0.8/src/commands/theme/locale/sync.ts)_
<!-- commandsstop -->

## Contributing
Expand All @@ -259,6 +344,7 @@ If you notice a bug, or want to contribute to the codebase, feel free to do so i
If you already have the plugin installed via npm, you'll need to [uninstall](#uninstalling-the-plugin) the plugin before being able to develop the plugin locally.

Once this is done, follow these steps to ensure the Shopify CLI is running the local version of the plugin:

- `git clone https://github.com/archetype-themes/plugin-theme-component.git`
- `cd plugin-theme-component`
- `npm i`
Expand Down
6 changes: 3 additions & 3 deletions src/commands/theme/component/clean.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* This command cleans up component files in a theme directory.
*
*
* - Removes component files (snippets and assets) that are not listed in the component map
* - Ensures the theme directory only contains necessary component files
*/

import fs from 'node:fs'
import path from 'node:path'

import Args from '../../../utilities/args.js'
import Args from '../../../utilities/args.js'
import BaseCommand from '../../../utilities/base-command.js'
import { getManifest } from '../../../utilities/manifest.js'
import { getThemeNodes } from '../../../utilities/nodes.js'
Expand All @@ -30,7 +30,7 @@ export default class Clean extends BaseCommand {

public async run(): Promise<void> {
const themeDir = path.resolve(process.cwd(), this.args[Args.THEME_DIR])

const manifest = getManifest(path.join(themeDir, 'component.manifest.json'))
const themeNodes = await getThemeNodes(themeDir)

Expand Down
8 changes: 4 additions & 4 deletions src/commands/theme/component/copy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* This command copies component files into a theme directory.
*
*
* - Copies rendered component files (snippets and assets) into the theme directory
* - Updates the theme CLI config (shopify.theme.json) with the component collection details
*/

import fs from 'node:fs'
import path from 'node:path'

import Args from '../../../utilities/args.js'
import Args from '../../../utilities/args.js'
import BaseCommand from '../../../utilities/base-command.js'
import { copyFileIfChanged } from '../../../utilities/files.js';
import Flags from '../../../utilities/flags.js'
import { getManifest } from '../../../utilities/manifest.js'
import { getCollectionNodes } from '../../../utilities/nodes.js'
import { getNameFromPackageJson , getVersionFromPackageJson } from '../../../utilities/package-json.js'
import { getNameFromPackageJson, getVersionFromPackageJson } from '../../../utilities/package-json.js'

export default class Copy extends BaseCommand {
static override args = Args.getDefinitions([
Expand Down Expand Up @@ -52,7 +52,7 @@ export default class Copy extends BaseCommand {
if (!fs.existsSync(path.join(themeDir, 'component.manifest.json'))) {
this.error('Error: component.manifest.json file not found in the theme directory. Run "shopify theme component map" to generate a component.manifest.json file.');
}

const manifest = getManifest(path.join(themeDir, 'component.manifest.json'))
const componentNodes = await getCollectionNodes(currentDir)

Expand Down
25 changes: 12 additions & 13 deletions src/commands/theme/component/dev.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/**
* This command sets up a sandboxed development environment for components.
*
*
* - Removes any existing development directory
* - Copies dev theme files and rendered component files into a temporary development directory
* - Watches for changes to synchronize updates
* - Runs 'shopify theme dev' on the temporary development directory to preview your work
*/


import chokidar from 'chokidar'
import path from 'node:path'
import { URL } from 'node:url'

import Args from '../../../utilities/args.js'
import Args from '../../../utilities/args.js'
import BaseCommand from '../../../utilities/base-command.js'
import { cleanDir, syncFiles } from '../../../utilities/files.js'
import Flags from '../../../utilities/flags.js'
Expand Down Expand Up @@ -82,14 +81,14 @@ export default class Dev extends BaseCommand {
const themeDir = await this.getThemeDirectory(devDir)

this.log(`Building theme in ${devDir}...`)

const buildThemeParams: BuildThemeParams = {
componentSelector,
generateTemplateMap,
setupFiles,
themeDir
}

await this.buildTheme(devDir, buildThemeParams)

// Run shopify theme dev if preview is enabled
Expand All @@ -111,12 +110,12 @@ export default class Dev extends BaseCommand {
// Copy the component setup files if needed
if (params.setupFiles) {
await copySetupComponentFiles(
process.cwd(),
destination,
process.cwd(),
destination,
params.componentSelector
)
}

// Install the components
await Install.run([destination])

Expand Down Expand Up @@ -154,24 +153,24 @@ export default class Dev extends BaseCommand {
private async getThemeDirectory(devDir: string): Promise<string> {
if (this.flags[Flags.THEME_DIR].startsWith('http')) {
const url = new URL(this.flags[Flags.THEME_DIR])
const {host} = url
const { host } = url

if (host === 'github.com' || host.endsWith('.github.com')) {
const themeDir = path.join(devDir, '.repo')
this.log(`Cloning theme from ${this.flags[Flags.THEME_DIR]} into dev directory ${devDir}`)
await cloneTheme(this.flags[Flags.THEME_DIR], themeDir)
return themeDir
}

throw new Error(`Unsupported theme URL: ${this.flags[Flags.THEME_DIR]}`)
}

return path.resolve(process.cwd(), this.flags[Flags.THEME_DIR])
}

private setupWatcher(devDir: string, themeDir: string, componentsDir: string, buildThemeParams: BuildThemeParams): Promise<void> {
const watchDir = path.join(devDir, '.watch')

// Need to access chokidar as a default import so it can be mocked in tests
// eslint-disable-next-line import/no-named-as-default-member
const themeWatcher = chokidar.watch([themeDir, componentsDir], {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/theme/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default class Component extends Command {
} else {
this.log(
'\nWelcome To The Theme Component Plugin by Archetype Themes.' +
'\n\nUse the "--help" or "-h" flag to list available commands'
'\n\nUse the "--help" or "-h" flag to list available commands'
)
}
}
}
}
6 changes: 3 additions & 3 deletions src/commands/theme/component/install.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* This command installs component files into a theme directory.
*
*
* - Maps the components in the theme directory
* - Copies rendered component files (snippets and assets) into the theme directory
* - Cleans up unnecessary component files in the theme directory
* - Generates an import-map.liquid snippet file based on JS assets
*/

import Args from '../../../utilities/args.js'
import Args from '../../../utilities/args.js'
import BaseCommand from '../../../utilities/base-command.js'
import Flags from '../../../utilities/flags.js'
import GenerateImportMap from '../generate/import-map.js'
Expand Down Expand Up @@ -44,4 +44,4 @@ export default class Install extends BaseCommand {
await Clean.run([this.args[Args.THEME_DIR]!])
await GenerateImportMap.run([this.args[Args.THEME_DIR]!, '--quiet'])
}
}
}
Loading