@nx/storybook 17.3.0-beta.2 → 17.3.0-beta.3
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/package.json +6 -6
- package/plugin.d.ts +1 -0
- package/plugin.js +6 -0
- package/src/generators/configuration/configuration.js +27 -19
- package/src/generators/configuration/lib/util-functions.d.ts +4 -3
- package/src/generators/configuration/lib/util-functions.js +24 -14
- package/src/generators/init/init.js +7 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +247 -0
- package/src/utils/utilities.d.ts +1 -0
- package/src/utils/utilities.js +24 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/storybook",
|
|
3
|
-
"version": "17.3.0-beta.
|
|
3
|
+
"version": "17.3.0-beta.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@nx/devkit": "17.3.0-beta.3",
|
|
33
34
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
34
35
|
"semver": "7.5.3",
|
|
35
36
|
"tslib": "^2.3.0",
|
|
36
|
-
"@nx/cypress": "17.3.0-beta.
|
|
37
|
-
"@nx/
|
|
38
|
-
"@nx/
|
|
39
|
-
"@
|
|
40
|
-
"@nrwl/storybook": "17.3.0-beta.2"
|
|
37
|
+
"@nx/cypress": "17.3.0-beta.3",
|
|
38
|
+
"@nx/js": "17.3.0-beta.3",
|
|
39
|
+
"@nx/eslint": "17.3.0-beta.3",
|
|
40
|
+
"@nrwl/storybook": "17.3.0-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
package/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNodes, StorybookPluginOptions, createDependencies, } from './src/plugins/plugin';
|
package/plugin.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDependencies = exports.createNodes = void 0;
|
|
4
|
+
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
6
|
+
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
|
|
@@ -16,12 +16,10 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
16
16
|
const schema = normalizeSchema(rawSchema);
|
|
17
17
|
const tasks = [];
|
|
18
18
|
const { projectType, targets, root } = (0, devkit_1.readProjectConfiguration)(tree, schema.project);
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (viteBuildTarget) {
|
|
19
|
+
const { compiler } = (0, utilities_1.findStorybookAndBuildTargetsAndCompiler)(targets);
|
|
20
|
+
const viteConfigFilePath = (0, util_functions_1.findViteConfig)(tree, root);
|
|
21
|
+
const nextConfigFilePath = (0, util_functions_1.findNextConfig)(tree, root);
|
|
22
|
+
if (viteConfigFilePath) {
|
|
25
23
|
if (schema.uiFramework === '@storybook/react-webpack5') {
|
|
26
24
|
devkit_1.logger.info(`Your project ${schema.project} uses Vite as a bundler.
|
|
27
25
|
Nx will configure Storybook for this project to use Vite as well.`);
|
|
@@ -33,7 +31,7 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
33
31
|
schema.uiFramework = '@storybook/web-components-vite';
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
|
-
if (
|
|
34
|
+
if (nextConfigFilePath) {
|
|
37
35
|
schema.uiFramework = '@storybook/nextjs';
|
|
38
36
|
}
|
|
39
37
|
const initTask = await (0, init_1.initGenerator)(tree, {
|
|
@@ -41,9 +39,15 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
41
39
|
js: schema.js,
|
|
42
40
|
});
|
|
43
41
|
tasks.push(initTask);
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
42
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
43
|
+
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
44
|
+
? p === '@nx/storybook/plugin'
|
|
45
|
+
: p.plugin === '@nx/storybook/plugin');
|
|
46
|
+
const mainDir = !!nextConfigFilePath && projectType === 'application'
|
|
47
|
+
? 'components'
|
|
48
|
+
: 'src';
|
|
49
|
+
const usesVite = !!viteConfigFilePath || schema.uiFramework.endsWith('-vite');
|
|
50
|
+
(0, util_functions_1.createProjectStorybookDir)(tree, schema.project, schema.uiFramework, schema.js, schema.tsConfiguration, root, projectType, (0, util_functions_1.projectIsRootProjectInStandaloneWorkspace)(root), schema.interactionTests, mainDir, !!nextConfigFilePath, compiler === 'swc', usesVite, viteConfigFilePath);
|
|
47
51
|
if (schema.uiFramework !== '@storybook/angular') {
|
|
48
52
|
(0, util_functions_1.createStorybookTsconfigFile)(tree, root, schema.uiFramework, (0, util_functions_1.projectIsRootProjectInStandaloneWorkspace)(root), mainDir);
|
|
49
53
|
}
|
|
@@ -53,14 +57,20 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
53
57
|
(0, util_functions_1.updateLintConfig)(tree, schema);
|
|
54
58
|
(0, util_functions_1.addBuildStorybookToCacheableOperations)(tree);
|
|
55
59
|
(0, util_functions_1.addStorybookToNamedInputs)(tree);
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
let devDeps = {};
|
|
61
|
+
if (!hasPlugin) {
|
|
62
|
+
if (schema.uiFramework === '@storybook/angular') {
|
|
63
|
+
(0, util_functions_1.addAngularStorybookTarget)(tree, schema.project, schema.interactionTests);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
(0, util_functions_1.addStorybookTarget)(tree, schema.project, schema.uiFramework, schema.interactionTests);
|
|
67
|
+
}
|
|
68
|
+
if (schema.configureStaticServe) {
|
|
69
|
+
(0, util_functions_1.addStaticTarget)(tree, schema);
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
72
|
else {
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if (schema.configureStaticServe) {
|
|
63
|
-
(0, util_functions_1.addStaticTarget)(tree, schema);
|
|
73
|
+
devDeps['storybook'] = versions_1.storybookVersion;
|
|
64
74
|
}
|
|
65
75
|
// TODO(katerina): Nx 18 -> remove Cypress
|
|
66
76
|
if (schema.configureCypress) {
|
|
@@ -83,7 +93,6 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
83
93
|
devkit_1.logger.warn(`There is already an e2e project setup for ${schema.project}, called ${e2eProject}.`);
|
|
84
94
|
}
|
|
85
95
|
}
|
|
86
|
-
let devDeps = {};
|
|
87
96
|
if (schema.tsConfiguration) {
|
|
88
97
|
devDeps['ts-node'] = versions_1.tsNodeVersion;
|
|
89
98
|
}
|
|
@@ -103,8 +112,7 @@ async function configurationGenerator(tree, rawSchema) {
|
|
|
103
112
|
schema.uiFramework === '@storybook/react-webpack5') {
|
|
104
113
|
devDeps['core-js'] = versions_1.coreJsVersion;
|
|
105
114
|
}
|
|
106
|
-
if (schema.uiFramework.endsWith('-vite') &&
|
|
107
|
-
(!viteBuildTarget || !viteConfigFilePath)) {
|
|
115
|
+
if (schema.uiFramework.endsWith('-vite') && !viteConfigFilePath) {
|
|
108
116
|
// This means that the user has selected a Vite framework
|
|
109
117
|
// but the project does not have Vite configuration.
|
|
110
118
|
// We need to install the @nx/vite plugin in order to be able to use
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { StorybookConfigureSchema } from '../schema';
|
|
3
3
|
import { UiFramework } from '../../../utils/models';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
4
|
+
export declare function addStorybookTarget(tree: Tree, projectName: string, uiFramework: UiFramework, interactionTests: boolean): void;
|
|
5
|
+
export declare function addAngularStorybookTarget(tree: Tree, projectName: string, interactionTests: boolean): void;
|
|
6
6
|
export declare function addStaticTarget(tree: Tree, opts: StorybookConfigureSchema): void;
|
|
7
7
|
export declare function createStorybookTsconfigFile(tree: Tree, projectRoot: string, uiFramework: UiFramework, isRootProject: boolean, mainDir: 'components' | 'src'): void;
|
|
8
8
|
export declare function editTsconfigBaseJson(tree: Tree): void;
|
|
@@ -25,5 +25,6 @@ export declare function projectIsRootProjectInStandaloneWorkspace(projectRoot: s
|
|
|
25
25
|
export declare function workspaceHasRootProject(tree: Tree): boolean;
|
|
26
26
|
export declare function rootFileIsTs(tree: Tree, rootFileName: string, tsConfiguration: boolean): boolean;
|
|
27
27
|
export declare function getE2EProjectName(tree: Tree, mainProject: string): Promise<string | undefined>;
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function findViteConfig(tree: Tree, projectRoot: string): string | undefined;
|
|
29
|
+
export declare function findNextConfig(tree: Tree, projectRoot: string): string | undefined;
|
|
29
30
|
export declare function renameAndMoveOldTsConfig(projectRoot: string, pathToStorybookConfigFile: string, tree: Tree): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renameAndMoveOldTsConfig = exports.
|
|
3
|
+
exports.renameAndMoveOldTsConfig = exports.findNextConfig = exports.findViteConfig = exports.getE2EProjectName = exports.rootFileIsTs = exports.workspaceHasRootProject = exports.projectIsRootProjectInStandaloneWorkspace = exports.addBuildStorybookToCacheableOperations = exports.getTsConfigPath = exports.createProjectStorybookDir = exports.addStorybookToNamedInputs = exports.normalizeSchema = exports.updateLintConfig = exports.configureTsSolutionConfig = exports.configureTsProjectConfig = exports.editTsconfigBaseJson = exports.createStorybookTsconfigFile = exports.addStaticTarget = exports.addAngularStorybookTarget = exports.addStorybookTarget = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
6
|
const eslint_1 = require("@nx/eslint");
|
|
@@ -10,7 +10,7 @@ const versions_1 = require("../../../utils/versions");
|
|
|
10
10
|
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
11
11
|
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
12
12
|
const DEFAULT_PORT = 4400;
|
|
13
|
-
function
|
|
13
|
+
function addStorybookTarget(tree, projectName, uiFramework, interactionTests) {
|
|
14
14
|
if (uiFramework === '@storybook/react-native') {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -50,8 +50,8 @@ function addStorybookTask(tree, projectName, uiFramework, interactionTests) {
|
|
|
50
50
|
}
|
|
51
51
|
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
52
52
|
}
|
|
53
|
-
exports.
|
|
54
|
-
function
|
|
53
|
+
exports.addStorybookTarget = addStorybookTarget;
|
|
54
|
+
function addAngularStorybookTarget(tree, projectName, interactionTests) {
|
|
55
55
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
56
56
|
const { ngBuildTarget } = (0, utilities_1.findStorybookAndBuildTargetsAndCompiler)(projectConfig.targets);
|
|
57
57
|
projectConfig.targets['storybook'] = {
|
|
@@ -93,7 +93,7 @@ function addAngularStorybookTask(tree, projectName, interactionTests) {
|
|
|
93
93
|
}
|
|
94
94
|
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
|
|
95
95
|
}
|
|
96
|
-
exports.
|
|
96
|
+
exports.addAngularStorybookTarget = addAngularStorybookTarget;
|
|
97
97
|
function addStaticTarget(tree, opts) {
|
|
98
98
|
const nrwlWeb = (0, devkit_1.ensurePackage)('@nx/web', versions_1.nxVersion);
|
|
99
99
|
nrwlWeb.webStaticServeGenerator(tree, {
|
|
@@ -479,16 +479,26 @@ async function getE2EProjectName(tree, mainProject) {
|
|
|
479
479
|
return e2eProject;
|
|
480
480
|
}
|
|
481
481
|
exports.getE2EProjectName = getE2EProjectName;
|
|
482
|
-
function
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
482
|
+
function findViteConfig(tree, projectRoot) {
|
|
483
|
+
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
|
484
|
+
for (const ext of allowsExt) {
|
|
485
|
+
const viteConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, `vite.config.${ext}`);
|
|
486
|
+
if (tree.exists(viteConfigPath)) {
|
|
487
|
+
return viteConfigPath;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
exports.findViteConfig = findViteConfig;
|
|
492
|
+
function findNextConfig(tree, projectRoot) {
|
|
493
|
+
const allowsExt = ['js', 'mjs', 'cjs'];
|
|
494
|
+
for (const ext of allowsExt) {
|
|
495
|
+
const nextConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, `next.config.${ext}`);
|
|
496
|
+
if (tree.exists(nextConfigPath)) {
|
|
497
|
+
return nextConfigPath;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
490
500
|
}
|
|
491
|
-
exports.
|
|
501
|
+
exports.findNextConfig = findNextConfig;
|
|
492
502
|
function renameAndMoveOldTsConfig(projectRoot, pathToStorybookConfigFile, tree) {
|
|
493
503
|
if (pathToStorybookConfigFile && tree.exists(pathToStorybookConfigFile)) {
|
|
494
504
|
(0, devkit_1.updateJson)(tree, pathToStorybookConfigFile, (json) => {
|
|
@@ -30,6 +30,9 @@ function checkDependenciesInstalled(host, schema) {
|
|
|
30
30
|
!packageJson.devDependencies['react-dom']) {
|
|
31
31
|
dependencies['react-dom'] = versions_1.reactVersion;
|
|
32
32
|
}
|
|
33
|
+
if (process.env.NX_PCV3 === 'true') {
|
|
34
|
+
devDependencies['storybook'] = storybook7VersionToInstall;
|
|
35
|
+
}
|
|
33
36
|
devDependencies['@storybook/core-server'] = storybook7VersionToInstall;
|
|
34
37
|
devDependencies['@storybook/addon-essentials'] = storybook7VersionToInstall;
|
|
35
38
|
if (schema.uiFramework) {
|
|
@@ -147,6 +150,10 @@ async function initGenerator(tree, schema) {
|
|
|
147
150
|
moveToDevDependencies(tree);
|
|
148
151
|
editRootTsConfig(tree);
|
|
149
152
|
addCacheableOperation(tree);
|
|
153
|
+
const addPlugins = process.env.NX_PCV3 === 'true';
|
|
154
|
+
if (addPlugins) {
|
|
155
|
+
(0, utilities_1.addPlugin)(tree);
|
|
156
|
+
}
|
|
150
157
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
151
158
|
}
|
|
152
159
|
exports.initGenerator = initGenerator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
2
|
+
export interface StorybookPluginOptions {
|
|
3
|
+
buildStorybookTargetName?: string;
|
|
4
|
+
serveStorybookTargetName?: string;
|
|
5
|
+
staticStorybookTargetName?: string;
|
|
6
|
+
testStorybookTargetName?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createDependencies: CreateDependencies;
|
|
9
|
+
export declare const createNodes: CreateNodes<StorybookPluginOptions>;
|
|
@@ -0,0 +1,247 @@
|
|
|
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
|
+
// For root projects, the name is not inferred from root package.json, so we need to manually set it.
|
|
63
|
+
// TODO(jack): We should handle this in core and remove this workaround.
|
|
64
|
+
if (projectRoot === '.') {
|
|
65
|
+
result.projects[projectRoot]['name'] = projectName;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
function buildStorybookTargets(configFilePath, projectRoot, options, context, projectName) {
|
|
71
|
+
const buildOutputs = getOutputs(projectRoot);
|
|
72
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
73
|
+
const storybookFramework = getStorybookConfig(configFilePath, context);
|
|
74
|
+
const frameworkIsAngular = storybookFramework === "'@storybook/angular'";
|
|
75
|
+
const targets = {};
|
|
76
|
+
targets[options.buildStorybookTargetName] = buildTarget(namedInputs, buildOutputs, configFilePath, projectRoot, frameworkIsAngular, projectName);
|
|
77
|
+
targets[options.serveStorybookTargetName] = serveTarget(configFilePath, frameworkIsAngular, projectName);
|
|
78
|
+
targets[options.testStorybookTargetName] = testTarget(configFilePath);
|
|
79
|
+
targets[options.staticStorybookTargetName] = serveStaticTarget(options, projectRoot);
|
|
80
|
+
return targets;
|
|
81
|
+
}
|
|
82
|
+
function buildTarget(namedInputs, outputs, configFilePath, projectRoot, frameworkIsAngular, projectName) {
|
|
83
|
+
const outputDir = (0, devkit_1.joinPathFragments)('dist/storybook', projectRoot);
|
|
84
|
+
let targetConfig;
|
|
85
|
+
if (frameworkIsAngular) {
|
|
86
|
+
targetConfig = {
|
|
87
|
+
executor: '@storybook/angular:build-storybook',
|
|
88
|
+
options: {
|
|
89
|
+
outputDir: `${outputDir}`,
|
|
90
|
+
configDir: `${(0, path_1.dirname)(configFilePath)}`,
|
|
91
|
+
browserTarget: `${projectName}:build-storybook`,
|
|
92
|
+
compodoc: false,
|
|
93
|
+
},
|
|
94
|
+
cache: true,
|
|
95
|
+
outputs,
|
|
96
|
+
inputs: [
|
|
97
|
+
...('production' in namedInputs
|
|
98
|
+
? ['production', '^production']
|
|
99
|
+
: ['default', '^default']),
|
|
100
|
+
{
|
|
101
|
+
externalDependencies: [
|
|
102
|
+
'storybook',
|
|
103
|
+
'@storybook/angular',
|
|
104
|
+
'@storybook/test-runner',
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
targetConfig = {
|
|
112
|
+
command: `storybook build --config-dir ${(0, path_1.dirname)(configFilePath)} --output-dir ${outputDir}`,
|
|
113
|
+
cache: true,
|
|
114
|
+
outputs,
|
|
115
|
+
inputs: [
|
|
116
|
+
...('production' in namedInputs
|
|
117
|
+
? ['production', '^production']
|
|
118
|
+
: ['default', '^default']),
|
|
119
|
+
{
|
|
120
|
+
externalDependencies: ['storybook', '@storybook/test-runner'],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return targetConfig;
|
|
126
|
+
}
|
|
127
|
+
function serveTarget(configFilePath, frameworkIsAngular, projectName) {
|
|
128
|
+
if (frameworkIsAngular) {
|
|
129
|
+
return {
|
|
130
|
+
executor: '@storybook/angular:start-storybook',
|
|
131
|
+
options: {
|
|
132
|
+
configDir: `${(0, path_1.dirname)(configFilePath)}`,
|
|
133
|
+
browserTarget: `${projectName}:build-storybook`,
|
|
134
|
+
compodoc: false,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return {
|
|
140
|
+
command: `storybook dev --config-dir ${(0, path_1.dirname)(configFilePath)}`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function testTarget(configFilePath) {
|
|
145
|
+
const targetConfig = {
|
|
146
|
+
command: `test-storybook --config-dir ${(0, path_1.dirname)(configFilePath)}`,
|
|
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
|
+
// TODO(katerina): need to read the output from CLI args
|
|
161
|
+
staticFilePath: (0, devkit_1.joinPathFragments)('dist/storybook', projectRoot),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
return targetConfig;
|
|
165
|
+
}
|
|
166
|
+
function getStorybookConfig(configFilePath, context) {
|
|
167
|
+
const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
|
168
|
+
const mainTsJs = (0, fs_1.readFileSync)(resolvedPath, 'utf-8');
|
|
169
|
+
const importDeclarations = tsquery_1.tsquery.query(mainTsJs, 'ImportDeclaration:has(ImportSpecifier:has([text="StorybookConfig"]))')?.[0];
|
|
170
|
+
const storybookConfigImportPackage = tsquery_1.tsquery.query(importDeclarations, 'StringLiteral')?.[0];
|
|
171
|
+
let frameworkName;
|
|
172
|
+
if (storybookConfigImportPackage?.getText() === `'@storybook/core-common'`) {
|
|
173
|
+
const frameworkPropertyAssignment = tsquery_1.tsquery.query(mainTsJs, `PropertyAssignment:has(Identifier:has([text="framework"]))`)?.[0];
|
|
174
|
+
if (!frameworkPropertyAssignment) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const propertyAssignments = tsquery_1.tsquery.query(frameworkPropertyAssignment, `PropertyAssignment:has(Identifier:has([text="name"]))`);
|
|
178
|
+
const namePropertyAssignment = propertyAssignments?.find((expression) => {
|
|
179
|
+
return expression.getText().startsWith('name');
|
|
180
|
+
});
|
|
181
|
+
if (!namePropertyAssignment) {
|
|
182
|
+
const storybookConfigImportPackage = tsquery_1.tsquery.query(frameworkPropertyAssignment, 'StringLiteral')?.[0];
|
|
183
|
+
frameworkName = storybookConfigImportPackage?.getText();
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
frameworkName = tsquery_1.tsquery
|
|
187
|
+
.query(namePropertyAssignment, `StringLiteral`)?.[0]
|
|
188
|
+
?.getText();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
frameworkName = storybookConfigImportPackage?.getText();
|
|
193
|
+
}
|
|
194
|
+
return frameworkName;
|
|
195
|
+
}
|
|
196
|
+
function getOutputs(_projectRoot) {
|
|
197
|
+
// TODO(katerina): need to read the output from CLI args
|
|
198
|
+
// const outputPath = <output path as read from CLI>;
|
|
199
|
+
const normalizedOutputPath = normalizeOutputPath(undefined, _projectRoot);
|
|
200
|
+
const outputs = [normalizedOutputPath];
|
|
201
|
+
return outputs;
|
|
202
|
+
}
|
|
203
|
+
function normalizeOutputPath(outputPath, projectRoot) {
|
|
204
|
+
if (!outputPath) {
|
|
205
|
+
if (projectRoot === '.') {
|
|
206
|
+
return `{projectRoot}/dist/storybook`;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return `{workspaceRoot}/dist/storybook/{projectRoot}`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
if ((0, path_1.isAbsolute)(outputPath)) {
|
|
214
|
+
return `{workspaceRoot}/${(0, path_1.relative)(devkit_1.workspaceRoot, outputPath)}`;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
if (outputPath.startsWith('..')) {
|
|
218
|
+
return (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, outputPath));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return (0, path_1.join)('{projectRoot}', outputPath);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function normalizeOptions(options) {
|
|
227
|
+
options ??= {};
|
|
228
|
+
options.buildStorybookTargetName = 'build-storybook';
|
|
229
|
+
options.serveStorybookTargetName = 'storybook';
|
|
230
|
+
options.testStorybookTargetName = 'test-storybook';
|
|
231
|
+
options.staticStorybookTargetName = 'static-storybook';
|
|
232
|
+
return options;
|
|
233
|
+
}
|
|
234
|
+
function buildProjectName(projectRoot, workspaceRoot) {
|
|
235
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
236
|
+
const projectJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'project.json');
|
|
237
|
+
let name;
|
|
238
|
+
if ((0, fs_1.existsSync)(projectJsonPath)) {
|
|
239
|
+
const projectJson = (0, devkit_1.parseJson)((0, fs_1.readFileSync)(projectJsonPath, 'utf-8'));
|
|
240
|
+
name = projectJson.name;
|
|
241
|
+
}
|
|
242
|
+
else if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
243
|
+
const packageJson = (0, devkit_1.parseJson)((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
244
|
+
name = packageJson.name;
|
|
245
|
+
}
|
|
246
|
+
return name ?? projectRoot;
|
|
247
|
+
}
|
package/src/utils/utilities.d.ts
CHANGED
|
@@ -40,3 +40,4 @@ export declare function findStorybookAndBuildTargetsAndCompiler(targets: {
|
|
|
40
40
|
export declare function isTheFileAStory(tree: Tree, path: string): boolean;
|
|
41
41
|
export declare function getTsSourceFile(host: Tree, path: string): ts.SourceFile;
|
|
42
42
|
export declare function pleaseUpgrade(): string;
|
|
43
|
+
export declare function addPlugin(tree: Tree): void;
|
package/src/utils/utilities.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pleaseUpgrade = exports.getTsSourceFile = exports.isTheFileAStory = exports.findStorybookAndBuildTargetsAndCompiler = exports.dedupe = exports.storybookConfigExistsCheck = exports.safeFileDelete = exports.getInstalledStorybookVersion = exports.storybookMajorVersion = exports.Constants = void 0;
|
|
3
|
+
exports.addPlugin = exports.pleaseUpgrade = exports.getTsSourceFile = exports.isTheFileAStory = exports.findStorybookAndBuildTargetsAndCompiler = exports.dedupe = exports.storybookConfigExistsCheck = exports.safeFileDelete = exports.getInstalledStorybookVersion = exports.storybookMajorVersion = exports.Constants = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const js_1 = require("@nx/js");
|
|
6
7
|
const ts = require("typescript");
|
|
@@ -222,3 +223,25 @@ function pleaseUpgrade() {
|
|
|
222
223
|
`;
|
|
223
224
|
}
|
|
224
225
|
exports.pleaseUpgrade = pleaseUpgrade;
|
|
226
|
+
function addPlugin(tree) {
|
|
227
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
228
|
+
nxJson.plugins ??= [];
|
|
229
|
+
for (const plugin of nxJson.plugins) {
|
|
230
|
+
if (typeof plugin === 'string'
|
|
231
|
+
? plugin === '@nx/storybook/plugin'
|
|
232
|
+
: plugin.plugin === '@nx/storybook/plugin') {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
nxJson.plugins.push({
|
|
237
|
+
plugin: '@nx/storybook/plugin',
|
|
238
|
+
options: {
|
|
239
|
+
buildStorybookTargetName: 'build-storybook',
|
|
240
|
+
serveStorybookTargetName: 'storybook',
|
|
241
|
+
testStorybookTargetName: 'test-storybook',
|
|
242
|
+
staticStorybookTargetName: 'static-storybook',
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
246
|
+
}
|
|
247
|
+
exports.addPlugin = addPlugin;
|