@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
@@ -0,0 +1,25 @@
1
+ const reservedCustomElementNames = new Set([
2
+ 'annotation-xml',
3
+ 'color-profile',
4
+ 'font-face',
5
+ 'font-face-src',
6
+ 'font-face-uri',
7
+ 'font-face-format',
8
+ 'font-face-name',
9
+ 'missing-glyph',
10
+ ]);
11
+ const validCustomElementNameCharacterPattern = /^[-.0-9_a-z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
12
+ export function deriveCustomElementTagName(filename, projectMachineName) {
13
+ return filename.includes('-')
14
+ ? filename
15
+ : `${projectMachineName}-${filename}`;
16
+ }
17
+ export function assertValidCustomElementTagName(tagName) {
18
+ if (typeof tagName !== 'string' ||
19
+ !/^[a-z]/u.test(tagName) ||
20
+ !validCustomElementNameCharacterPattern.test(tagName.slice(1)) ||
21
+ !tagName.includes('-') ||
22
+ reservedCustomElementNames.has(tagName)) {
23
+ throw new SyntaxError(`Invalid custom element tag name "${String(tagName)}". Names must start with an ASCII lowercase letter, contain a hyphen, use browser-supported custom-element name characters, and must not be a reserved name.`);
24
+ }
25
+ }
@@ -1,12 +1,28 @@
1
1
  import { promises as fs } from 'fs';
2
- export default async function loadJsonFile(path, json) {
3
- const data = JSON.stringify(json, null, 2);
2
+ import { randomUUID } from 'crypto';
3
+ import { basename, dirname, join } from 'path';
4
+ function createTemporaryPath(path) {
5
+ return join(dirname(path), `.${basename(path)}.${process.pid}.${randomUUID()}.tmp`);
6
+ }
7
+ export default async function writeToJsonFile(path, json) {
8
+ const temporaryPath = createTemporaryPath(path);
4
9
  try {
5
- await fs.writeFile(path, data, {
10
+ await fs.writeFile(temporaryPath, JSON.stringify(json, null, 2), {
6
11
  encoding: 'utf-8',
12
+ flag: 'wx',
13
+ flush: true,
7
14
  });
15
+ await fs.rename(temporaryPath, path);
8
16
  }
9
- catch (e) {
10
- throw new Error(`Unable to write to ${path} with the given JSON: ${data}`);
17
+ catch (error) {
18
+ let cleanupMessage = '';
19
+ try {
20
+ await fs.rm(temporaryPath, { force: true });
21
+ }
22
+ catch (caughtCleanupError) {
23
+ const cleanupCause = String(caughtCleanupError);
24
+ cleanupMessage = ` Temporary-file cleanup also failed: ${cleanupCause}`;
25
+ }
26
+ throw new Error(`Unable to write JSON file at ${path}: ${String(error)}.${cleanupMessage}`, { cause: error });
11
27
  }
12
28
  }
@@ -1,8 +1,52 @@
1
+ import { existsSync } from 'fs';
2
+ import { basename, isAbsolute, resolve, win32 } from 'path';
3
+ const fileUriPattern = /^file:\/\//i;
4
+ const explicitRelativePathPattern = /^\.{1,2}(?:[\\/]|$)/;
5
+ const uriPattern = /^[a-z][a-z\d+.-]*:\/\//i;
6
+ const scpLikePattern = /^(?:[^@/\\\s]+@)?[^:/\\\s]+:.+/;
7
+ function isLocalRepository(repository) {
8
+ if (fileUriPattern.test(repository) ||
9
+ isAbsolute(repository) ||
10
+ win32.isAbsolute(repository) ||
11
+ explicitRelativePathPattern.test(repository)) {
12
+ return true;
13
+ }
14
+ if (uriPattern.test(repository) || scpLikePattern.test(repository)) {
15
+ return false;
16
+ }
17
+ return existsSync(repository);
18
+ }
19
+ function getLocalRepositoryName(repository) {
20
+ let name;
21
+ if (fileUriPattern.test(repository)) {
22
+ try {
23
+ const pathname = decodeURIComponent(new URL(repository).pathname);
24
+ name = basename(pathname.replace(/[\\/]+$/, ''));
25
+ }
26
+ catch {
27
+ return;
28
+ }
29
+ }
30
+ else if (win32.isAbsolute(repository) || repository.includes('\\')) {
31
+ name = win32.basename(repository.replace(/[\\/]+$/, ''));
32
+ }
33
+ else {
34
+ name = basename(resolve(repository));
35
+ }
36
+ return name.endsWith('.git') ? name.slice(0, -4) || undefined : name;
37
+ }
1
38
  export default function getGitRepoNameFromUrl(url) {
2
- const parts = url.split('/');
39
+ const repository = url.trim();
40
+ if (!repository) {
41
+ throw new Error('The repository URL must end in .git.');
42
+ }
43
+ if (isLocalRepository(repository)) {
44
+ return getLocalRepositoryName(repository);
45
+ }
46
+ const parts = repository.split('/');
3
47
  const gitName = parts.at(-1);
4
- if (!gitName.includes('.git')) {
48
+ if (!gitName.endsWith('.git')) {
5
49
  throw new Error('The repository URL must end in .git.');
6
50
  }
7
- return gitName.split('.').at(0);
51
+ return gitName.slice(0, -4) || undefined;
8
52
  }
@@ -0,0 +1,7 @@
1
+ export default function getNonInteractiveGitEnvironment(environment = process.env) {
2
+ return {
3
+ ...environment,
4
+ GIT_TERMINAL_PROMPT: '0',
5
+ GIT_SSH_COMMAND: environment.GIT_SSH_COMMAND || 'ssh -oBatchMode=yes',
6
+ };
7
+ }
@@ -1,9 +1,21 @@
1
1
  import { execFile } from 'child_process';
2
+ import getNonInteractiveGitEnvironment from './getNonInteractiveGitEnvironment.js';
2
3
  const tagPattern = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
4
+ const REMOTE_TAG_LOOKUP_TIMEOUT_MS = 10_000;
5
+ class RemoteTagLookupTimeoutError extends Error {
6
+ }
3
7
  function getRemoteTagRefs(repoUrl) {
4
8
  return new Promise((resolve, reject) => {
5
- execFile('git', ['ls-remote', '--tags', '--refs', repoUrl], { encoding: 'utf8' }, (error, stdout, stderr) => {
9
+ execFile('git', ['ls-remote', '--tags', '--refs', '--', repoUrl], {
10
+ encoding: 'utf8',
11
+ timeout: REMOTE_TAG_LOOKUP_TIMEOUT_MS,
12
+ env: getNonInteractiveGitEnvironment(),
13
+ }, (error, stdout, stderr) => {
6
14
  if (error) {
15
+ if (error.killed && error.signal === 'SIGTERM') {
16
+ reject(new RemoteTagLookupTimeoutError(`The lookup timed out after ${REMOTE_TAG_LOOKUP_TIMEOUT_MS / 1_000} seconds.`));
17
+ return;
18
+ }
7
19
  reject(new Error(stderr.trim() || error.message));
8
20
  return;
9
21
  }
@@ -88,7 +100,10 @@ const getRepositoryLatestTag = async (repoUrl) => {
88
100
  }
89
101
  catch (error) {
90
102
  const message = error instanceof Error ? error.message : String(error);
91
- throw new Error(`Unable to read tags from repository ${repoUrl}: ${message}`);
103
+ const checkoutSuggestion = error instanceof RemoteTagLookupTimeoutError
104
+ ? ` Retry with --repository "${repoUrl}" --checkout <branch, tag, or commit> to skip automatic tag lookup.`
105
+ : '';
106
+ throw new Error(`Unable to read tags from repository ${repoUrl}: ${message}${checkoutSuggestion}`);
92
107
  }
93
108
  const usableTags = refs
94
109
  .split('\n')
@@ -54,20 +54,31 @@ function getVariantMatchRank(variantPlatform, projectPlatform) {
54
54
  }
55
55
  return undefined;
56
56
  }
57
+ export function rankPlatformVariants(variants, projectPlatform) {
58
+ return (variants || [])
59
+ .map((variant, index) => {
60
+ const rank = getVariantMatchRank(variant.platform, projectPlatform);
61
+ return rank === undefined ? { variant, index } : { variant, rank, index };
62
+ })
63
+ .sort((left, right) => {
64
+ if (left.rank === undefined) {
65
+ return right.rank === undefined ? left.index - right.index : 1;
66
+ }
67
+ if (right.rank === undefined) {
68
+ return -1;
69
+ }
70
+ return left.rank - right.rank || left.index - right.index;
71
+ });
72
+ }
57
73
  export function getVariantPlatformExpressions(variants) {
58
74
  return variants?.map(({ platform }) => platform) || [];
59
75
  }
60
76
  export function selectCompatiblePlatformVariant(variants, projectPlatform) {
61
- const rankedVariants = (variants || [])
62
- .map((variant) => ({
63
- variant,
64
- rank: getVariantMatchRank(variant.platform, projectPlatform),
65
- }))
66
- .filter((match) => match.rank !== undefined);
77
+ const rankedVariants = rankPlatformVariants(variants, projectPlatform).filter((match) => match.rank !== undefined);
67
78
  if (rankedVariants.length === 0) {
68
79
  return { status: 'none' };
69
80
  }
70
- const bestRank = Math.min(...rankedVariants.map(({ rank }) => rank));
81
+ const bestRank = rankedVariants[0].rank;
71
82
  const bestMatches = rankedVariants
72
83
  .filter(({ rank }) => rank === bestRank)
73
84
  .map(({ variant }) => variant);
@@ -0,0 +1,121 @@
1
+ import { componentTemplateToken, } from '../renderTemplate.js';
2
+ import { buildReactTemplate } from './react.js';
3
+ import { buildReactStoriesTemplate } from './reactStories.js';
4
+ import { buildScssTemplate } from './scss.js';
5
+ import { buildSdcJsTemplate } from './sdcJs.js';
6
+ import { buildSdcMetadataTemplate } from './sdcMetadata.js';
7
+ import { buildSdcStoriesTemplate } from './sdcStories.js';
8
+ import { buildStoriesTemplate } from './stories.js';
9
+ import { buildTwigTemplate } from './twig.js';
10
+ import { buildWebComponentTemplate } from './webComponent.js';
11
+ import { buildWebComponentStoriesTemplate } from './webComponentStories.js';
12
+ import { buildYmlTemplate } from './yml.js';
13
+ export const COMPONENT_TEMPLATE_TOKEN_VARS = {
14
+ filename: componentTemplateToken('filename'),
15
+ className: componentTemplateToken('className'),
16
+ camelName: componentTemplateToken('camelName'),
17
+ pascalName: componentTemplateToken('pascalName'),
18
+ snakeName: componentTemplateToken('snakeName'),
19
+ humanName: componentTemplateToken('humanName'),
20
+ directory: componentTemplateToken('directory'),
21
+ directoryTitle: componentTemplateToken('directoryTitle'),
22
+ format: componentTemplateToken('format'),
23
+ formatLabel: componentTemplateToken('formatLabel'),
24
+ type: componentTemplateToken('type'),
25
+ tagName: componentTemplateToken('tagName'),
26
+ };
27
+ export default function buildComponentArtifacts(type, vars) {
28
+ const { filename, className, camelName, pascalName, snakeName, humanName, directoryTitle, formatLabel, tagName, } = vars;
29
+ switch (type) {
30
+ case 'twig':
31
+ return [
32
+ {
33
+ logicalName: 'component.twig',
34
+ destinationName: `${filename}.twig`,
35
+ contents: buildTwigTemplate(filename, snakeName, className, formatLabel),
36
+ },
37
+ {
38
+ logicalName: 'component.scss',
39
+ destinationName: `${filename}.scss`,
40
+ contents: buildScssTemplate(className, formatLabel),
41
+ },
42
+ {
43
+ logicalName: 'component.yml',
44
+ destinationName: `${filename}.yml`,
45
+ contents: buildYmlTemplate(snakeName, humanName),
46
+ },
47
+ {
48
+ logicalName: 'component.stories.js',
49
+ destinationName: `${filename}.stories.js`,
50
+ contents: buildStoriesTemplate(camelName, filename, humanName, directoryTitle),
51
+ },
52
+ ];
53
+ case 'twig-sdc':
54
+ return [
55
+ {
56
+ logicalName: 'component.twig',
57
+ destinationName: `${filename}.twig`,
58
+ contents: buildTwigTemplate(filename, snakeName, className, formatLabel),
59
+ },
60
+ {
61
+ logicalName: 'component.scss',
62
+ destinationName: `${filename}.scss`,
63
+ contents: buildScssTemplate(className, formatLabel),
64
+ },
65
+ {
66
+ logicalName: 'component.component.yml',
67
+ destinationName: `${filename}.component.yml`,
68
+ contents: buildSdcMetadataTemplate(snakeName, humanName),
69
+ },
70
+ {
71
+ logicalName: 'component.js',
72
+ destinationName: `${filename}.js`,
73
+ contents: buildSdcJsTemplate(camelName, filename, className),
74
+ },
75
+ {
76
+ logicalName: 'component.stories.js',
77
+ destinationName: `${filename}.stories.js`,
78
+ contents: buildSdcStoriesTemplate(camelName, filename, snakeName, humanName, directoryTitle),
79
+ },
80
+ ];
81
+ case 'react':
82
+ return [
83
+ {
84
+ logicalName: 'component.jsx',
85
+ destinationName: `${filename}.jsx`,
86
+ contents: buildReactTemplate(pascalName, filename, className, humanName),
87
+ },
88
+ {
89
+ logicalName: 'component.scss',
90
+ destinationName: `${filename}.scss`,
91
+ contents: buildScssTemplate(className, formatLabel),
92
+ },
93
+ {
94
+ logicalName: 'component.stories.jsx',
95
+ destinationName: `${filename}.stories.jsx`,
96
+ contents: buildReactStoriesTemplate(pascalName, filename, humanName, directoryTitle),
97
+ },
98
+ ];
99
+ case 'web-component':
100
+ return [
101
+ {
102
+ logicalName: 'component.js',
103
+ destinationName: `${filename}.js`,
104
+ contents: buildWebComponentTemplate(pascalName, filename, className, humanName, tagName),
105
+ },
106
+ {
107
+ logicalName: 'component.scss',
108
+ destinationName: `${filename}.scss`,
109
+ contents: buildScssTemplate(className, formatLabel),
110
+ },
111
+ {
112
+ logicalName: 'component.stories.js',
113
+ destinationName: `${filename}.stories.js`,
114
+ contents: buildWebComponentStoriesTemplate(filename, humanName, directoryTitle, tagName),
115
+ },
116
+ ];
117
+ }
118
+ }
119
+ export function buildEjectableComponentTemplates(type) {
120
+ return buildComponentArtifacts(type, COMPONENT_TEMPLATE_TOKEN_VARS);
121
+ }
@@ -1,7 +1,12 @@
1
1
  export { buildScssTemplate } from './scss.js';
2
+ export { default as buildComponentArtifacts, buildEjectableComponentTemplates, COMPONENT_TEMPLATE_TOKEN_VARS, } from './buildComponentArtifacts.js';
3
+ export { buildReactStoriesTemplate } from './reactStories.js';
4
+ export { buildReactTemplate } from './react.js';
2
5
  export { buildSdcJsTemplate } from './sdcJs.js';
3
6
  export { buildSdcMetadataTemplate } from './sdcMetadata.js';
4
7
  export { buildSdcStoriesTemplate } from './sdcStories.js';
5
8
  export { buildStoriesTemplate } from './stories.js';
6
9
  export { buildTwigTemplate } from './twig.js';
10
+ export { buildWebComponentStoriesTemplate } from './webComponentStories.js';
11
+ export { buildWebComponentTemplate } from './webComponent.js';
7
12
  export { buildYmlTemplate } from './yml.js';
@@ -0,0 +1,20 @@
1
+ export function buildReactTemplate(pascalName, filename, className, humanName) {
2
+ return `/**
3
+ * @file
4
+ * ${filename}.jsx
5
+ */
6
+ import React from 'react';
7
+
8
+ export function ${pascalName}({
9
+ heading = '${humanName} Component',
10
+ content = 'This is the content area of the ${humanName} React component. Replace it with your markup and data.',
11
+ }) {
12
+ return (
13
+ <article className="${className}">
14
+ {heading && <h2 className="${className}__heading">{heading}</h2>}
15
+ <div className="${className}__content">{content}</div>
16
+ </article>
17
+ );
18
+ }
19
+ `;
20
+ }
@@ -0,0 +1,18 @@
1
+ export function buildReactStoriesTemplate(pascalName, filename, humanName, directoryTitle) {
2
+ return `import { ${pascalName} } from './${filename}.jsx';
3
+
4
+ /**
5
+ * Storybook Definition.
6
+ */
7
+ export default {
8
+ title: '${directoryTitle}/${humanName}',
9
+ component: ${pascalName},
10
+ args: {
11
+ heading: '${humanName} Component',
12
+ content: 'This is the content area of the ${humanName} React component. Replace it with your markup and data.',
13
+ },
14
+ };
15
+
16
+ export const Default = {};
17
+ `;
18
+ }
@@ -1,7 +1,6 @@
1
- export function buildScssTemplate(className, format) {
2
- const label = format === 'DEFAULT' ? 'STANDARD' : format;
1
+ export function buildScssTemplate(className, formatLabel) {
3
2
  return `/*
4
- * Base Styles for ${className} (${label})
3
+ * Base Styles for ${className} (${formatLabel})
5
4
  *
6
5
  * These styles are provided as a starting point.
7
6
  * Replace or extend them to match your project's design system.
@@ -1,4 +1,4 @@
1
- export function buildSdcStoriesTemplate(camelName, filename, snakeName, humanName, directory) {
1
+ export function buildSdcStoriesTemplate(camelName, filename, snakeName, humanName, directoryTitle) {
2
2
  return `import ${camelName}Twig from './${filename}.twig';
3
3
  import { props } from './${filename}.component.yml';
4
4
  import './${filename}';
@@ -9,7 +9,7 @@ const ${camelName}Data = props.properties;
9
9
  * Storybook Definition.
10
10
  */
11
11
  export default {
12
- title: '${directory[0].toUpperCase() + directory.slice(1)}/${humanName}',
12
+ title: '${directoryTitle}/${humanName}',
13
13
  args: {
14
14
  heading: ${camelName}Data.${snakeName}__heading.data,
15
15
  content: ${camelName}Data.${snakeName}__content.data,
@@ -1,11 +1,11 @@
1
- export function buildStoriesTemplate(camelName, filename, humanName, directory) {
1
+ export function buildStoriesTemplate(camelName, filename, humanName, directoryTitle) {
2
2
  return `import ${camelName}Twig from './${filename}.twig';
3
3
  import ${camelName}Data from './${filename}.yml';
4
4
 
5
5
  /**
6
6
  * Storybook Definition.
7
7
  */
8
- export default { title: '${directory[0].toUpperCase() + directory.slice(1)}/${humanName}' };
8
+ export default { title: '${directoryTitle}/${humanName}' };
9
9
 
10
10
  export const ${camelName} = () => ${camelName}Twig(${camelName}Data);
11
11
  `;
@@ -1,10 +1,9 @@
1
- export function buildTwigTemplate(filename, snakeName, className, format) {
2
- const label = format === 'DEFAULT' ? 'STANDARD' : format;
1
+ export function buildTwigTemplate(filename, snakeName, className, formatLabel) {
3
2
  return `{#
4
3
  /**
5
4
  * @file
6
5
  * ${filename}.twig
7
- * Format: ${label}
6
+ * Format: ${formatLabel}
8
7
  *
9
8
  * Available variables:
10
9
  * - ${snakeName}__heading - the heading text for this component
@@ -0,0 +1,49 @@
1
+ export function buildWebComponentTemplate(pascalName, filename, className, humanName, tagName) {
2
+ return `/**
3
+ * @file
4
+ * ${filename}.js
5
+ */
6
+
7
+ export class ${pascalName}Element extends HTMLElement {
8
+ set heading(value) {
9
+ this.headingValue = value;
10
+ this.render();
11
+ }
12
+
13
+ get heading() {
14
+ return this.headingValue;
15
+ }
16
+
17
+ set content(value) {
18
+ this.contentValue = value;
19
+ this.render();
20
+ }
21
+
22
+ get content() {
23
+ return this.contentValue;
24
+ }
25
+
26
+ connectedCallback() {
27
+ this.render();
28
+ }
29
+
30
+ render() {
31
+ const heading = this.headingValue ?? '${humanName} Component';
32
+ const content =
33
+ this.contentValue ??
34
+ 'This is the content area of the ${humanName} web component. Replace it with your markup and data.';
35
+
36
+ this.innerHTML = \`
37
+ <article class="${className}">
38
+ \${heading ? \`<h2 class="${className}__heading">\${heading}</h2>\` : ''}
39
+ <div class="${className}__content">\${content}</div>
40
+ </article>
41
+ \`;
42
+ }
43
+ }
44
+
45
+ if (!customElements.get('${tagName}')) {
46
+ customElements.define('${tagName}', ${pascalName}Element);
47
+ }
48
+ `;
49
+ }
@@ -0,0 +1,19 @@
1
+ export function buildWebComponentStoriesTemplate(filename, humanName, directoryTitle, tagName) {
2
+ return `import { renderWebComponent } from '@emulsify/core/storybook';
3
+ import './${filename}.js';
4
+
5
+ /**
6
+ * Storybook Definition.
7
+ */
8
+ export default {
9
+ title: '${directoryTitle}/${humanName}',
10
+ render: renderWebComponent('${tagName}'),
11
+ args: {
12
+ heading: '${humanName} Component',
13
+ content: 'This is the content area of the ${humanName} web component. Replace it with your markup and data.',
14
+ },
15
+ };
16
+
17
+ export const Default = {};
18
+ `;
19
+ }
@@ -0,0 +1,71 @@
1
+ import { join } from 'path';
2
+ import loadJsonFile from '../fs/loadJsonFile.js';
3
+ export const COMPONENT_TYPES = [
4
+ 'twig',
5
+ 'twig-sdc',
6
+ 'react',
7
+ 'web-component',
8
+ ];
9
+ export const MISSING_COMPONENT_TYPE_ERROR = 'Component type is required in non-interactive mode. Pass --type <twig|twig-sdc|react|web-component>.';
10
+ export const MISSING_COMPONENT_DIRECTORY_ERROR = 'Component directory is required in non-interactive mode. Pass --directory <directory>.';
11
+ const LEGACY_FORMAT_TO_TYPE = {
12
+ default: 'twig',
13
+ sdc: 'twig-sdc',
14
+ };
15
+ const COMPONENT_FORMAT_LABELS = {
16
+ twig: 'STANDARD',
17
+ 'twig-sdc': 'SDC',
18
+ react: 'REACT',
19
+ 'web-component': 'WEB COMPONENT',
20
+ };
21
+ function normalizeOption(value) {
22
+ return value.trim().toLowerCase();
23
+ }
24
+ export function normalizeComponentType(value) {
25
+ const normalized = normalizeOption(value);
26
+ if (!COMPONENT_TYPES.includes(normalized)) {
27
+ throw new Error(`Invalid component type "${value}". Supported types are: ${COMPONENT_TYPES.join(', ')}.`);
28
+ }
29
+ return normalized;
30
+ }
31
+ export function componentTypeFromLegacyFormat(value) {
32
+ const normalized = normalizeOption(value);
33
+ if (!(normalized in LEGACY_FORMAT_TO_TYPE)) {
34
+ throw new Error(`Invalid component format "${value}". Supported formats are: default, sdc.`);
35
+ }
36
+ return LEGACY_FORMAT_TO_TYPE[normalized];
37
+ }
38
+ export function getCompatibleFormatToken(type) {
39
+ if (type === 'twig')
40
+ return 'default';
41
+ if (type === 'twig-sdc')
42
+ return 'sdc';
43
+ return type;
44
+ }
45
+ export function getComponentFormatLabel(type) {
46
+ return COMPONENT_FORMAT_LABELS[type];
47
+ }
48
+ export function getAvailableComponentTypes(platform, hasEmulsifyCore) {
49
+ return COMPONENT_TYPES.filter((type) => {
50
+ if (type === 'twig-sdc')
51
+ return platform === 'drupal';
52
+ if (type === 'react' || type === 'web-component') {
53
+ return hasEmulsifyCore;
54
+ }
55
+ return true;
56
+ });
57
+ }
58
+ function hasDependency(dependencies) {
59
+ const version = dependencies?.['@emulsify/core'];
60
+ return typeof version === 'string' && version.trim().length > 0;
61
+ }
62
+ export async function projectDeclaresEmulsifyCore(projectRoot) {
63
+ try {
64
+ const packageInfo = await loadJsonFile(join(projectRoot, 'package.json'));
65
+ return (hasDependency(packageInfo?.dependencies) ||
66
+ hasDependency(packageInfo?.devDependencies));
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }