@nx/vue 0.0.0-pr-22179-271588f

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 (95) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +3 -0
  4. package/generators.json +50 -0
  5. package/index.d.ts +13 -0
  6. package/index.js +21 -0
  7. package/migrations.json +14 -0
  8. package/package.json +52 -0
  9. package/src/generators/application/application.d.ts +5 -0
  10. package/src/generators/application/application.js +70 -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 +833 -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 +67 -0
  23. package/src/generators/application/lib/add-vite.d.ts +3 -0
  24. package/src/generators/application/lib/add-vite.js +35 -0
  25. package/src/generators/application/lib/create-application-files.d.ts +3 -0
  26. package/src/generators/application/lib/create-application-files.js +30 -0
  27. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  28. package/src/generators/application/lib/normalize-options.js +45 -0
  29. package/src/generators/application/schema.d.ts +31 -0
  30. package/src/generators/application/schema.json +140 -0
  31. package/src/generators/component/component.d.ts +5 -0
  32. package/src/generators/component/component.js +41 -0
  33. package/src/generators/component/files/__fileName__.spec.ts__tmpl__ +9 -0
  34. package/src/generators/component/files/__fileName__.vue__tmpl__ +10 -0
  35. package/src/generators/component/lib/utils.d.ts +4 -0
  36. package/src/generators/component/lib/utils.js +66 -0
  37. package/src/generators/component/schema.d.ts +37 -0
  38. package/src/generators/component/schema.json +104 -0
  39. package/src/generators/init/init.d.ts +4 -0
  40. package/src/generators/init/init.js +23 -0
  41. package/src/generators/init/schema.d.ts +5 -0
  42. package/src/generators/init/schema.json +27 -0
  43. package/src/generators/library/files/README.md +7 -0
  44. package/src/generators/library/files/package.json__tmpl__ +12 -0
  45. package/src/generators/library/files/src/index.ts__tmpl__ +0 -0
  46. package/src/generators/library/files/src/vue-shims.d.ts__tmpl__ +5 -0
  47. package/src/generators/library/files/tsconfig.lib.json__tmpl__ +27 -0
  48. package/src/generators/library/files/tsconfig.spec.json__tmpl__ +27 -0
  49. package/src/generators/library/lib/add-vite.d.ts +3 -0
  50. package/src/generators/library/lib/add-vite.js +58 -0
  51. package/src/generators/library/lib/create-library-files.d.ts +3 -0
  52. package/src/generators/library/lib/create-library-files.js +28 -0
  53. package/src/generators/library/lib/normalize-options.d.ts +3 -0
  54. package/src/generators/library/lib/normalize-options.js +56 -0
  55. package/src/generators/library/library.d.ts +5 -0
  56. package/src/generators/library/library.js +80 -0
  57. package/src/generators/library/schema.d.ts +42 -0
  58. package/src/generators/library/schema.json +139 -0
  59. package/src/generators/setup-tailwind/files/postcss.config.js.template +10 -0
  60. package/src/generators/setup-tailwind/files/tailwind.config.js.template +18 -0
  61. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.d.ts +3 -0
  62. package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +32 -0
  63. package/src/generators/setup-tailwind/schema.d.ts +6 -0
  64. package/src/generators/setup-tailwind/schema.json +45 -0
  65. package/src/generators/setup-tailwind/setup-tailwind.d.ts +4 -0
  66. package/src/generators/setup-tailwind/setup-tailwind.js +25 -0
  67. package/src/generators/stories/lib/component-story.d.ts +3 -0
  68. package/src/generators/stories/lib/component-story.js +34 -0
  69. package/src/generators/stories/lib/files/js/__componentFileName__.stories.js__tmpl__ +25 -0
  70. package/src/generators/stories/lib/files/ts/__componentFileName__.stories.ts__tmpl__ +32 -0
  71. package/src/generators/stories/lib/utils.d.ts +10 -0
  72. package/src/generators/stories/lib/utils.js +75 -0
  73. package/src/generators/stories/schema.json +67 -0
  74. package/src/generators/stories/stories.d.ts +13 -0
  75. package/src/generators/stories/stories.js +62 -0
  76. package/src/generators/storybook-configuration/configuration.d.ts +5 -0
  77. package/src/generators/storybook-configuration/configuration.js +43 -0
  78. package/src/generators/storybook-configuration/schema.d.ts +13 -0
  79. package/src/generators/storybook-configuration/schema.json +80 -0
  80. package/src/tailwind.d.ts +6 -0
  81. package/src/tailwind.js +29 -0
  82. package/src/utils/add-linting.d.ts +13 -0
  83. package/src/utils/add-linting.js +118 -0
  84. package/src/utils/ast-utils.d.ts +3 -0
  85. package/src/utils/ast-utils.js +33 -0
  86. package/src/utils/create-ts-config.d.ts +8 -0
  87. package/src/utils/create-ts-config.js +66 -0
  88. package/src/utils/ensure-dependencies.d.ts +6 -0
  89. package/src/utils/ensure-dependencies.js +24 -0
  90. package/src/utils/lint.d.ts +8 -0
  91. package/src/utils/lint.js +12 -0
  92. package/src/utils/test-utils.d.ts +3 -0
  93. package/src/utils/test-utils.js +30 -0
  94. package/src/utils/versions.d.ts +14 -0
  95. package/src/utils/versions.js +22 -0
@@ -0,0 +1,37 @@
1
+ export interface ComponentGeneratorSchema {
2
+ name: string;
3
+ skipTests?: boolean;
4
+ directory?: string;
5
+ export?: boolean;
6
+ routing?: boolean;
7
+ js?: boolean;
8
+ fileName?: string;
9
+ inSourceTests?: boolean;
10
+ skipFormat?: boolean;
11
+ nameAndDirectoryFormat?: 'as-provided' | 'derived';
12
+
13
+ /**
14
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19.
15
+ */
16
+ flat?: boolean;
17
+ /**
18
+ * @deprecated Provide the desired `directory` option instead and use the `as-provided` format. It will be removed in Nx v19.
19
+ */
20
+ pascalCaseDirectory?: boolean;
21
+ /**
22
+ * @deprecated Provide the desired `name` option instead and use the `as-provided` format. It will be removed in Nx v19.
23
+ */
24
+ pascalCaseFiles?: boolean;
25
+ /**
26
+ * @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v19.
27
+ */
28
+ project?: string;
29
+ }
30
+
31
+ export interface NormalizedSchema extends ComponentGeneratorSchema {
32
+ projectName: string;
33
+ projectSourceRoot: string;
34
+ fileName: string;
35
+ className: string;
36
+ filePath: string;
37
+ }
@@ -0,0 +1,104 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxVueComponent",
5
+ "title": "Create a Vue Component",
6
+ "description": "Create a Vue Component for Nx.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/vue:component --directory=my-app/src/app/one --name=one --nameAndDirectoryFormat=as-provided --unitTestRunner=vitest",
11
+ "description": "Generate a component in the `my-app` application"
12
+ }
13
+ ],
14
+ "properties": {
15
+ "project": {
16
+ "type": "string",
17
+ "description": "The name of the project.",
18
+ "alias": "p",
19
+ "$default": {
20
+ "$source": "projectName"
21
+ },
22
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
23
+ },
24
+ "name": {
25
+ "type": "string",
26
+ "description": "The name of the component.",
27
+ "$default": {
28
+ "$source": "argv",
29
+ "index": 0
30
+ },
31
+ "x-prompt": "What name would you like to use for the component?",
32
+ "x-priority": "important"
33
+ },
34
+ "nameAndDirectoryFormat": {
35
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
36
+ "type": "string",
37
+ "enum": ["as-provided", "derived"]
38
+ },
39
+ "js": {
40
+ "type": "boolean",
41
+ "description": "Generate JavaScript files rather than TypeScript files.",
42
+ "default": false
43
+ },
44
+ "skipTests": {
45
+ "type": "boolean",
46
+ "description": "When true, does not create `spec.ts` test files for the new component.",
47
+ "default": false,
48
+ "x-priority": "internal"
49
+ },
50
+ "directory": {
51
+ "type": "string",
52
+ "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
53
+ "alias": "dir",
54
+ "x-priority": "important"
55
+ },
56
+ "flat": {
57
+ "type": "boolean",
58
+ "description": "Create component at the source root rather than its own directory.",
59
+ "default": false,
60
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19."
61
+ },
62
+ "export": {
63
+ "type": "boolean",
64
+ "description": "When true, the component is exported from the project `index.ts` (if it exists).",
65
+ "alias": "e",
66
+ "default": false,
67
+ "x-prompt": "Should this component be exported in the project?"
68
+ },
69
+ "pascalCaseFiles": {
70
+ "type": "boolean",
71
+ "description": "Use pascal case component file name (e.g. `App.tsx`).",
72
+ "alias": "P",
73
+ "default": false,
74
+ "x-deprecated": "Provide the desired `name` option instead and use the `as-provided` format. It will be removed in Nx v19."
75
+ },
76
+ "pascalCaseDirectory": {
77
+ "type": "boolean",
78
+ "description": "Use pascal case directory name (e.g. `App/App.tsx`).",
79
+ "alias": "R",
80
+ "default": false,
81
+ "x-deprecated": "Provide the desired `directory` option instead and use the `as-provided` format. It will be removed in Nx v19."
82
+ },
83
+ "routing": {
84
+ "type": "boolean",
85
+ "description": "Generate a library with routes."
86
+ },
87
+ "fileName": {
88
+ "type": "string",
89
+ "description": "Create a component with this file name."
90
+ },
91
+ "inSourceTests": {
92
+ "type": "boolean",
93
+ "default": false,
94
+ "description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html"
95
+ },
96
+ "skipFormat": {
97
+ "description": "Skip formatting files.",
98
+ "type": "boolean",
99
+ "default": false,
100
+ "x-priority": "internal"
101
+ }
102
+ },
103
+ "required": ["name"]
104
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { InitSchema } from './schema';
3
+ export declare function vueInitGenerator(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
+ export default vueInitGenerator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vueInitGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ function updateDependencies(host, schema) {
7
+ const tasks = [];
8
+ tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/vue'], []));
9
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { vue: versions_1.vueVersion }, { '@nx/vue': versions_1.nxVersion }, undefined, schema.keepExistingVersions));
10
+ return (0, devkit_1.runTasksInSerial)(...tasks);
11
+ }
12
+ async function vueInitGenerator(host, schema) {
13
+ let installTask = () => { };
14
+ if (!schema.skipPackageJson) {
15
+ installTask = updateDependencies(host, schema);
16
+ }
17
+ if (!schema.skipFormat) {
18
+ await (0, devkit_1.formatFiles)(host);
19
+ }
20
+ return installTask;
21
+ }
22
+ exports.vueInitGenerator = vueInitGenerator;
23
+ exports.default = vueInitGenerator;
@@ -0,0 +1,5 @@
1
+ export interface InitSchema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxVueInit",
4
+ "title": "Init Vue Plugin",
5
+ "description": "Initialize a Vue Plugin.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ }
25
+ },
26
+ "required": []
27
+ }
@@ -0,0 +1,7 @@
1
+ # <%= name %>
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test <%= name %>` to execute the unit tests via [Vitest](https://vitest.dev/).
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "<%= name %>",
3
+ "version": "0.0.1",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./index.mjs",
9
+ "require": "./index.js"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ declare module '*.vue' {
2
+ import { defineComponent } from 'vue';
3
+ const component: ReturnType<typeof defineComponent>;
4
+ export default component;
5
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "types": [],
6
+ },
7
+ "exclude": [
8
+ "src/**/__tests__/*",
9
+ "src/**/*.spec.ts",
10
+ "src/**/*.test.ts",
11
+ "src/**/*.spec.tsx",
12
+ "src/**/*.test.tsx",
13
+ "src/**/*.spec.js",
14
+ "src/**/*.test.js",
15
+ "src/**/*.spec.jsx",
16
+ "src/**/*.test.jsx",
17
+ "src/**/*.spec.vue",
18
+ "src/**/*.test.vue"
19
+ ],
20
+ "include": [
21
+ "src/**/*.js",
22
+ "src/**/*.jsx",
23
+ "src/**/*.ts",
24
+ "src/**/*.tsx",
25
+ "src/**/*.vue"
26
+ ]
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [],
4
+ "compilerOptions": {
5
+ "outDir": "../../dist/out-tsc",
6
+ "lib": [],
7
+ "types": [
8
+ "vitest",
9
+ "vitest/globals",
10
+ "vitest/importMeta",
11
+ "vite/client",
12
+ "node"]
13
+ },
14
+ "include": [
15
+ "vite.config.ts",
16
+ "src/**/__tests__/*",
17
+ "src/**/*.test.ts",
18
+ "src/**/*.spec.ts",
19
+ "src/**/*.test.tsx",
20
+ "src/**/*.spec.tsx",
21
+ "src/**/*.test.js",
22
+ "src/**/*.spec.js",
23
+ "src/**/*.test.jsx",
24
+ "src/**/*.spec.jsx",
25
+ "src/**/*.d.ts"
26
+ ]
27
+ }
@@ -0,0 +1,3 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ export declare function addVite(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addVite = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../../utils/versions");
6
+ async function addVite(tree, options) {
7
+ const tasks = [];
8
+ // Set up build target
9
+ if (options.bundler === 'vite') {
10
+ const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
11
+ const viteTask = await viteConfigurationGenerator(tree, {
12
+ uiFramework: 'none',
13
+ project: options.name,
14
+ newProject: true,
15
+ includeLib: true,
16
+ inSourceTests: options.inSourceTests,
17
+ includeVitest: options.unitTestRunner === 'vitest',
18
+ skipFormat: true,
19
+ testEnvironment: 'jsdom',
20
+ addPlugin: options.addPlugin,
21
+ });
22
+ tasks.push(viteTask);
23
+ createOrEditViteConfig(tree, {
24
+ project: options.name,
25
+ includeLib: true,
26
+ includeVitest: options.unitTestRunner === 'vitest',
27
+ inSourceTests: options.inSourceTests,
28
+ imports: [`import vue from '@vitejs/plugin-vue'`],
29
+ plugins: ['vue()'],
30
+ }, false);
31
+ }
32
+ // Set up test target
33
+ if (options.unitTestRunner === 'vitest' &&
34
+ options.bundler !== 'vite' // tests are already configured if bundler is vite
35
+ ) {
36
+ const { vitestGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
37
+ const vitestTask = await vitestGenerator(tree, {
38
+ uiFramework: 'none',
39
+ project: options.name,
40
+ coverageProvider: 'v8',
41
+ inSourceTests: options.inSourceTests,
42
+ skipFormat: true,
43
+ testEnvironment: 'jsdom',
44
+ addPlugin: options.addPlugin,
45
+ });
46
+ tasks.push(vitestTask);
47
+ createOrEditViteConfig(tree, {
48
+ project: options.name,
49
+ includeLib: true,
50
+ includeVitest: true,
51
+ inSourceTests: options.inSourceTests,
52
+ imports: [`import vue from '@vitejs/plugin-vue'`],
53
+ plugins: ['vue()'],
54
+ }, true);
55
+ }
56
+ return (0, devkit_1.runTasksInSerial)(...tasks);
57
+ }
58
+ exports.addVite = addVite;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ export declare function createLibraryFiles(host: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLibraryFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const create_ts_config_1 = require("../../../utils/create-ts-config");
7
+ function createLibraryFiles(host, options) {
8
+ const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot);
9
+ const substitutions = {
10
+ ...options,
11
+ ...(0, devkit_1.names)(options.name),
12
+ tmpl: '',
13
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
14
+ fileName: options.fileName,
15
+ };
16
+ (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, '../files'), options.projectRoot, substitutions);
17
+ if (!options.publishable && options.bundler === 'none') {
18
+ host.delete(`${options.projectRoot}/package.json`);
19
+ }
20
+ if (options.unitTestRunner !== 'vitest') {
21
+ host.delete(`${options.projectRoot}/tsconfig.spec.json`);
22
+ }
23
+ if (options.js) {
24
+ (0, devkit_1.toJS)(host);
25
+ }
26
+ (0, create_ts_config_1.createTsConfig)(host, options.projectRoot, 'lib', options, relativePathToRootTsConfig);
27
+ }
28
+ exports.createLibraryFiles = createLibraryFiles;
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema, Schema } from '../schema';
3
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ async function normalizeOptions(host, options) {
7
+ const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ name: options.name,
9
+ projectType: 'library',
10
+ directory: options.directory,
11
+ importPath: options.importPath,
12
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
13
+ callingGenerator: '@nx/vue:library',
14
+ });
15
+ const fileName = projectNames.projectFileName;
16
+ const parsedTags = options.tags
17
+ ? options.tags.split(',').map((s) => s.trim())
18
+ : [];
19
+ let bundler = options.bundler ?? 'none';
20
+ if (bundler === 'none') {
21
+ if (options.publishable) {
22
+ devkit_1.logger.warn(`Publishable libraries cannot be used with bundler: 'none'. Defaulting to 'vite'.`);
23
+ bundler = 'vite';
24
+ }
25
+ }
26
+ const normalized = {
27
+ addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
28
+ ...options,
29
+ bundler,
30
+ fileName,
31
+ routePath: `/${projectNames.projectFileName}`,
32
+ name: projectName,
33
+ projectRoot,
34
+ parsedTags,
35
+ importPath,
36
+ };
37
+ // Libraries with a bundler or is publishable must also be buildable.
38
+ normalized.bundler =
39
+ normalized.bundler !== 'none' || options.publishable ? 'vite' : 'none';
40
+ normalized.inSourceTests === normalized.minimal || normalized.inSourceTests;
41
+ if (options.appProject) {
42
+ const appProjectConfig = (0, devkit_1.getProjects)(host).get(options.appProject);
43
+ if (appProjectConfig.projectType !== 'application') {
44
+ throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
45
+ }
46
+ try {
47
+ normalized.appMain = appProjectConfig.targets.build.options.main;
48
+ normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
49
+ }
50
+ catch (e) {
51
+ throw new Error(`Could not locate project main for ${options.appProject}`);
52
+ }
53
+ }
54
+ return normalized;
55
+ }
56
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function libraryGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function libraryGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
5
+ export default libraryGenerator;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.libraryGeneratorInternal = 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 ensure_dependencies_1 = require("../../utils/ensure-dependencies");
14
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
15
+ function libraryGenerator(tree, schema) {
16
+ return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
17
+ }
18
+ exports.libraryGenerator = libraryGenerator;
19
+ async function libraryGeneratorInternal(tree, schema) {
20
+ const tasks = [];
21
+ const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
22
+ if (options.publishable === true && !schema.importPath) {
23
+ 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)`);
24
+ }
25
+ (0, devkit_1.addProjectConfiguration)(tree, options.name, {
26
+ root: options.projectRoot,
27
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
28
+ projectType: 'library',
29
+ tags: options.parsedTags,
30
+ targets: {},
31
+ });
32
+ tasks.push(await (0, js_1.initGenerator)(tree, { ...schema, skipFormat: true }));
33
+ tasks.push(await (0, init_1.vueInitGenerator)(tree, {
34
+ ...options,
35
+ skipFormat: true,
36
+ }));
37
+ if (!options.skipPackageJson) {
38
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
39
+ }
40
+ (0, create_ts_config_1.extractTsConfigBase)(tree);
41
+ tasks.push(await (0, add_linting_1.addLinting)(tree, options, 'lib'));
42
+ (0, create_library_files_1.createLibraryFiles)(tree, options);
43
+ tasks.push(await (0, add_vite_1.addVite)(tree, options));
44
+ if (options.component) {
45
+ await (0, component_1.default)(tree, {
46
+ name: options.name,
47
+ project: options.name,
48
+ flat: true,
49
+ skipTests: options.unitTestRunner === 'none' ||
50
+ (options.unitTestRunner === 'vitest' && options.inSourceTests == true),
51
+ export: true,
52
+ routing: options.routing,
53
+ js: options.js,
54
+ pascalCaseFiles: options.pascalCaseFiles,
55
+ inSourceTests: options.inSourceTests,
56
+ skipFormat: true,
57
+ });
58
+ }
59
+ if (options.publishable || options.bundler !== 'none') {
60
+ (0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
61
+ json.name = options.importPath;
62
+ return json;
63
+ });
64
+ }
65
+ if (!options.skipTsConfig) {
66
+ (0, js_1.addTsConfigPath)(tree, options.importPath, [
67
+ (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
68
+ ]);
69
+ }
70
+ if (options.js)
71
+ (0, devkit_1.toJS)(tree);
72
+ if (!options.skipFormat)
73
+ await (0, devkit_1.formatFiles)(tree);
74
+ tasks.push(() => {
75
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
76
+ });
77
+ return (0, devkit_1.runTasksInSerial)(...tasks);
78
+ }
79
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
80
+ exports.default = libraryGenerator;
@@ -0,0 +1,42 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/eslint';
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?: 'vitest' | 'none';
26
+ minimal?: boolean;
27
+ e2eTestRunner?: 'cypress' | 'none';
28
+ addPlugin?: boolean;
29
+ }
30
+
31
+ export interface NormalizedSchema extends Schema {
32
+ js: boolean;
33
+ name: string;
34
+ linter: Linter;
35
+ fileName: string;
36
+ projectRoot: string;
37
+ routePath: string;
38
+ parsedTags: string[];
39
+ appMain?: string;
40
+ appSourceRoot?: string;
41
+ unitTestRunner?: 'vitest' | 'none';
42
+ }