@emulsify/cli 2.3.0 → 2.4.0
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.
- package/README.md +96 -16
- package/dist/handlers/componentCreate.js +34 -5
- package/dist/handlers/componentEjectTemplates.js +317 -0
- package/dist/handlers/componentInstall.js +54 -14
- package/dist/handlers/hofs/withEmulsifySystem.js +1 -1
- package/dist/handlers/init.js +26 -22
- package/dist/handlers/systemCreate.js +222 -0
- package/dist/handlers/systemDetach.js +50 -0
- package/dist/handlers/systemInstall.js +341 -101
- package/dist/index.js +66 -110
- package/dist/lib/log.js +12 -9
- package/dist/lib/rootHelp.js +321 -0
- package/dist/lib/terminalColors.js +10 -0
- package/dist/schemas/emulsifyProjectConfig.json +59 -0
- package/dist/util/cache/cloneIntoCache.js +2 -4
- package/dist/util/deriveComponentNames.js +5 -0
- package/dist/util/deriveCustomElementTagName.js +25 -0
- package/dist/util/fs/writeToJsonFile.js +21 -5
- package/dist/util/getGitRepoNameFromUrl.js +47 -3
- package/dist/util/getNonInteractiveGitEnvironment.js +7 -0
- package/dist/util/getRepositoryLatestTag.js +17 -2
- package/dist/util/platform/platformCompatibility.js +18 -7
- package/dist/util/project/componentTemplates/buildComponentArtifacts.js +121 -0
- package/dist/util/project/componentTemplates/index.js +5 -0
- package/dist/util/project/componentTemplates/react.js +20 -0
- package/dist/util/project/componentTemplates/reactStories.js +18 -0
- package/dist/util/project/componentTemplates/scss.js +2 -3
- package/dist/util/project/componentTemplates/sdcStories.js +2 -2
- package/dist/util/project/componentTemplates/stories.js +2 -2
- package/dist/util/project/componentTemplates/twig.js +2 -3
- package/dist/util/project/componentTemplates/webComponent.js +49 -0
- package/dist/util/project/componentTemplates/webComponentStories.js +19 -0
- package/dist/util/project/componentTypes.js +71 -0
- package/dist/util/project/generateComponent.js +139 -101
- package/dist/util/project/getEmulsifyConfig.js +4 -0
- package/dist/util/project/renderTemplate.js +24 -4
- package/dist/util/project/resolveComponentTemplate.js +24 -11
- package/dist/util/project/unsetEmulsifyConfig.js +16 -0
- package/dist/util/prompt/index.js +25 -0
- package/dist/util/system/buildSystemInstallPlan.js +46 -0
- package/dist/util/system/buildSystemScaffold.js +99 -0
- package/dist/util/system/getAvailableSystems.js +4 -0
- package/package.json +2 -2
|
@@ -19,6 +19,29 @@
|
|
|
19
19
|
"machineName": {
|
|
20
20
|
"type": "string",
|
|
21
21
|
"description": "Machine-friendly name of the project, such as 'carmen-sandiego'."
|
|
22
|
+
},
|
|
23
|
+
"singleDirectoryComponents": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"description": "Whether Drupal Single Directory Component output mirroring is enabled."
|
|
26
|
+
},
|
|
27
|
+
"generatedFrom": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Name of the Emulsify project that generated this project."
|
|
30
|
+
},
|
|
31
|
+
"generatedFromVersion": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Version of the Emulsify project that generated this project."
|
|
34
|
+
},
|
|
35
|
+
"description": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Human-facing description of the generated project."
|
|
38
|
+
},
|
|
39
|
+
"assetRoots": {
|
|
40
|
+
"type": "array",
|
|
41
|
+
"description": "Compatibility alias for additional project-relative asset directories. Prefer the top-level assets.roots property.",
|
|
42
|
+
"items": {
|
|
43
|
+
"type": "string"
|
|
44
|
+
}
|
|
22
45
|
}
|
|
23
46
|
},
|
|
24
47
|
"additionalProperties": false,
|
|
@@ -36,6 +59,42 @@
|
|
|
36
59
|
"additionalProperties": false,
|
|
37
60
|
"required": ["repository"]
|
|
38
61
|
},
|
|
62
|
+
"projectStructure": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"description": "Compatibility configuration for Emulsify Core project structure. Prefer the top-level assets property for asset settings.",
|
|
65
|
+
"properties": {
|
|
66
|
+
"assetRoots": {
|
|
67
|
+
"type": "array",
|
|
68
|
+
"description": "Compatibility alias for additional project-relative asset directories. Prefer assets.roots.",
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "string"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"additionalProperties": false
|
|
75
|
+
},
|
|
76
|
+
"assets": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"description": "Configures Emulsify Core asset discovery and output behavior.",
|
|
79
|
+
"properties": {
|
|
80
|
+
"roots": {
|
|
81
|
+
"type": "array",
|
|
82
|
+
"description": "Additional project-relative directories containing static assets.",
|
|
83
|
+
"items": {
|
|
84
|
+
"type": "string"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"rebase": {
|
|
88
|
+
"type": "boolean",
|
|
89
|
+
"description": "Whether Emulsify Core resolves asset aliases and repairs unresolved CSS asset URLs."
|
|
90
|
+
},
|
|
91
|
+
"selfContainedOutput": {
|
|
92
|
+
"type": "boolean",
|
|
93
|
+
"description": "Whether project assets remain under the build output so it can be deployed independently."
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"additionalProperties": false
|
|
97
|
+
},
|
|
39
98
|
"system": {
|
|
40
99
|
"type": "object",
|
|
41
100
|
"description": "Contains information about the Emulsify system this project is utilizing",
|
|
@@ -4,6 +4,7 @@ import { basename, dirname, join } from 'path';
|
|
|
4
4
|
import { EMULSIFY_CACHE_METADATA_FILE } from '../../lib/constants.js';
|
|
5
5
|
import getCachedItemPath from './getCachedItemPath.js';
|
|
6
6
|
import normalizeRepositoryUrl from './normalizeRepositoryUrl.js';
|
|
7
|
+
import getNonInteractiveGitEnvironment from '../getNonInteractiveGitEnvironment.js';
|
|
7
8
|
const REMOTE_REF_LOOKUP_TIMEOUT_MS = 2_000;
|
|
8
9
|
const TEMP_DIRECTORY_MARKER = '.tmp-';
|
|
9
10
|
const ABANDONED_TEMP_DIRECTORY_AGE_MS = 24 * 60 * 60 * 1_000;
|
|
@@ -98,10 +99,7 @@ async function getRemoteResolvedRef(repository, checkout) {
|
|
|
98
99
|
stdOut: false,
|
|
99
100
|
stdErr: false,
|
|
100
101
|
},
|
|
101
|
-
}).env(
|
|
102
|
-
...process.env,
|
|
103
|
-
GIT_TERMINAL_PROMPT: '0',
|
|
104
|
-
});
|
|
102
|
+
}).env(getNonInteractiveGitEnvironment());
|
|
105
103
|
const output = await git.listRemote([repository, ...remoteRefs]);
|
|
106
104
|
const resolvedRefs = new Map();
|
|
107
105
|
for (const line of output.trim().split(/\r?\n/)) {
|
|
@@ -11,6 +11,10 @@ export default function deriveComponentNames(componentName) {
|
|
|
11
11
|
const filename = strToMachineName(sanitizedName.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/-/g, ' '));
|
|
12
12
|
const className = filename;
|
|
13
13
|
const camelName = filename.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
14
|
+
const pascalCandidate = `${camelName.charAt(0).toUpperCase()}${camelName.slice(1)}`;
|
|
15
|
+
const pascalName = /^[A-Za-z_$]/.test(pascalCandidate)
|
|
16
|
+
? pascalCandidate
|
|
17
|
+
: `Component${pascalCandidate}`;
|
|
14
18
|
const snakeName = filename.replace(/-/g, '_');
|
|
15
19
|
const humanName = filename
|
|
16
20
|
.split('-')
|
|
@@ -20,6 +24,7 @@ export default function deriveComponentNames(componentName) {
|
|
|
20
24
|
filename,
|
|
21
25
|
className,
|
|
22
26
|
camelName,
|
|
27
|
+
pascalName,
|
|
23
28
|
snakeName,
|
|
24
29
|
humanName,
|
|
25
30
|
};
|
|
@@ -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
|
-
|
|
3
|
-
|
|
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(
|
|
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 (
|
|
10
|
-
|
|
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
|
|
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.
|
|
48
|
+
if (!gitName.endsWith('.git')) {
|
|
5
49
|
throw new Error('The repository URL must end in .git.');
|
|
6
50
|
}
|
|
7
|
-
return gitName.
|
|
51
|
+
return gitName.slice(0, -4) || undefined;
|
|
8
52
|
}
|
|
@@ -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',
|
|
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
|
-
|
|
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 =
|
|
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,
|
|
2
|
-
const label = format === 'DEFAULT' ? 'STANDARD' : format;
|
|
1
|
+
export function buildScssTemplate(className, formatLabel) {
|
|
3
2
|
return `/*
|
|
4
|
-
* Base Styles for ${className} (${
|
|
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,
|
|
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: '${
|
|
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,
|
|
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: '${
|
|
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,
|
|
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: ${
|
|
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
|
+
}
|