@emulsify/cli 2.3.1 → 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/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/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
|
@@ -1,71 +1,146 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
44
|
-
?
|
|
45
|
-
:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
156
|
+
directoryTitle,
|
|
157
|
+
format: getCompatibleFormatToken(type),
|
|
158
|
+
formatLabel,
|
|
159
|
+
type,
|
|
160
|
+
tagName,
|
|
81
161
|
};
|
|
82
|
-
const
|
|
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
|
-
?
|
|
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
|
-
`
|
|
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 =
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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,
|
|
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(
|
|
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 = /
|
|
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(
|
|
6
|
-
if (
|
|
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 "
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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,46 @@
|
|
|
1
|
+
import { dirname, relative, sep } from 'path';
|
|
2
|
+
import safeResolveWithin from '../fs/safeResolveWithin.js';
|
|
3
|
+
import { getComponentDestination } from '../project/installComponentFromCache.js';
|
|
4
|
+
function toProjectRelativeDisplayPath(projectRoot, destination) {
|
|
5
|
+
const displayPath = relative(projectRoot, destination).split(sep).join('/');
|
|
6
|
+
return displayPath || '.';
|
|
7
|
+
}
|
|
8
|
+
function uniqueInOrder(values) {
|
|
9
|
+
return [...new Set(values)];
|
|
10
|
+
}
|
|
11
|
+
function assertSystemStructure(systemConf, component) {
|
|
12
|
+
if (!systemConf.structure.some(({ name }) => name === component.structure)) {
|
|
13
|
+
throw new Error(`The structure (${component.structure}) specified within the component ${component.name} is invalid.`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default function buildSystemInstallPlan(systemConf, variantConf, installAll, projectConfigPath) {
|
|
17
|
+
const projectRoot = dirname(projectConfigPath);
|
|
18
|
+
const requiredComponents = variantConf.components.filter(({ required }) => required === true);
|
|
19
|
+
const components = installAll
|
|
20
|
+
? [...variantConf.components]
|
|
21
|
+
: requiredComponents;
|
|
22
|
+
const componentParentDestinations = uniqueInOrder(components.map((component) => {
|
|
23
|
+
assertSystemStructure(systemConf, component);
|
|
24
|
+
return toProjectRelativeDisplayPath(projectRoot, dirname(getComponentDestination(variantConf, component.name, projectConfigPath)));
|
|
25
|
+
}));
|
|
26
|
+
const directories = variantConf.directories || [];
|
|
27
|
+
const files = variantConf.files || [];
|
|
28
|
+
const directoryAssetDestinations = uniqueInOrder(directories.map(({ destinationPath }) => {
|
|
29
|
+
const destination = safeResolveWithin(projectRoot, destinationPath, 'General asset destination');
|
|
30
|
+
return `${toProjectRelativeDisplayPath(projectRoot, destination)}/`;
|
|
31
|
+
}));
|
|
32
|
+
const fileAssetDestinations = uniqueInOrder(files.map(({ destinationPath }) => toProjectRelativeDisplayPath(projectRoot, safeResolveWithin(projectRoot, destinationPath, 'General asset destination'))));
|
|
33
|
+
const directoryAssetCount = directories.length;
|
|
34
|
+
const fileAssetCount = files.length;
|
|
35
|
+
return {
|
|
36
|
+
components,
|
|
37
|
+
requiredComponentCount: requiredComponents.length,
|
|
38
|
+
totalComponentCount: variantConf.components.length,
|
|
39
|
+
componentParentDestinations,
|
|
40
|
+
directoryAssetDestinations,
|
|
41
|
+
fileAssetDestinations,
|
|
42
|
+
directoryAssetCount,
|
|
43
|
+
fileAssetCount,
|
|
44
|
+
totalAssetCount: directoryAssetCount + fileAssetCount,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -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.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "2.4.0",
|
|
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",
|