@emulsify/cli 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +96 -16
  2. package/dist/handlers/componentCreate.js +37 -5
  3. package/dist/handlers/componentEjectTemplates.js +317 -0
  4. package/dist/handlers/componentInstall.js +54 -14
  5. package/dist/handlers/hofs/withEmulsifySystem.js +1 -1
  6. package/dist/handlers/init.js +75 -32
  7. package/dist/handlers/systemCreate.js +222 -0
  8. package/dist/handlers/systemDetach.js +50 -0
  9. package/dist/handlers/systemInstall.js +339 -101
  10. package/dist/index.js +67 -110
  11. package/dist/lib/log.js +12 -9
  12. package/dist/lib/rootHelp.js +321 -0
  13. package/dist/lib/terminalColors.js +10 -0
  14. package/dist/util/cache/cloneIntoCache.js +2 -4
  15. package/dist/util/deriveComponentNames.js +5 -0
  16. package/dist/util/deriveCustomElementTagName.js +25 -0
  17. package/dist/util/fs/writeToJsonFile.js +21 -5
  18. package/dist/util/getGitRepoNameFromUrl.js +47 -3
  19. package/dist/util/getNonInteractiveGitEnvironment.js +7 -0
  20. package/dist/util/getRepositoryLatestTag.js +17 -2
  21. package/dist/util/platform/platformCompatibility.js +18 -7
  22. package/dist/util/project/componentTemplates/buildComponentArtifacts.js +121 -0
  23. package/dist/util/project/componentTemplates/index.js +5 -0
  24. package/dist/util/project/componentTemplates/react.js +20 -0
  25. package/dist/util/project/componentTemplates/reactStories.js +18 -0
  26. package/dist/util/project/componentTemplates/scss.js +2 -3
  27. package/dist/util/project/componentTemplates/sdcStories.js +2 -2
  28. package/dist/util/project/componentTemplates/stories.js +2 -2
  29. package/dist/util/project/componentTemplates/twig.js +2 -3
  30. package/dist/util/project/componentTemplates/webComponent.js +49 -0
  31. package/dist/util/project/componentTemplates/webComponentStories.js +19 -0
  32. package/dist/util/project/componentTypes.js +71 -0
  33. package/dist/util/project/generateComponent.js +139 -101
  34. package/dist/util/project/renderTemplate.js +24 -4
  35. package/dist/util/project/resolveComponentTemplate.js +24 -11
  36. package/dist/util/project/unsetEmulsifyConfig.js +16 -0
  37. package/dist/util/prompt/index.js +25 -0
  38. package/dist/util/system/buildSystemInstallPlan.js +53 -0
  39. package/dist/util/system/buildSystemScaffold.js +99 -0
  40. package/dist/util/system/getAvailableSystems.js +4 -0
  41. package/package.json +2 -2
@@ -1,71 +1,146 @@
1
- import { select, confirm } from '@inquirer/prompts';
1
+ import { confirm, input, select } from '@inquirer/prompts';
2
2
  import { promises as fs } from 'fs';
3
3
  import { dirname } from 'path';
4
4
  import { pathExists, remove } from 'fs-extra';
5
- import { cyan, green, bold, yellow } from 'colorette';
6
5
  import log from '../../lib/log.js';
6
+ import getTerminalColors from '../../lib/terminalColors.js';
7
7
  import findFileInCurrentPath from '../fs/findFileInCurrentPath.js';
8
8
  import safeResolveWithin from '../fs/safeResolveWithin.js';
9
9
  import { EMULSIFY_PROJECT_CONFIG_FILE } from '../../lib/constants.js';
10
10
  import deriveComponentNames from '../deriveComponentNames.js';
11
+ import { assertValidCustomElementTagName, deriveCustomElementTagName, } from '../deriveCustomElementTagName.js';
12
+ import { isInteractiveTerminal, runPrompt } from '../prompt/index.js';
13
+ import { componentTypeFromLegacyFormat, getAvailableComponentTypes, getComponentFormatLabel, getCompatibleFormatToken, MISSING_COMPONENT_DIRECTORY_ERROR, MISSING_COMPONENT_TYPE_ERROR, normalizeComponentType, projectDeclaresEmulsifyCore, } from './componentTypes.js';
11
14
  import resolveComponentTemplate from './resolveComponentTemplate.js';
12
- import { buildScssTemplate, buildSdcJsTemplate, buildSdcMetadataTemplate, buildSdcStoriesTemplate, buildStoriesTemplate, buildTwigTemplate, buildYmlTemplate, } from './componentTemplates/index.js';
13
- const COMPONENT_FORMAT_CHOICES = [
14
- {
15
- name: `${bold('Default')} (Standard Emulsify component)`,
16
- value: 'default',
17
- },
18
- {
19
- name: `${bold('SDC')} (Single Directory Component for Drupal)`,
20
- value: 'sdc',
21
- },
22
- ];
23
- const COMPONENT_FORMATS = ['default', 'sdc'];
24
- function getComponentFormat(format) {
25
- const normalizedFormat = format.toLowerCase();
26
- if (!COMPONENT_FORMATS.includes(normalizedFormat)) {
27
- throw new Error(`Invalid component format "${format}". Supported formats are: default, sdc.`);
28
- }
29
- return normalizedFormat;
15
+ import { buildComponentArtifacts } from './componentTemplates/index.js';
16
+ const TYPE_LABELS = {
17
+ twig: 'Twig',
18
+ 'twig-sdc': 'Twig SDC',
19
+ react: 'React',
20
+ 'web-component': 'Web Component',
21
+ };
22
+ function resolveProvidedComponentType(options) {
23
+ if (options.type) {
24
+ const type = normalizeComponentType(options.type);
25
+ if (options.format) {
26
+ log('warn', `The --format option is deprecated and was ignored because --type ${type} was also provided.`);
27
+ }
28
+ return type;
29
+ }
30
+ if (!options.format)
31
+ return undefined;
32
+ const type = componentTypeFromLegacyFormat(options.format);
33
+ log('warn', `The --format option is deprecated; use --type ${type} instead.`);
34
+ return type;
35
+ }
36
+ async function promptForComponentType(projectRoot, platform, bold, cyan) {
37
+ const hasEmulsifyCore = await projectDeclaresEmulsifyCore(projectRoot);
38
+ const availableTypes = getAvailableComponentTypes(platform, hasEmulsifyCore);
39
+ if (platform !== 'drupal') {
40
+ log('info', 'Twig SDC is available only for Drupal projects, so it is not shown.');
41
+ }
42
+ if (!hasEmulsifyCore) {
43
+ log('info', "React and Web Component are not shown because @emulsify/core is not declared in this project's package.json. Pass --type explicitly to scaffold either one anyway.");
44
+ }
45
+ if (availableTypes.length === 1) {
46
+ log('info', 'Using Twig, the only detected compatible component type.');
47
+ return 'twig';
48
+ }
49
+ const descriptions = {
50
+ twig: 'Twig template with YAML data and a Storybook story',
51
+ 'twig-sdc': 'Drupal Single Directory Component built with Twig',
52
+ react: "React component using Storybook's standard React support",
53
+ 'web-component': 'Custom element rendered by @emulsify/core',
54
+ };
55
+ return select({
56
+ message: cyan('Choose the component type:'),
57
+ choices: availableTypes.map((type) => ({
58
+ name: bold(TYPE_LABELS[type]),
59
+ value: type,
60
+ description: descriptions[type],
61
+ })),
62
+ });
30
63
  }
31
- export default async function generateComponent(variant, componentName, options = {}) {
32
- const { filename, className, camelName, snakeName, humanName } = deriveComponentNames(componentName);
33
- const canPrompt = process.stdin.isTTY === true;
34
- const providedFormat = options.format
35
- ? getComponentFormat(options.format)
36
- : undefined;
64
+ function validateCustomElementTagName(value) {
65
+ try {
66
+ assertValidCustomElementTagName(value.trim());
67
+ return true;
68
+ }
69
+ catch (error) {
70
+ return error.message;
71
+ }
72
+ }
73
+ export default async function generateComponent(variant, projectConfig, componentName, options = {}) {
74
+ const { bold, cyan, green, yellow } = getTerminalColors();
75
+ const { filename, className, camelName, pascalName, snakeName, humanName } = deriveComponentNames(componentName);
76
+ const providedType = resolveProvidedComponentType(options);
77
+ const force = options.force === true || options.yes === true;
37
78
  let directory = options.directory || '';
38
79
  const path = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
39
80
  if (!path) {
40
81
  throw new Error('Unable to find an Emulsify project to create the component into.');
41
82
  }
42
83
  const projectRoot = dirname(path);
43
- const format = providedFormat
44
- ? providedFormat
45
- : canPrompt
46
- ? await select({
47
- message: cyan('Choose the component format:'),
48
- choices: COMPONENT_FORMAT_CHOICES,
49
- })
50
- : (() => {
51
- throw new Error('Component format is required in non-interactive mode. Pass --format default or --format sdc.');
52
- })();
53
- if (!directory) {
54
- if (!canPrompt) {
55
- throw new Error('Component directory is required in non-interactive mode. Pass --directory <directory>.');
84
+ const type = providedType
85
+ ? providedType
86
+ : await runPrompt({
87
+ prompt: () => promptForComponentType(projectRoot, projectConfig.project.platform, bold, cyan),
88
+ nonInteractive: { error: MISSING_COMPONENT_TYPE_ERROR },
89
+ });
90
+ if (options.tagName !== undefined && type !== 'web-component') {
91
+ throw new Error('The --tag-name option can only be used with --type web-component.');
92
+ }
93
+ if (providedType &&
94
+ (type === 'react' || type === 'web-component') &&
95
+ !(await projectDeclaresEmulsifyCore(projectRoot))) {
96
+ log('warn', `@emulsify/core was not detected in this project's package.json. The generated ${type} component may require installing @emulsify/core before its Storybook story can run.`);
97
+ }
98
+ let tagName = '';
99
+ if (type === 'web-component') {
100
+ if (options.tagName !== undefined) {
101
+ tagName = options.tagName.trim();
102
+ }
103
+ else {
104
+ const derivedTagName = deriveCustomElementTagName(filename, projectConfig.project.machineName);
105
+ tagName = (await runPrompt({
106
+ prompt: () => input({
107
+ message: cyan('Custom element tag name:'),
108
+ default: derivedTagName,
109
+ validate: validateCustomElementTagName,
110
+ }),
111
+ nonInteractive: { value: derivedTagName },
112
+ })).trim();
113
+ }
114
+ try {
115
+ assertValidCustomElementTagName(tagName);
116
+ }
117
+ catch (error) {
118
+ if (options.tagName === undefined && !isInteractiveTerminal()) {
119
+ throw new SyntaxError(`${error.message} Pass --tag-name <tag-name> to provide a valid custom element name.`);
120
+ }
121
+ throw error;
56
122
  }
57
- directory = await select({
58
- message: cyan('Choose a directory for the new component:'),
59
- choices: variant.structureImplementations.map((structure) => ({
60
- name: structure.name,
61
- value: structure.name,
62
- })),
123
+ }
124
+ if (!directory) {
125
+ directory = await runPrompt({
126
+ prompt: () => select({
127
+ message: cyan('Choose a directory for the new component:'),
128
+ choices: variant.structureImplementations.map((structure) => ({
129
+ name: structure.name,
130
+ value: structure.name,
131
+ })),
132
+ }),
133
+ nonInteractive: {
134
+ error: MISSING_COMPONENT_DIRECTORY_ERROR,
135
+ },
63
136
  });
64
137
  }
65
138
  const structure = variant.structureImplementations.find(({ name }) => name === directory);
66
139
  if (!structure) {
67
140
  throw new Error(`The structure (${directory}) specified within the component ${componentName} is invalid.`);
68
141
  }
142
+ const directoryTitle = `${directory.charAt(0).toUpperCase()}${directory.slice(1)}`;
143
+ const formatLabel = getComponentFormatLabel(type);
69
144
  const parentPath = safeResolveWithin(projectRoot, structure.directory, 'Component structure directory', { allowRoot: true });
70
145
  const parentExists = await pathExists(parentPath);
71
146
  const destination = safeResolveWithin(projectRoot, [structure.directory, filename], 'Component destination');
@@ -74,59 +149,21 @@ export default async function generateComponent(variant, componentName, options
74
149
  filename,
75
150
  className,
76
151
  camelName,
152
+ pascalName,
77
153
  snakeName,
78
154
  humanName,
79
155
  directory,
80
- format,
156
+ directoryTitle,
157
+ format: getCompatibleFormatToken(type),
158
+ formatLabel,
159
+ type,
160
+ tagName,
81
161
  };
82
- const formatLabel = format.toUpperCase();
83
- const sharedArtifacts = [
84
- {
85
- logicalName: 'component.twig',
86
- destinationName: `${filename}.twig`,
87
- build: () => buildTwigTemplate(filename, snakeName, className, formatLabel),
88
- },
89
- {
90
- logicalName: 'component.scss',
91
- destinationName: `${filename}.scss`,
92
- build: () => buildScssTemplate(className, formatLabel),
93
- },
94
- ];
95
- const formatArtifacts = format === 'sdc'
96
- ? [
97
- {
98
- logicalName: 'component.component.yml',
99
- destinationName: `${filename}.component.yml`,
100
- build: () => buildSdcMetadataTemplate(snakeName, humanName),
101
- },
102
- {
103
- logicalName: 'component.js',
104
- destinationName: `${filename}.js`,
105
- build: () => buildSdcJsTemplate(camelName, filename, className),
106
- },
107
- {
108
- logicalName: 'component.stories.js',
109
- destinationName: `${filename}.stories.js`,
110
- build: () => buildSdcStoriesTemplate(camelName, filename, snakeName, humanName, directory),
111
- },
112
- ]
113
- : [
114
- {
115
- logicalName: 'component.yml',
116
- destinationName: `${filename}.yml`,
117
- build: () => buildYmlTemplate(snakeName, humanName),
118
- },
119
- {
120
- logicalName: 'component.stories.js',
121
- destinationName: `${filename}.stories.js`,
122
- build: () => buildStoriesTemplate(camelName, filename, humanName, directory),
123
- },
124
- ];
125
- const artifacts = [...sharedArtifacts, ...formatArtifacts];
162
+ const artifacts = buildComponentArtifacts(type, templateVars);
126
163
  const artifactDestinations = artifacts.map((artifact) => safeResolveWithin(projectRoot, [structure.directory, filename, artifact.destinationName], 'Component file destination'));
127
164
  if (options.dryRun) {
128
165
  const realRunAction = componentExists
129
- ? options.yes
166
+ ? force
130
167
  ? 'replace the existing component directory'
131
168
  : 'prompt before replacing the existing component directory'
132
169
  : 'create the component directory';
@@ -135,7 +172,7 @@ export default async function generateComponent(variant, componentName, options
135
172
  .join('\n');
136
173
  return log('info', [
137
174
  `Dry run: component create "${filename}"`,
138
- `Format: ${format}`,
175
+ `Type: ${type}`,
139
176
  `Directory: ${directory}`,
140
177
  `Structure path: ${structure.directory}`,
141
178
  `Parent directory: ${parentPath} (${parentExists ? 'exists' : 'would be created'})`,
@@ -151,13 +188,14 @@ export default async function generateComponent(variant, componentName, options
151
188
  await fs.mkdir(parentPath, { recursive: true });
152
189
  }
153
190
  if (componentExists) {
154
- const shouldReplace = options.yes ||
155
- (canPrompt
156
- ? await confirm({
157
- message: yellow(`The component "${humanName}" already exists in ${structure.directory}. Would you like to replace it?`),
158
- default: false,
159
- })
160
- : false);
191
+ const shouldReplace = await runPrompt({
192
+ prompt: () => confirm({
193
+ message: yellow(`The component "${humanName}" already exists in ${structure.directory}. Would you like to replace it?`),
194
+ default: false,
195
+ }),
196
+ nonInteractive: { value: false },
197
+ accept: { when: force, value: true },
198
+ });
161
199
  if (!shouldReplace) {
162
200
  return log('info', `Component creation canceled.`);
163
201
  }
@@ -165,9 +203,9 @@ export default async function generateComponent(variant, componentName, options
165
203
  }
166
204
  await fs.mkdir(destination, { recursive: true });
167
205
  for (const [index, artifact] of artifacts.entries()) {
168
- const templateFile = (await resolveComponentTemplate(projectRoot, format, artifact.logicalName, templateVars)) ?? artifact.build();
206
+ const templateFile = (await resolveComponentTemplate(projectRoot, type, artifact.logicalName, templateVars)) ?? artifact.contents;
169
207
  const artifactDestination = artifactDestinations[index];
170
208
  await fs.writeFile(artifactDestination, templateFile);
171
209
  }
172
- return log('success', `${bold(green('Success!'))} The ${bold(cyan(componentName))} component (${yellow(format.toUpperCase())}) has been created in ${bold(directory)}.`);
210
+ return log('success', `${bold(green('Success!'))} The ${bold(cyan(componentName))} component (${yellow(TYPE_LABELS[type].toUpperCase())}) has been created in ${bold(directory)}.`);
173
211
  }
@@ -1,14 +1,34 @@
1
1
  import log from '../../lib/log.js';
2
- const tokenPattern = /{{\s*([A-Za-z][A-Za-z0-9]*)\s*}}/g;
2
+ const tokenPattern = /__EMULSIFY_([A-Za-z][A-Za-z0-9_]*?)__/g;
3
+ const legacyTokenPattern = /{{\s*([A-Za-z][A-Za-z0-9]*)\s*}}/g;
4
+ const legacyTokenNames = new Set([
5
+ 'filename',
6
+ 'className',
7
+ 'camelName',
8
+ 'snakeName',
9
+ 'humanName',
10
+ 'directory',
11
+ 'format',
12
+ ]);
13
+ export function componentTemplateToken(name) {
14
+ return `__EMULSIFY_${name}__`;
15
+ }
3
16
  export default function renderTemplate(template, vars) {
17
+ return renderTokens(template, vars, tokenPattern);
18
+ }
19
+ export function renderLegacyTemplate(template, vars) {
20
+ return renderTokens(template, vars, legacyTokenPattern, legacyTokenNames);
21
+ }
22
+ function renderTokens(template, vars, pattern, supportedTokens) {
4
23
  const warnedTokens = new Set();
5
- return template.replace(tokenPattern, (match, token) => {
6
- if (token in vars) {
24
+ return template.replace(pattern, (match, token) => {
25
+ if ((!supportedTokens || supportedTokens.has(token)) &&
26
+ Object.hasOwn(vars, token)) {
7
27
  return vars[token];
8
28
  }
9
29
  if (!warnedTokens.has(token)) {
10
30
  warnedTokens.add(token);
11
- log('warn', `Unknown component template token "{{ ${token} }}" left unchanged.`);
31
+ log('warn', `Unknown component template token "${match}" left unchanged.`);
12
32
  }
13
33
  return match;
14
34
  });
@@ -3,16 +3,29 @@ import { join } from 'path';
3
3
  import { pathExists } from 'fs-extra';
4
4
  import log from '../../lib/log.js';
5
5
  import { EMULSIFY_PROJECT_TEMPLATES_FOLDER } from '../../lib/constants.js';
6
- import renderTemplate from './renderTemplate.js';
7
- export default async function resolveComponentTemplate(projectRoot, format, logicalName, vars) {
8
- const templatePath = join(projectRoot, EMULSIFY_PROJECT_TEMPLATES_FOLDER, format, logicalName);
9
- if (!(await pathExists(templatePath))) {
10
- return null;
6
+ import renderTemplate, { renderLegacyTemplate, } from './renderTemplate.js';
7
+ const LEGACY_TEMPLATE_DIRECTORIES = {
8
+ twig: 'default',
9
+ 'twig-sdc': 'sdc',
10
+ };
11
+ export default async function resolveComponentTemplate(projectRoot, type, logicalName, vars) {
12
+ const directories = [type];
13
+ const legacyDirectory = LEGACY_TEMPLATE_DIRECTORIES[type];
14
+ if (legacyDirectory)
15
+ directories.push(legacyDirectory);
16
+ for (const directory of directories) {
17
+ const templatePath = join(projectRoot, EMULSIFY_PROJECT_TEMPLATES_FOLDER, directory, logicalName);
18
+ if (!(await pathExists(templatePath))) {
19
+ continue;
20
+ }
21
+ const template = await fs.readFile(templatePath, 'utf8');
22
+ if (template.trim() === '') {
23
+ log('warn', `Component template override "${templatePath}" is empty; using the built-in template instead.`);
24
+ return null;
25
+ }
26
+ return directory === legacyDirectory
27
+ ? renderLegacyTemplate(template, vars)
28
+ : renderTemplate(template, vars);
11
29
  }
12
- const template = await fs.readFile(templatePath, 'utf8');
13
- if (template.trim() === '') {
14
- log('warn', `Component template override "${templatePath}" is empty; using the built-in template instead.`);
15
- return null;
16
- }
17
- return renderTemplate(template, vars);
30
+ return null;
18
31
  }
@@ -0,0 +1,16 @@
1
+ import { EMULSIFY_PROJECT_CONFIG_FILE } from '../../lib/constants.js';
2
+ import findFileInCurrentPath from '../fs/findFileInCurrentPath.js';
3
+ import writeToJsonFile from '../fs/writeToJsonFile.js';
4
+ import getEmulsifyConfig from './getEmulsifyConfig.js';
5
+ export default async function unsetEmulsifyConfig(...keys) {
6
+ const path = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
7
+ const existingConfig = await getEmulsifyConfig();
8
+ if (!path || !existingConfig) {
9
+ throw new Error(`Unable to remove values from ${EMULSIFY_PROJECT_CONFIG_FILE} because you are not in an Emulsify project`);
10
+ }
11
+ const updatedConfig = { ...existingConfig };
12
+ for (const key of keys) {
13
+ delete updatedConfig[key];
14
+ }
15
+ await writeToJsonFile(path, updatedConfig);
16
+ }
@@ -0,0 +1,25 @@
1
+ import CliError from '../../lib/CliError.js';
2
+ export function isInteractiveTerminal() {
3
+ return process.stdin.isTTY === true;
4
+ }
5
+ export function requireInteractiveTerminal(nonInteractiveError) {
6
+ if (!isInteractiveTerminal()) {
7
+ throw new CliError(nonInteractiveError);
8
+ }
9
+ }
10
+ export function isExitPromptError(error) {
11
+ return error instanceof Error && error.name === 'ExitPromptError';
12
+ }
13
+ export async function runPrompt({ prompt, nonInteractive, accept, }) {
14
+ if (accept?.when === true) {
15
+ return accept.value;
16
+ }
17
+ if ('error' in nonInteractive) {
18
+ requireInteractiveTerminal(nonInteractive.error);
19
+ return prompt();
20
+ }
21
+ if (!isInteractiveTerminal()) {
22
+ return nonInteractive.value;
23
+ }
24
+ return prompt();
25
+ }
@@ -0,0 +1,53 @@
1
+ import { dirname, relative, sep } from 'path';
2
+ import safeResolveWithin from '../fs/safeResolveWithin.js';
3
+ import buildComponentDependencyList from '../project/buildComponentDependencyList.js';
4
+ import { getComponentDestination } from '../project/installComponentFromCache.js';
5
+ function toProjectRelativeDisplayPath(projectRoot, destination) {
6
+ const displayPath = relative(projectRoot, destination).split(sep).join('/');
7
+ return displayPath || '.';
8
+ }
9
+ function uniqueInOrder(values) {
10
+ return [...new Set(values)];
11
+ }
12
+ export function selectSystemComponents(variantConf, installAll) {
13
+ if (installAll) {
14
+ return [...variantConf.components];
15
+ }
16
+ const requiredComponents = variantConf.components.filter(({ required }) => required === true);
17
+ const selectedNames = uniqueInOrder(requiredComponents.flatMap(({ name }) => buildComponentDependencyList(variantConf.components, name)));
18
+ return selectedNames.map((name) => variantConf.components.find((component) => component.name === name));
19
+ }
20
+ function assertSystemStructure(systemConf, component) {
21
+ if (!systemConf.structure.some(({ name }) => name === component.structure)) {
22
+ throw new Error(`The structure (${component.structure}) specified within the component ${component.name} is invalid.`);
23
+ }
24
+ }
25
+ export default function buildSystemInstallPlan(systemConf, variantConf, installAll, projectConfigPath) {
26
+ const projectRoot = dirname(projectConfigPath);
27
+ const requiredComponents = variantConf.components.filter(({ required }) => required === true);
28
+ const components = selectSystemComponents(variantConf, installAll);
29
+ const componentParentDestinations = uniqueInOrder(components.map((component) => {
30
+ assertSystemStructure(systemConf, component);
31
+ return toProjectRelativeDisplayPath(projectRoot, dirname(getComponentDestination(variantConf, component.name, projectConfigPath)));
32
+ }));
33
+ const directories = variantConf.directories || [];
34
+ const files = variantConf.files || [];
35
+ const directoryAssetDestinations = uniqueInOrder(directories.map(({ destinationPath }) => {
36
+ const destination = safeResolveWithin(projectRoot, destinationPath, 'General asset destination');
37
+ return `${toProjectRelativeDisplayPath(projectRoot, destination)}/`;
38
+ }));
39
+ const fileAssetDestinations = uniqueInOrder(files.map(({ destinationPath }) => toProjectRelativeDisplayPath(projectRoot, safeResolveWithin(projectRoot, destinationPath, 'General asset destination'))));
40
+ const directoryAssetCount = directories.length;
41
+ const fileAssetCount = files.length;
42
+ return {
43
+ components,
44
+ requiredComponentCount: requiredComponents.length,
45
+ totalComponentCount: variantConf.components.length,
46
+ componentParentDestinations,
47
+ directoryAssetDestinations,
48
+ fileAssetDestinations,
49
+ directoryAssetCount,
50
+ fileAssetCount,
51
+ totalAssetCount: directoryAssetCount + fileAssetCount,
52
+ };
53
+ }
@@ -0,0 +1,99 @@
1
+ import { buildScssTemplate, buildStoriesTemplate, buildTwigTemplate, buildYmlTemplate, } from '../project/componentTemplates/index.js';
2
+ const COMPONENT_STRUCTURE_NAME = 'components';
3
+ const EXAMPLE_COMPONENT_NAME = 'example-card';
4
+ const EXAMPLE_COMPONENT_CAMEL_NAME = 'exampleCard';
5
+ const EXAMPLE_COMPONENT_SNAKE_NAME = 'example_card';
6
+ const EXAMPLE_COMPONENT_HUMAN_NAME = 'Example Card';
7
+ const STANDARD_FORMAT_LABEL = 'STANDARD';
8
+ const COMPONENT_STRUCTURE_TITLE = 'Components';
9
+ export function buildSystemDefinition({ name, platform, homepage, repository, }) {
10
+ return {
11
+ name,
12
+ homepage,
13
+ repository,
14
+ structure: [
15
+ {
16
+ name: COMPONENT_STRUCTURE_NAME,
17
+ description: 'Reusable components provided by this system',
18
+ },
19
+ ],
20
+ variants: [
21
+ {
22
+ platform,
23
+ structureImplementations: [
24
+ {
25
+ name: COMPONENT_STRUCTURE_NAME,
26
+ directory: COMPONENT_STRUCTURE_NAME,
27
+ },
28
+ ],
29
+ components: [
30
+ {
31
+ name: EXAMPLE_COMPONENT_NAME,
32
+ structure: COMPONENT_STRUCTURE_NAME,
33
+ description: 'Example card included with the generated system',
34
+ required: true,
35
+ },
36
+ ],
37
+ },
38
+ ],
39
+ };
40
+ }
41
+ function buildReadme({ name, platform, homepage, repository, }) {
42
+ return `# ${name}
43
+
44
+ An [Emulsify](https://www.emulsify.info/) component system targeting \`${platform}\`.
45
+
46
+ ## Included component
47
+
48
+ - \`example-card\`: a standard Emulsify component ready to customize or replace.
49
+
50
+ ## Use this system
51
+
52
+ 1. Replace the example metadata and component with your system's content.
53
+ 2. Replace the placeholder in \`LICENSE\` with the license for this system.
54
+ 3. Commit the repository and create a stable tag.
55
+ 4. Install that tag from an Emulsify project:
56
+
57
+ \`\`\`bash
58
+ emulsify system install --repository ${repository} --checkout <tag>
59
+ \`\`\`
60
+
61
+ Homepage: ${homepage}
62
+ `;
63
+ }
64
+ export default function buildSystemScaffold(options) {
65
+ const exampleComponentDirectory = `${COMPONENT_STRUCTURE_NAME}/${EXAMPLE_COMPONENT_NAME}`;
66
+ return {
67
+ systemConfig: buildSystemDefinition(options),
68
+ files: [
69
+ {
70
+ path: 'README.md',
71
+ contents: buildReadme(options),
72
+ },
73
+ {
74
+ path: '.gitignore',
75
+ contents: '.DS_Store\nnode_modules/\n',
76
+ },
77
+ {
78
+ path: 'LICENSE',
79
+ contents: 'Choose a license for this system and replace this placeholder before distribution.\n',
80
+ },
81
+ {
82
+ path: `${exampleComponentDirectory}/${EXAMPLE_COMPONENT_NAME}.twig`,
83
+ contents: buildTwigTemplate(EXAMPLE_COMPONENT_NAME, EXAMPLE_COMPONENT_SNAKE_NAME, EXAMPLE_COMPONENT_NAME, STANDARD_FORMAT_LABEL),
84
+ },
85
+ {
86
+ path: `${exampleComponentDirectory}/${EXAMPLE_COMPONENT_NAME}.scss`,
87
+ contents: buildScssTemplate(EXAMPLE_COMPONENT_NAME, STANDARD_FORMAT_LABEL),
88
+ },
89
+ {
90
+ path: `${exampleComponentDirectory}/${EXAMPLE_COMPONENT_NAME}.yml`,
91
+ contents: buildYmlTemplate(EXAMPLE_COMPONENT_SNAKE_NAME, EXAMPLE_COMPONENT_HUMAN_NAME),
92
+ },
93
+ {
94
+ path: `${exampleComponentDirectory}/${EXAMPLE_COMPONENT_NAME}.stories.js`,
95
+ contents: buildStoriesTemplate(EXAMPLE_COMPONENT_CAMEL_NAME, EXAMPLE_COMPONENT_NAME, EXAMPLE_COMPONENT_HUMAN_NAME, COMPONENT_STRUCTURE_TITLE),
96
+ },
97
+ ],
98
+ };
99
+ }
@@ -2,11 +2,15 @@ export default async function getAvailableSystems() {
2
2
  return [
3
3
  {
4
4
  name: 'compound',
5
+ label: 'Compound',
6
+ description: 'Accessible, tested components. Drupal, WordPress, plain.',
5
7
  repository: 'https://github.com/emulsify-ds/compound.git',
6
8
  platforms: ['none', 'drupal', 'wordpress'],
7
9
  },
8
10
  {
9
11
  name: 'emulsify-ui-kit',
12
+ label: 'Emulsify UI Kit',
13
+ description: 'Broader design-system starter kit.',
10
14
  repository: 'https://github.com/emulsify-ds/emulsify-ui-kit.git',
11
15
  platforms: ['none', 'drupal', 'wordpress'],
12
16
  },
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@emulsify/cli",
3
3
  "productName": "Emulsify CLI",
4
- "version": "2.3.1",
5
- "description": "Command line interface for Emulsify",
4
+ "version": "2.4.1",
5
+ "description": "Build and use component systems in Drupal, WordPress, or standalone front ends.",
6
6
  "repository": "git@github.com:emulsify-ds/emulsify-cli.git",
7
7
  "author": "Patrick Coffey <patrickcoffey48@gmail.com>",
8
8
  "license": "GPL-2.0",