@nx/storybook 17.0.4 → 17.0.6
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/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +2 -2
- package/migrations.json +0 -140
- package/package.json +7 -7
- package/presets/cypress.d.ts +20 -1
- package/src/executors/build-storybook/build-storybook.impl.js +1 -1
- package/src/executors/storybook/storybook.impl.js +1 -1
- package/src/generators/configuration/configuration.d.ts +1 -2
- package/src/generators/configuration/configuration.js +32 -69
- package/src/generators/configuration/lib/util-functions.d.ts +5 -11
- package/src/generators/configuration/lib/util-functions.js +69 -88
- package/src/generators/configuration/project-files/.storybook/main.js__tmpl__ +3 -23
- package/src/generators/configuration/project-files-ts/.storybook/main.ts__tmpl__ +3 -22
- package/src/generators/configuration/schema.d.ts +3 -9
- package/src/generators/configuration/schema.json +13 -6
- package/src/generators/cypress-project/cypress-project.d.ts +3 -3
- package/src/generators/cypress-project/cypress-project.js +8 -3
- package/src/generators/cypress-project/schema.json +1 -1
- package/src/generators/init/init.d.ts +0 -1
- package/src/generators/init/init.js +117 -47
- package/src/generators/init/schema.d.ts +4 -5
- package/src/generators/init/schema.json +33 -18
- package/src/migrations/update-16-5-0/move-storybook-tsconfig.js +0 -1
- package/src/utils/models.d.ts +1 -1
- package/src/utils/utilities.d.ts +0 -1
- package/src/utils/utilities.js +8 -30
- package/src/utils/versions.d.ts +7 -6
- package/src/utils/versions.js +8 -7
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -6
- package/src/generators/configuration/lib/edit-root-tsconfig.d.ts +0 -8
- package/src/generators/configuration/lib/edit-root-tsconfig.js +0 -35
- package/src/generators/configuration/lib/ensure-dependencies.d.ts +0 -6
- package/src/generators/configuration/lib/ensure-dependencies.js +0 -70
- package/src/generators/init/lib/update-gitignore.d.ts +0 -2
- package/src/generators/init/lib/update-gitignore.js +0 -16
- package/src/plugins/plugin.d.ts +0 -9
- package/src/plugins/plugin.js +0 -232
package/src/plugins/plugin.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
9
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
10
|
-
const js_1 = require("@nx/js");
|
|
11
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
12
|
-
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'storybook.hash');
|
|
13
|
-
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
14
|
-
const calculatedTargets = {};
|
|
15
|
-
function readTargetsCache() {
|
|
16
|
-
return (0, devkit_1.readJsonFile)(cachePath);
|
|
17
|
-
}
|
|
18
|
-
function writeTargetsToCache(targets) {
|
|
19
|
-
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
|
20
|
-
}
|
|
21
|
-
const createDependencies = () => {
|
|
22
|
-
writeTargetsToCache(calculatedTargets);
|
|
23
|
-
return [];
|
|
24
|
-
};
|
|
25
|
-
exports.createDependencies = createDependencies;
|
|
26
|
-
exports.createNodes = [
|
|
27
|
-
'**/.storybook/main.{js,ts,mjs,mts,cjs,cts}',
|
|
28
|
-
(configFilePath, options, context) => {
|
|
29
|
-
let projectRoot = '';
|
|
30
|
-
if (configFilePath.includes('/.storybook')) {
|
|
31
|
-
projectRoot = (0, path_1.dirname)(configFilePath).replace('/.storybook', '');
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
projectRoot = (0, path_1.dirname)(configFilePath).replace('.storybook', '');
|
|
35
|
-
}
|
|
36
|
-
if (projectRoot === '') {
|
|
37
|
-
projectRoot = '.';
|
|
38
|
-
}
|
|
39
|
-
// Do not create a project if package.json and project.json isn't there.
|
|
40
|
-
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
41
|
-
if (!siblingFiles.includes('package.json') &&
|
|
42
|
-
!siblingFiles.includes('project.json')) {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
options = normalizeOptions(options);
|
|
46
|
-
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
|
|
47
|
-
(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
|
|
48
|
-
]);
|
|
49
|
-
const projectName = buildProjectName(projectRoot, context.workspaceRoot);
|
|
50
|
-
const targets = targetsCache[hash]
|
|
51
|
-
? targetsCache[hash]
|
|
52
|
-
: buildStorybookTargets(configFilePath, projectRoot, options, context, projectName);
|
|
53
|
-
calculatedTargets[hash] = targets;
|
|
54
|
-
const result = {
|
|
55
|
-
projects: {
|
|
56
|
-
[projectRoot]: {
|
|
57
|
-
root: projectRoot,
|
|
58
|
-
targets,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
return result;
|
|
63
|
-
},
|
|
64
|
-
];
|
|
65
|
-
function buildStorybookTargets(configFilePath, projectRoot, options, context, projectName) {
|
|
66
|
-
const buildOutputs = getOutputs(projectRoot);
|
|
67
|
-
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
68
|
-
const storybookFramework = getStorybookFramework(configFilePath, context);
|
|
69
|
-
const frameworkIsAngular = storybookFramework === "'@storybook/angular'";
|
|
70
|
-
if (frameworkIsAngular && !projectName) {
|
|
71
|
-
throw new Error(`Could not find a name for the project at '${projectRoot}'. Please make sure that the project has a package.json or project.json file with name specified.`);
|
|
72
|
-
}
|
|
73
|
-
const targets = {};
|
|
74
|
-
targets[options.buildStorybookTargetName] = buildTarget(namedInputs, buildOutputs, projectRoot, frameworkIsAngular, projectName, configFilePath);
|
|
75
|
-
targets[options.serveStorybookTargetName] = serveTarget(projectRoot, frameworkIsAngular, projectName, configFilePath);
|
|
76
|
-
targets[options.testStorybookTargetName] = testTarget(projectRoot);
|
|
77
|
-
targets[options.staticStorybookTargetName] = serveStaticTarget(options, projectRoot);
|
|
78
|
-
return targets;
|
|
79
|
-
}
|
|
80
|
-
function buildTarget(namedInputs, outputs, projectRoot, frameworkIsAngular, projectName, configFilePath) {
|
|
81
|
-
let targetConfig;
|
|
82
|
-
if (frameworkIsAngular) {
|
|
83
|
-
targetConfig = {
|
|
84
|
-
executor: '@storybook/angular:build-storybook',
|
|
85
|
-
options: {
|
|
86
|
-
configDir: `${(0, path_1.dirname)(configFilePath)}`,
|
|
87
|
-
browserTarget: `${projectName}:build-storybook`,
|
|
88
|
-
compodoc: false,
|
|
89
|
-
outputDir: (0, devkit_1.joinPathFragments)(projectRoot, 'storybook-static'),
|
|
90
|
-
},
|
|
91
|
-
cache: true,
|
|
92
|
-
outputs,
|
|
93
|
-
inputs: [
|
|
94
|
-
...('production' in namedInputs
|
|
95
|
-
? ['production', '^production']
|
|
96
|
-
: ['default', '^default']),
|
|
97
|
-
{
|
|
98
|
-
externalDependencies: [
|
|
99
|
-
'storybook',
|
|
100
|
-
'@storybook/angular',
|
|
101
|
-
'@storybook/test-runner',
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
targetConfig = {
|
|
109
|
-
command: `storybook build`,
|
|
110
|
-
options: { cwd: projectRoot },
|
|
111
|
-
cache: true,
|
|
112
|
-
outputs,
|
|
113
|
-
inputs: [
|
|
114
|
-
...('production' in namedInputs
|
|
115
|
-
? ['production', '^production']
|
|
116
|
-
: ['default', '^default']),
|
|
117
|
-
{
|
|
118
|
-
externalDependencies: ['storybook', '@storybook/test-runner'],
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
return targetConfig;
|
|
124
|
-
}
|
|
125
|
-
function serveTarget(projectRoot, frameworkIsAngular, projectName, configFilePath) {
|
|
126
|
-
if (frameworkIsAngular) {
|
|
127
|
-
return {
|
|
128
|
-
executor: '@storybook/angular:start-storybook',
|
|
129
|
-
options: {
|
|
130
|
-
configDir: `${(0, path_1.dirname)(configFilePath)}`,
|
|
131
|
-
browserTarget: `${projectName}:build-storybook`,
|
|
132
|
-
compodoc: false,
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return {
|
|
138
|
-
command: `storybook dev`,
|
|
139
|
-
options: { cwd: projectRoot },
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function testTarget(projectRoot) {
|
|
144
|
-
const targetConfig = {
|
|
145
|
-
command: `test-storybook`,
|
|
146
|
-
options: { cwd: projectRoot },
|
|
147
|
-
inputs: [
|
|
148
|
-
{
|
|
149
|
-
externalDependencies: ['storybook', '@storybook/test-runner'],
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
};
|
|
153
|
-
return targetConfig;
|
|
154
|
-
}
|
|
155
|
-
function serveStaticTarget(options, projectRoot) {
|
|
156
|
-
const targetConfig = {
|
|
157
|
-
executor: '@nx/web:file-server',
|
|
158
|
-
options: {
|
|
159
|
-
buildTarget: `${options.buildStorybookTargetName}`,
|
|
160
|
-
staticFilePath: (0, devkit_1.joinPathFragments)(projectRoot, 'storybook-static'),
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
return targetConfig;
|
|
164
|
-
}
|
|
165
|
-
function getStorybookFramework(configFilePath, context) {
|
|
166
|
-
const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
|
167
|
-
const mainTsJs = (0, fs_1.readFileSync)(resolvedPath, 'utf-8');
|
|
168
|
-
const importDeclarations = tsquery_1.tsquery.query(mainTsJs, 'ImportDeclaration:has(ImportSpecifier:has([text="StorybookConfig"]))')?.[0];
|
|
169
|
-
if (!importDeclarations) {
|
|
170
|
-
return parseFrameworkName(mainTsJs);
|
|
171
|
-
}
|
|
172
|
-
const storybookConfigImportPackage = tsquery_1.tsquery.query(importDeclarations, 'StringLiteral')?.[0];
|
|
173
|
-
if (storybookConfigImportPackage?.getText() === `'@storybook/core-common'`) {
|
|
174
|
-
return parseFrameworkName(mainTsJs);
|
|
175
|
-
}
|
|
176
|
-
return storybookConfigImportPackage?.getText();
|
|
177
|
-
}
|
|
178
|
-
function parseFrameworkName(mainTsJs) {
|
|
179
|
-
const frameworkPropertyAssignment = tsquery_1.tsquery.query(mainTsJs, `PropertyAssignment:has(Identifier:has([text="framework"]))`)?.[0];
|
|
180
|
-
if (!frameworkPropertyAssignment) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
const propertyAssignments = tsquery_1.tsquery.query(frameworkPropertyAssignment, `PropertyAssignment:has(Identifier:has([text="name"]))`);
|
|
184
|
-
const namePropertyAssignment = propertyAssignments?.find((expression) => {
|
|
185
|
-
return expression.getText().startsWith('name');
|
|
186
|
-
});
|
|
187
|
-
if (!namePropertyAssignment) {
|
|
188
|
-
const storybookConfigImportPackage = tsquery_1.tsquery.query(frameworkPropertyAssignment, 'StringLiteral')?.[0];
|
|
189
|
-
return storybookConfigImportPackage?.getText();
|
|
190
|
-
}
|
|
191
|
-
return tsquery_1.tsquery.query(namePropertyAssignment, `StringLiteral`)?.[0]?.getText();
|
|
192
|
-
}
|
|
193
|
-
function getOutputs(projectRoot) {
|
|
194
|
-
const normalizedOutputPath = normalizeOutputPath(projectRoot);
|
|
195
|
-
const outputs = [
|
|
196
|
-
normalizedOutputPath,
|
|
197
|
-
`{options.output-dir}`,
|
|
198
|
-
`{options.outputDir}`,
|
|
199
|
-
`{options.o}`,
|
|
200
|
-
];
|
|
201
|
-
return outputs;
|
|
202
|
-
}
|
|
203
|
-
function normalizeOutputPath(projectRoot) {
|
|
204
|
-
if (projectRoot === '.') {
|
|
205
|
-
return `{projectRoot}/storybook-static`;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return `{workspaceRoot}/{projectRoot}/storybook-static`;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function normalizeOptions(options) {
|
|
212
|
-
options ??= {};
|
|
213
|
-
options.buildStorybookTargetName = 'build-storybook';
|
|
214
|
-
options.serveStorybookTargetName = 'storybook';
|
|
215
|
-
options.testStorybookTargetName = 'test-storybook';
|
|
216
|
-
options.staticStorybookTargetName = 'static-storybook';
|
|
217
|
-
return options;
|
|
218
|
-
}
|
|
219
|
-
function buildProjectName(projectRoot, workspaceRoot) {
|
|
220
|
-
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
221
|
-
const projectJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'project.json');
|
|
222
|
-
let name;
|
|
223
|
-
if ((0, fs_1.existsSync)(projectJsonPath)) {
|
|
224
|
-
const projectJson = (0, devkit_1.parseJson)((0, fs_1.readFileSync)(projectJsonPath, 'utf-8'));
|
|
225
|
-
name = projectJson.name;
|
|
226
|
-
}
|
|
227
|
-
else if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
228
|
-
const packageJson = (0, devkit_1.parseJson)((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
229
|
-
name = packageJson.name;
|
|
230
|
-
}
|
|
231
|
-
return name;
|
|
232
|
-
}
|