@nx/vue 17.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +63 -0
  3. package/executors.json +3 -0
  4. package/generators.json +50 -0
  5. package/index.d.ts +11 -0
  6. package/index.js +21 -0
  7. package/migrations.json +4 -0
  8. package/package.json +54 -0
  9. package/src/generators/application/application.d.ts +4 -0
  10. package/src/generators/application/application.js +52 -0
  11. package/src/generators/application/files/common/index.html.template +13 -0
  12. package/src/generators/application/files/common/src/app/App.spec.ts.template +12 -0
  13. package/src/generators/application/files/common/src/app/App.vue.template +54 -0
  14. package/src/generators/application/files/common/src/app/NxWelcome.vue.template +793 -0
  15. package/src/generators/application/files/common/src/main.ts.template +15 -0
  16. package/src/generators/application/files/common/tsconfig.app.json.template +8 -0
  17. package/src/generators/application/files/routing/src/router/index.ts.template +23 -0
  18. package/src/generators/application/files/routing/src/views/AboutView.vue.template +16 -0
  19. package/src/generators/application/files/routing/src/views/HomeView.vue.template +9 -0
  20. package/src/generators/application/files/stylesheet/src/styles.__style__.template +42 -0
  21. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  22. package/src/generators/application/lib/add-e2e.js +48 -0
  23. package/src/generators/application/lib/add-jest.d.ts +5 -0
  24. package/src/generators/application/lib/add-jest.js +22 -0
  25. package/src/generators/application/lib/add-vite.d.ts +3 -0
  26. package/src/generators/application/lib/add-vite.js +32 -0
  27. package/src/generators/application/lib/create-application-files.d.ts +3 -0
  28. package/src/generators/application/lib/create-application-files.js +30 -0
  29. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  30. package/src/generators/application/lib/normalize-options.js +45 -0
  31. package/src/generators/application/schema.d.ts +30 -0
  32. package/src/generators/application/schema.json +140 -0
  33. package/src/generators/component/component.d.ts +4 -0
  34. package/src/generators/component/component.js +40 -0
  35. package/src/generators/component/files/__fileName__.spec.ts__tmpl__ +13 -0
  36. package/src/generators/component/files/__fileName__.vue__tmpl__ +10 -0
  37. package/src/generators/component/lib/utils.d.ts +7 -0
  38. package/src/generators/component/lib/utils.js +86 -0
  39. package/src/generators/component/schema.d.ts +22 -0
  40. package/src/generators/component/schema.json +107 -0
  41. package/src/generators/init/init.d.ts +4 -0
  42. package/src/generators/init/init.js +41 -0
  43. package/src/generators/init/schema.d.ts +7 -0
  44. package/src/generators/init/schema.json +37 -0
  45. package/src/generators/library/files/README.md +7 -0
  46. package/src/generators/library/files/package.json__tmpl__ +12 -0
  47. package/src/generators/library/files/src/index.ts__tmpl__ +0 -0
  48. package/src/generators/library/files/src/vue-shims.d.ts__tmpl__ +5 -0
  49. package/src/generators/library/files/tsconfig.lib.json__tmpl__ +34 -0
  50. package/src/generators/library/files/tsconfig.spec.json__tmpl__ +27 -0
  51. package/src/generators/library/lib/add-jest.d.ts +3 -0
  52. package/src/generators/library/lib/add-jest.js +23 -0
  53. package/src/generators/library/lib/add-vite.d.ts +3 -0
  54. package/src/generators/library/lib/add-vite.js +56 -0
  55. package/src/generators/library/lib/create-library-files.d.ts +3 -0
  56. package/src/generators/library/lib/create-library-files.js +28 -0
  57. package/src/generators/library/lib/normalize-options.d.ts +3 -0
  58. package/src/generators/library/lib/normalize-options.js +55 -0
  59. package/src/generators/library/library.d.ts +4 -0
  60. package/src/generators/library/library.js +71 -0
  61. package/src/generators/library/schema.d.ts +41 -0
  62. package/src/generators/library/schema.json +139 -0
  63. package/src/generators/setup-tailwind/files/postcss.config.js.template +10 -0
  64. package/src/generators/setup-tailwind/files/tailwind.config.js.template +18 -0
  65. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.d.ts +3 -0
  66. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +25 -0
  67. package/src/generators/setup-tailwind/schema.d.ts +6 -0
  68. package/src/generators/setup-tailwind/schema.json +45 -0
  69. package/src/generators/setup-tailwind/setup-tailwind.d.ts +4 -0
  70. package/src/generators/setup-tailwind/setup-tailwind.js +25 -0
  71. package/src/generators/stories/lib/component-story.d.ts +3 -0
  72. package/src/generators/stories/lib/component-story.js +34 -0
  73. package/src/generators/stories/lib/files/js/__componentFileName__.stories.js__tmpl__ +25 -0
  74. package/src/generators/stories/lib/files/ts/__componentFileName__.stories.ts__tmpl__ +32 -0
  75. package/src/generators/stories/lib/utils.d.ts +10 -0
  76. package/src/generators/stories/lib/utils.js +75 -0
  77. package/src/generators/stories/schema.json +64 -0
  78. package/src/generators/stories/stories.d.ts +13 -0
  79. package/src/generators/stories/stories.js +61 -0
  80. package/src/generators/storybook-configuration/configuration.d.ts +4 -0
  81. package/src/generators/storybook-configuration/configuration.js +35 -0
  82. package/src/generators/storybook-configuration/schema.d.ts +12 -0
  83. package/src/generators/storybook-configuration/schema.json +77 -0
  84. package/src/tailwind.d.ts +6 -0
  85. package/src/tailwind.js +29 -0
  86. package/src/utils/add-linting.d.ts +12 -0
  87. package/src/utils/add-linting.js +121 -0
  88. package/src/utils/ast-utils.d.ts +3 -0
  89. package/src/utils/ast-utils.js +33 -0
  90. package/src/utils/create-ts-config.d.ts +9 -0
  91. package/src/utils/create-ts-config.js +66 -0
  92. package/src/utils/lint.d.ts +9 -0
  93. package/src/utils/lint.js +26 -0
  94. package/src/utils/setup-jest.d.ts +4 -0
  95. package/src/utils/setup-jest.js +96 -0
  96. package/src/utils/test-utils.d.ts +3 -0
  97. package/src/utils/test-utils.js +30 -0
  98. package/src/utils/versions.d.ts +16 -0
  99. package/src/utils/versions.js +25 -0
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.libraryGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const init_1 = require("../init/init");
7
+ const normalize_options_1 = require("./lib/normalize-options");
8
+ const add_linting_1 = require("../../utils/add-linting");
9
+ const create_library_files_1 = require("./lib/create-library-files");
10
+ const create_ts_config_1 = require("../../utils/create-ts-config");
11
+ const component_1 = require("../component/component");
12
+ const add_vite_1 = require("./lib/add-vite");
13
+ const add_jest_1 = require("./lib/add-jest");
14
+ async function libraryGenerator(tree, schema) {
15
+ const tasks = [];
16
+ const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
17
+ if (options.publishable === true && !schema.importPath) {
18
+ throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
19
+ }
20
+ (0, devkit_1.addProjectConfiguration)(tree, options.name, {
21
+ root: options.projectRoot,
22
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
23
+ projectType: 'library',
24
+ tags: options.parsedTags,
25
+ targets: {},
26
+ });
27
+ tasks.push(await (0, init_1.vueInitGenerator)(tree, {
28
+ ...options,
29
+ skipFormat: true,
30
+ }));
31
+ (0, create_ts_config_1.extractTsConfigBase)(tree);
32
+ tasks.push(await (0, add_linting_1.addLinting)(tree, options, 'lib'));
33
+ (0, create_library_files_1.createLibraryFiles)(tree, options);
34
+ tasks.push(await (0, add_vite_1.addVite)(tree, options));
35
+ if (options.unitTestRunner === 'jest')
36
+ tasks.push(await (0, add_jest_1.addJest)(tree, options));
37
+ if (options.component) {
38
+ tasks.push(await (0, component_1.default)(tree, {
39
+ name: options.fileName,
40
+ project: options.name,
41
+ flat: true,
42
+ skipTests: options.unitTestRunner === 'none' ||
43
+ (options.unitTestRunner === 'vitest' &&
44
+ options.inSourceTests == true),
45
+ export: true,
46
+ routing: options.routing,
47
+ js: options.js,
48
+ pascalCaseFiles: options.pascalCaseFiles,
49
+ inSourceTests: options.inSourceTests,
50
+ skipFormat: true,
51
+ }));
52
+ }
53
+ if (options.publishable || options.bundler !== 'none') {
54
+ (0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
55
+ json.name = options.importPath;
56
+ return json;
57
+ });
58
+ }
59
+ if (!options.skipTsConfig) {
60
+ (0, js_1.addTsConfigPath)(tree, options.importPath, [
61
+ (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
62
+ ]);
63
+ }
64
+ if (options.js)
65
+ (0, devkit_1.toJS)(tree);
66
+ if (!options.skipFormat)
67
+ await (0, devkit_1.formatFiles)(tree);
68
+ return (0, devkit_1.runTasksInSerial)(...tasks);
69
+ }
70
+ exports.libraryGenerator = libraryGenerator;
71
+ exports.default = libraryGenerator;
@@ -0,0 +1,41 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { SupportedStyles } from '../../../typings/style';
4
+
5
+ export interface Schema {
6
+ appProject?: string;
7
+ bundler?: 'none' | 'vite';
8
+ component?: boolean;
9
+ directory?: string;
10
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
+ importPath?: string;
12
+ inSourceTests?: boolean;
13
+ js?: boolean;
14
+ linter: Linter;
15
+ name: string;
16
+ pascalCaseFiles?: boolean;
17
+ publishable?: boolean;
18
+ routing?: boolean;
19
+ setParserOptionsProject?: boolean;
20
+ skipFormat?: boolean;
21
+ skipPackageJson?: boolean;
22
+ skipTsConfig?: boolean;
23
+ strict?: boolean;
24
+ tags?: string;
25
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
26
+ minimal?: boolean;
27
+ e2eTestRunner?: 'cypress' | 'none';
28
+ }
29
+
30
+ export interface NormalizedSchema extends Schema {
31
+ js: boolean;
32
+ name: string;
33
+ linter: Linter;
34
+ fileName: string;
35
+ projectRoot: string;
36
+ routePath: string;
37
+ parsedTags: string[];
38
+ appMain?: string;
39
+ appSourceRoot?: string;
40
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
41
+ }
@@ -0,0 +1,139 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxVueLibrary",
5
+ "title": "Create a Vue Library",
6
+ "description": "Create a Vue Library for an Nx workspace.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g lib mylib --directory=libs/mylib",
11
+ "description": "Generate `libs/mylib`"
12
+ },
13
+ {
14
+ "command": "nx g lib mylib --appProject=myapp",
15
+ "description": "Generate a library with routes and add them to `myapp`"
16
+ }
17
+ ],
18
+ "properties": {
19
+ "name": {
20
+ "type": "string",
21
+ "description": "Library name",
22
+ "$default": {
23
+ "$source": "argv",
24
+ "index": 0
25
+ },
26
+ "x-prompt": "What name would you like to use for the library?",
27
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
28
+ "x-priority": "important"
29
+ },
30
+ "directory": {
31
+ "type": "string",
32
+ "description": "A directory where the lib is placed.",
33
+ "alias": "dir",
34
+ "x-priority": "important"
35
+ },
36
+ "projectNameAndRootFormat": {
37
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
38
+ "type": "string",
39
+ "enum": ["as-provided", "derived"]
40
+ },
41
+ "linter": {
42
+ "description": "The tool to use for running lint checks.",
43
+ "type": "string",
44
+ "enum": ["eslint", "none"],
45
+ "default": "eslint"
46
+ },
47
+ "unitTestRunner": {
48
+ "type": "string",
49
+ "enum": ["vitest", "jest", "none"],
50
+ "description": "Test runner to use for unit tests.",
51
+ "x-prompt": "What unit test runner should be used?"
52
+ },
53
+ "inSourceTests": {
54
+ "type": "boolean",
55
+ "default": false,
56
+ "description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files."
57
+ },
58
+ "tags": {
59
+ "type": "string",
60
+ "description": "Add tags to the library (used for linting).",
61
+ "alias": "t"
62
+ },
63
+ "skipFormat": {
64
+ "description": "Skip formatting files.",
65
+ "type": "boolean",
66
+ "default": false,
67
+ "x-priority": "internal"
68
+ },
69
+ "skipTsConfig": {
70
+ "type": "boolean",
71
+ "default": false,
72
+ "description": "Do not update `tsconfig.json` for development experience.",
73
+ "x-priority": "internal"
74
+ },
75
+ "pascalCaseFiles": {
76
+ "type": "boolean",
77
+ "description": "Use pascal case component file name (e.g. `App.tsx`).",
78
+ "alias": "P",
79
+ "default": false
80
+ },
81
+ "routing": {
82
+ "type": "boolean",
83
+ "description": "Generate library with routes."
84
+ },
85
+ "appProject": {
86
+ "type": "string",
87
+ "description": "The application project to add the library route to.",
88
+ "alias": "a"
89
+ },
90
+ "publishable": {
91
+ "type": "boolean",
92
+ "description": "Create a publishable library."
93
+ },
94
+ "importPath": {
95
+ "type": "string",
96
+ "description": "The library name used to import it, like `@myorg/my-awesome-lib`."
97
+ },
98
+ "component": {
99
+ "type": "boolean",
100
+ "description": "Generate a default component.",
101
+ "default": true
102
+ },
103
+ "js": {
104
+ "type": "boolean",
105
+ "description": "Generate JavaScript files rather than TypeScript files.",
106
+ "default": false
107
+ },
108
+ "strict": {
109
+ "type": "boolean",
110
+ "description": "Whether to enable tsconfig strict mode or not.",
111
+ "default": true
112
+ },
113
+ "setParserOptionsProject": {
114
+ "type": "boolean",
115
+ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
116
+ "default": false
117
+ },
118
+ "bundler": {
119
+ "type": "string",
120
+ "description": "The bundler to use. Choosing 'none' means this library is not buildable.",
121
+ "enum": ["none", "vite"],
122
+ "default": "none",
123
+ "x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
124
+ "x-priority": "important"
125
+ },
126
+ "skipPackageJson": {
127
+ "description": "Do not add dependencies to `package.json`.",
128
+ "type": "boolean",
129
+ "default": false,
130
+ "x-priority": "internal"
131
+ },
132
+ "minimal": {
133
+ "description": "Create a Vue library with a minimal setup, no separate test files.",
134
+ "type": "boolean",
135
+ "default": false
136
+ }
137
+ },
138
+ "required": ["name"]
139
+ }
@@ -0,0 +1,10 @@
1
+ const { join } = require('path');
2
+
3
+ module.exports = {
4
+ plugins: {
5
+ tailwindcss: {
6
+ config: join(__dirname, 'tailwind.config.js'),
7
+ },
8
+ autoprefixer: {},
9
+ },
10
+ }
@@ -0,0 +1,18 @@
1
+ const { createGlobPatternsForDependencies } = require('@nx/vue/tailwind');
2
+ const { join } = require('path');
3
+
4
+ /** @type {import('tailwindcss').Config} */
5
+ module.exports = {
6
+ content: [
7
+ join(__dirname, 'index.html'),
8
+ join(
9
+ __dirname,
10
+ 'src/**/*!(*.stories|*.spec).{vue,ts,tsx,js,jsx}'
11
+ ),
12
+ ...createGlobPatternsForDependencies(__dirname),
13
+ ],
14
+ theme: {
15
+ extend: {},
16
+ },
17
+ plugins: [],
18
+ };
@@ -0,0 +1,3 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { SetupTailwindOptions } from '../schema';
3
+ export declare function addTailwindStyleImports(tree: Tree, project: ProjectConfiguration, _options: SetupTailwindOptions): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addTailwindStyleImports = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const knownStylesheetLocations = [
6
+ // What we generate by default
7
+ 'src/styles.css',
8
+ 'src/styles.scss',
9
+ 'src/styles.less',
10
+ // Other common locations (e.g. what `npm create vue` does)
11
+ 'src/assets/styles.css',
12
+ 'src/assets/styles.scss',
13
+ 'src/assets/styles.less',
14
+ ];
15
+ function addTailwindStyleImports(tree, project, _options) {
16
+ const stylesPath = knownStylesheetLocations
17
+ .map((file) => (0, devkit_1.joinPathFragments)(project.root, file))
18
+ .find((file) => tree.exists(file));
19
+ if (!stylesPath) {
20
+ throw new Error(`Could not find the stylesheet to update. Use --stylesheet to specify this path (relative to the workspace root).`);
21
+ }
22
+ const content = tree.read(stylesPath).toString();
23
+ tree.write(stylesPath, `@tailwind base;\n@tailwind components;\n@tailwind utilities;\n${content}`);
24
+ }
25
+ exports.addTailwindStyleImports = addTailwindStyleImports;
@@ -0,0 +1,6 @@
1
+ export interface SetupTailwindOptions {
2
+ project: string;
3
+ skipFormat?: boolean;
4
+ skipPackageJson?: boolean;
5
+ stylesheet?: string;
6
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxVueTailwindSetupGenerator",
5
+ "title": "Configures Tailwind CSS for an application or a library.",
6
+ "description": "Adds the Tailwind CSS configuration files for a given Vue project and installs, if needed, the packages required for Tailwind CSS to work.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g setup-tailwind --project=my-app",
11
+ "description": "Initialize Tailwind configuration for the `my-app` project."
12
+ }
13
+ ],
14
+ "properties": {
15
+ "project": {
16
+ "type": "string",
17
+ "description": "The name of the project to add the Tailwind CSS setup for.",
18
+ "alias": "p",
19
+ "$default": {
20
+ "$source": "argv",
21
+ "index": 0
22
+ },
23
+ "x-dropdown": "projects",
24
+ "x-prompt": "What project would you like to add the Tailwind CSS setup?",
25
+ "x-priority": "important"
26
+ },
27
+ "skipFormat": {
28
+ "type": "boolean",
29
+ "description": "Skips formatting the workspace after the generator completes.",
30
+ "x-priority": "internal"
31
+ },
32
+ "skipPackageJson": {
33
+ "type": "boolean",
34
+ "default": false,
35
+ "description": "Do not add dependencies to `package.json`.",
36
+ "x-priority": "internal"
37
+ },
38
+ "stylesheet": {
39
+ "type": "string",
40
+ "description": "Path to the styles entry point relative to the workspace root. This option is only needed if the stylesheet location cannot be found automatically."
41
+ }
42
+ },
43
+ "additionalProperties": false,
44
+ "required": ["project"]
45
+ }
@@ -0,0 +1,4 @@
1
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import type { SetupTailwindOptions } from './schema';
3
+ export declare function setupTailwindGenerator(tree: Tree, options: SetupTailwindOptions): Promise<void | GeneratorCallback>;
4
+ export default setupTailwindGenerator;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupTailwindGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ const add_tailwind_style_imports_1 = require("./lib/add-tailwind-style-imports");
7
+ const path_1 = require("path");
8
+ async function setupTailwindGenerator(tree, options) {
9
+ let installTask = undefined;
10
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
11
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {});
12
+ (0, add_tailwind_style_imports_1.addTailwindStyleImports)(tree, project, options);
13
+ if (!options.skipPackageJson) {
14
+ installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
15
+ autoprefixer: versions_1.autoprefixerVersion,
16
+ postcss: versions_1.postcssVersion,
17
+ tailwindcss: versions_1.tailwindcssVersion,
18
+ });
19
+ }
20
+ if (!options.skipFormat)
21
+ await (0, devkit_1.formatFiles)(tree);
22
+ return installTask;
23
+ }
24
+ exports.setupTailwindGenerator = setupTailwindGenerator;
25
+ exports.default = setupTailwindGenerator;
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { StorybookStoriesSchema } from '../stories';
3
+ export declare function createComponentStories(host: Tree, { project, js, interactionTests }: StorybookStoriesSchema, componentPath: string): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createComponentStories = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ const utils_1 = require("./utils");
7
+ let tsModule;
8
+ function createComponentStories(host, { project, js, interactionTests }, componentPath) {
9
+ if (!tsModule) {
10
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
11
+ }
12
+ const proj = (0, devkit_1.getProjects)(host).get(project);
13
+ const sourceRoot = proj.sourceRoot;
14
+ const componentFilePath = (0, devkit_1.joinPathFragments)(sourceRoot, componentPath);
15
+ const componentDirectory = componentFilePath.replace(componentFilePath.slice(componentFilePath.lastIndexOf('/')), '');
16
+ const componentFileName = componentFilePath
17
+ .slice(componentFilePath.lastIndexOf('/') + 1)
18
+ .replace('.vue', '');
19
+ const name = componentFileName;
20
+ const contents = host.read(componentFilePath, 'utf-8');
21
+ const propsObject = (0, utils_1.getDefinePropsObject)(contents);
22
+ (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `./files${js ? '/js' : '/ts'}`), (0, devkit_1.normalizePath)(componentDirectory), {
23
+ tmpl: '',
24
+ componentFileName: name,
25
+ componentImportFileName: `${name}.vue`,
26
+ props: (0, utils_1.createDefautPropsObject)(propsObject),
27
+ componentName: (0, utils_1.camelCase)(name),
28
+ interactionTests,
29
+ });
30
+ if (contents === null) {
31
+ throw new Error(`Failed to read ${componentFilePath}`);
32
+ }
33
+ }
34
+ exports.createComponentStories = createComponentStories;
@@ -0,0 +1,25 @@
1
+ import componentName from './<%= componentImportFileName %>';
2
+ <% if ( interactionTests ) { %>
3
+ import { within } from '@storybook/testing-library';
4
+ import { expect } from '@storybook/jest';
5
+ <% } %>
6
+
7
+ export default {
8
+ component: <%= componentName %>,
9
+ title: '<%= componentName %>'
10
+ };
11
+
12
+ export const Primary = {
13
+ args: {<% for (let prop of props) { %>
14
+ <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
15
+ },
16
+ };
17
+
18
+ <% if ( interactionTests ) { %>
19
+ export const Heading: Story = {
20
+ play: async ({ canvasElement }) => {
21
+ const canvas = within(canvasElement);
22
+ await expect(canvas.getByText(/Welcome to <%=componentName%>!/gi)).toBeTruthy();
23
+ },
24
+ };
25
+ <% } %>
@@ -0,0 +1,32 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3';
2
+ import <%= componentName %> from './<%= componentImportFileName %>';
3
+ <% if ( interactionTests ) { %>
4
+ import { within } from '@storybook/testing-library';
5
+ import { expect } from '@storybook/jest';
6
+ <% } %>
7
+
8
+ const meta: Meta<typeof <%= componentName %>> = {
9
+ component: <%= componentName %>,
10
+ title: '<%= componentName %>',
11
+ };
12
+ export default meta;
13
+ type Story = StoryObj<typeof meta>;
14
+
15
+
16
+ export const Primary = {
17
+ args: {<% for (let prop of props) { %>
18
+ <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
19
+ },
20
+ };
21
+
22
+ <% if ( interactionTests ) { %>
23
+ export const Heading: Story = {
24
+ args: {<% for (let prop of props) { %>
25
+ <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
26
+ },
27
+ play: async ({ canvasElement }) => {
28
+ const canvas = within(canvasElement);
29
+ await expect(canvas.getByText(/Welcome to <%=componentName%>!/gi)).toBeTruthy();
30
+ },
31
+ };
32
+ <% } %>
@@ -0,0 +1,10 @@
1
+ export declare function camelCase(input: string): string;
2
+ export declare function createDefautPropsObject(propsObject: {
3
+ [key: string]: string;
4
+ }): {
5
+ name: string;
6
+ defaultValue: any;
7
+ }[];
8
+ export declare function getDefinePropsObject(vueComponentFileContent: string): {
9
+ [key: string]: string;
10
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefinePropsObject = exports.createDefautPropsObject = exports.camelCase = void 0;
4
+ function camelCase(input) {
5
+ if (input.indexOf('-') > 1) {
6
+ return input
7
+ .toLowerCase()
8
+ .replace(/-(.)/g, (_match, group1) => group1.toUpperCase())
9
+ .replace('.', '');
10
+ }
11
+ else {
12
+ return input;
13
+ }
14
+ }
15
+ exports.camelCase = camelCase;
16
+ function createDefautPropsObject(propsObject) {
17
+ const props = [];
18
+ for (const key in propsObject) {
19
+ if (Object.prototype.hasOwnProperty.call(propsObject, key)) {
20
+ let defaultValueOfProp;
21
+ const element = propsObject[key];
22
+ if (element === 'string') {
23
+ defaultValueOfProp = `'${key}'`;
24
+ }
25
+ else if (element === 'boolean') {
26
+ defaultValueOfProp = false;
27
+ }
28
+ else if (element === 'number') {
29
+ defaultValueOfProp = 0;
30
+ }
31
+ props.push({
32
+ name: key,
33
+ defaultValue: defaultValueOfProp,
34
+ });
35
+ }
36
+ }
37
+ return props;
38
+ }
39
+ exports.createDefautPropsObject = createDefautPropsObject;
40
+ function getDefinePropsObject(vueComponentFileContent) {
41
+ const scriptTagRegex = /<script[^>]*>([\s\S]*?)<\/script>/;
42
+ const match = vueComponentFileContent?.match(scriptTagRegex);
43
+ let propsContent;
44
+ if (match && match[1]) {
45
+ const scriptContent = match[1].trim();
46
+ const definePropsRegex = /defineProps<([\s\S]*?)>/;
47
+ const definePropsMatch = scriptContent.match(definePropsRegex);
48
+ if (definePropsMatch && definePropsMatch[1]) {
49
+ propsContent = definePropsMatch[1].trim();
50
+ }
51
+ else {
52
+ const propsRegex = /(props:\s*\{[\s\S]*?\})/;
53
+ const match = scriptContent.match(propsRegex);
54
+ if (match && match[1]) {
55
+ propsContent = match[1].trim();
56
+ }
57
+ else {
58
+ // No props found
59
+ }
60
+ }
61
+ }
62
+ else {
63
+ // No props found
64
+ }
65
+ const attributes = {};
66
+ if (propsContent) {
67
+ const keyTypeRegex = /(\w+):\s*(\w+);/g;
68
+ let match;
69
+ while ((match = keyTypeRegex.exec(propsContent)) !== null) {
70
+ attributes[match[1]] = match[2];
71
+ }
72
+ }
73
+ return attributes;
74
+ }
75
+ exports.getDefinePropsObject = getDefinePropsObject;
@@ -0,0 +1,64 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxVueStorybookStories",
5
+ "title": "Generate Vue Storybook stories",
6
+ "description": "Generate stories/specs for all components declared in a project.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "aliases": ["name", "projectName"],
12
+ "description": "Project for which to generate stories.",
13
+ "$default": {
14
+ "$source": "projectName",
15
+ "index": 0
16
+ },
17
+ "x-prompt": "For which project do you want to generate stories?",
18
+ "x-priority": "important"
19
+ },
20
+ "generateCypressSpecs": {
21
+ "type": "boolean",
22
+ "description": "Automatically generate `*.spec.ts` files in the cypress e2e app generated by the cypress-configure generator."
23
+ },
24
+ "cypressProject": {
25
+ "type": "string",
26
+ "description": "The Cypress project to generate the stories under. This is inferred from `project` by default."
27
+ },
28
+ "interactionTests": {
29
+ "type": "boolean",
30
+ "description": "Set up Storybook interaction tests.",
31
+ "x-prompt": "Do you want to set up Storybook interaction tests?",
32
+ "x-priority": "important",
33
+ "default": true
34
+ },
35
+ "js": {
36
+ "type": "boolean",
37
+ "description": "Generate JavaScript files rather than TypeScript files.",
38
+ "default": false
39
+ },
40
+ "ignorePaths": {
41
+ "type": "array",
42
+ "description": "Paths to ignore when looking for components.",
43
+ "items": {
44
+ "type": "string",
45
+ "description": "Path to ignore."
46
+ },
47
+ "examples": [
48
+ "apps/my-app/src/not-stories/**",
49
+ "**/**/src/**/not-stories/**",
50
+ "libs/my-lib/**/*.something.ts",
51
+ "**/**/src/**/*.other.*",
52
+ "libs/my-lib/src/not-stories/**,**/**/src/**/*.other.*,apps/my-app/**/*.something.ts"
53
+ ]
54
+ },
55
+ "skipFormat": {
56
+ "description": "Skip formatting files.",
57
+ "type": "boolean",
58
+ "default": false,
59
+ "x-priority": "internal"
60
+ }
61
+ },
62
+ "required": ["project"],
63
+ "examplesFile": "../../../docs/stories-examples.md"
64
+ }
@@ -0,0 +1,13 @@
1
+ import { GeneratorCallback, ProjectConfiguration, Tree } from '@nx/devkit';
2
+ export interface StorybookStoriesSchema {
3
+ project: string;
4
+ interactionTests?: boolean;
5
+ js?: boolean;
6
+ ignorePaths?: string[];
7
+ skipFormat?: boolean;
8
+ cypressProject?: string;
9
+ generateCypressSpecs?: boolean;
10
+ }
11
+ export declare function createAllStories(tree: Tree, projectName: string, interactionTests: boolean, js: boolean, projectConfiguration: ProjectConfiguration, ignorePaths?: string[]): Promise<void>;
12
+ export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<GeneratorCallback>;
13
+ export default storiesGenerator;