@nx/nuxt 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.
Files changed (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/generators.json +26 -0
  4. package/index.d.ts +4 -0
  5. package/index.js +9 -0
  6. package/migrations.json +4 -0
  7. package/package.json +50 -0
  8. package/plugin.d.ts +1 -0
  9. package/plugin.js +5 -0
  10. package/src/generators/application/application.d.ts +4 -0
  11. package/src/generators/application/application.js +73 -0
  12. package/src/generators/application/files/__dot__npmrc +2 -0
  13. package/src/generators/application/files/nuxt.config.ts__tmpl__ +36 -0
  14. package/src/generators/application/files/src/app.vue__tmpl__ +48 -0
  15. package/src/generators/application/files/src/assets/css/styles.__style__ +41 -0
  16. package/src/generators/application/files/src/components/NxWelcome.vue__tmpl__ +824 -0
  17. package/src/generators/application/files/src/pages/about.vue__tmpl__ +16 -0
  18. package/src/generators/application/files/src/pages/index.vue__tmpl__ +6 -0
  19. package/src/generators/application/files/src/public/__dot__gitkeep +0 -0
  20. package/src/generators/application/files/src/public/favicon.ico__tmpl__ +0 -0
  21. package/src/generators/application/files/src/server/api/greet.ts__tmpl__ +10 -0
  22. package/src/generators/application/files/src/server/tsconfig.json__tmpl__ +3 -0
  23. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  24. package/src/generators/application/lib/add-e2e.js +50 -0
  25. package/src/generators/application/lib/add-vitest.d.ts +3 -0
  26. package/src/generators/application/lib/add-vitest.js +37 -0
  27. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  28. package/src/generators/application/lib/normalize-options.js +44 -0
  29. package/src/generators/application/schema.d.ts +26 -0
  30. package/src/generators/application/schema.json +110 -0
  31. package/src/generators/init/init.d.ts +4 -0
  32. package/src/generators/init/init.js +22 -0
  33. package/src/generators/init/lib/utils.d.ts +5 -0
  34. package/src/generators/init/lib/utils.js +76 -0
  35. package/src/generators/init/schema.d.ts +6 -0
  36. package/src/generators/init/schema.json +31 -0
  37. package/src/generators/storybook-configuration/configuration.d.ts +4 -0
  38. package/src/generators/storybook-configuration/configuration.js +28 -0
  39. package/src/generators/storybook-configuration/schema.d.ts +12 -0
  40. package/src/generators/storybook-configuration/schema.json +80 -0
  41. package/src/plugins/plugin.d.ts +7 -0
  42. package/src/plugins/plugin.js +140 -0
  43. package/src/utils/add-linting.d.ts +10 -0
  44. package/src/utils/add-linting.js +30 -0
  45. package/src/utils/create-ts-config.d.ts +6 -0
  46. package/src/utils/create-ts-config.js +47 -0
  47. package/src/utils/executor-utils.d.ts +1 -0
  48. package/src/utils/executor-utils.js +7 -0
  49. package/src/utils/lint.d.ts +7 -0
  50. package/src/utils/lint.js +19 -0
  51. package/src/utils/update-gitignore.d.ts +2 -0
  52. package/src/utils/update-gitignore.js +23 -0
  53. package/src/utils/versions.d.ts +6 -0
  54. package/src/utils/versions.js +11 -0
@@ -0,0 +1,140 @@
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 cache_directory_1 = require("nx/src/utils/cache-directory");
7
+ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
+ const fs_1 = require("fs");
9
+ const executor_utils_1 = require("../utils/executor-utils");
10
+ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
11
+ const js_1 = require("@nx/js");
12
+ const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'nuxt.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
+ '**/nuxt.config.{js,ts,mjs,mts,cjs,cts}',
28
+ async (configFilePath, options, context) => {
29
+ const projectRoot = (0, path_1.dirname)(configFilePath);
30
+ // Do not create a project if package.json and project.json isn't there.
31
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
32
+ if (!siblingFiles.includes('package.json') &&
33
+ !siblingFiles.includes('project.json')) {
34
+ return {};
35
+ }
36
+ options = normalizeOptions(options);
37
+ const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
38
+ (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
39
+ ]);
40
+ const targets = targetsCache[hash]
41
+ ? targetsCache[hash]
42
+ : await buildNuxtTargets(configFilePath, projectRoot, options, context);
43
+ calculatedTargets[hash] = targets;
44
+ return {
45
+ projects: {
46
+ [projectRoot]: {
47
+ root: projectRoot,
48
+ targets,
49
+ },
50
+ },
51
+ };
52
+ },
53
+ ];
54
+ async function buildNuxtTargets(configFilePath, projectRoot, options, context) {
55
+ const nuxtConfig = await getInfoFromNuxtConfig(configFilePath, context, projectRoot);
56
+ const { buildOutputs } = getOutputs(nuxtConfig, projectRoot);
57
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
58
+ const targets = {};
59
+ targets[options.buildTargetName] = buildTarget(options.buildTargetName, namedInputs, buildOutputs, projectRoot);
60
+ targets[options.serveTargetName] = serveTarget(projectRoot);
61
+ return targets;
62
+ }
63
+ function buildTarget(buildTargetName, namedInputs, buildOutputs, projectRoot) {
64
+ return {
65
+ command: `nuxi build`,
66
+ options: { cwd: projectRoot },
67
+ cache: true,
68
+ dependsOn: [`^${buildTargetName}`],
69
+ inputs: [
70
+ ...('production' in namedInputs
71
+ ? ['production', '^production']
72
+ : ['default', '^default']),
73
+ {
74
+ externalDependencies: ['nuxi'],
75
+ },
76
+ ],
77
+ outputs: buildOutputs,
78
+ };
79
+ }
80
+ function serveTarget(projectRoot) {
81
+ const targetConfig = {
82
+ command: `nuxi dev`,
83
+ options: {
84
+ cwd: projectRoot,
85
+ },
86
+ };
87
+ return targetConfig;
88
+ }
89
+ async function getInfoFromNuxtConfig(configFilePath, context, projectRoot) {
90
+ const { loadNuxtConfig } = await (0, executor_utils_1.loadNuxtKitDynamicImport)();
91
+ const config = await loadNuxtConfig({
92
+ cwd: (0, devkit_1.joinPathFragments)(context.workspaceRoot, projectRoot),
93
+ configFile: (0, path_1.basename)(configFilePath),
94
+ });
95
+ return {
96
+ buildDir: config?.buildDir,
97
+ };
98
+ }
99
+ function getOutputs(nuxtConfig, projectRoot) {
100
+ let nuxtBuildDir = nuxtConfig?.buildDir;
101
+ if (nuxtConfig?.buildDir && (0, path_1.basename)(nuxtConfig?.buildDir) === '.nuxt') {
102
+ // buildDir will most probably be `../dist/my-app/.nuxt`
103
+ // we want the "general" outputPath to be `../dist/my-app`
104
+ nuxtBuildDir = nuxtConfig.buildDir.replace((0, path_1.basename)(nuxtConfig.buildDir), '');
105
+ }
106
+ const buildOutputPath = normalizeOutputPath(nuxtBuildDir, projectRoot) ??
107
+ '{workspaceRoot}/dist/{projectRoot}';
108
+ return {
109
+ buildOutputs: [buildOutputPath],
110
+ };
111
+ }
112
+ function normalizeOutputPath(outputPath, projectRoot) {
113
+ if (!outputPath) {
114
+ if (projectRoot === '.') {
115
+ return `{projectRoot}/dist`;
116
+ }
117
+ else {
118
+ return `{workspaceRoot}/dist/{projectRoot}`;
119
+ }
120
+ }
121
+ else {
122
+ if ((0, path_1.isAbsolute)(outputPath)) {
123
+ return `{workspaceRoot}/${(0, path_1.relative)(devkit_1.workspaceRoot, outputPath)}`;
124
+ }
125
+ else {
126
+ if (outputPath.startsWith('..')) {
127
+ return (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, outputPath));
128
+ }
129
+ else {
130
+ return (0, path_1.join)('{projectRoot}', outputPath);
131
+ }
132
+ }
133
+ }
134
+ }
135
+ function normalizeOptions(options) {
136
+ options ??= {};
137
+ options.buildTargetName ??= 'build';
138
+ options.serveTargetName ??= 'serve';
139
+ return options;
140
+ }
@@ -0,0 +1,10 @@
1
+ import { Tree } from 'nx/src/generators/tree';
2
+ import { Linter } from '@nx/eslint';
3
+ import { GeneratorCallback } from '@nx/devkit';
4
+ export declare function addLinting(host: Tree, options: {
5
+ linter: Linter;
6
+ projectName: string;
7
+ projectRoot: string;
8
+ unitTestRunner?: 'vitest' | 'none';
9
+ rootProject?: boolean;
10
+ }): Promise<GeneratorCallback>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addLinting = void 0;
4
+ const eslint_1 = require("@nx/eslint");
5
+ const path_1 = require("nx/src/utils/path");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const lint_1 = require("./lint");
8
+ const vue_1 = require("@nx/vue");
9
+ async function addLinting(host, options) {
10
+ const tasks = [];
11
+ if (options.linter === 'eslint') {
12
+ const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
13
+ linter: options.linter,
14
+ project: options.projectName,
15
+ tsConfigPaths: [(0, path_1.joinPathFragments)(options.projectRoot, 'tsconfig.json')],
16
+ unitTestRunner: options.unitTestRunner,
17
+ skipFormat: true,
18
+ rootProject: options.rootProject,
19
+ });
20
+ tasks.push(lintTask);
21
+ (0, devkit_1.updateJson)(host, (0, path_1.joinPathFragments)(options.projectRoot, '.eslintrc.json'), lint_1.extendNuxtEslintJson);
22
+ (0, vue_1.editEslintConfigFiles)(host, options.projectRoot, options.rootProject);
23
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, {
24
+ ...lint_1.extraEslintDependencies.devDependencies,
25
+ });
26
+ tasks.push(installTask);
27
+ }
28
+ return (0, devkit_1.runTasksInSerial)(...tasks);
29
+ }
30
+ exports.addLinting = addLinting;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function createTsConfig(host: Tree, options: {
3
+ projectRoot: string;
4
+ rootProject?: boolean;
5
+ unitTestRunner?: string;
6
+ }, relativePathToRootTsConfig: string): void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTsConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const shared = require("@nx/js/src/utils/typescript/create-ts-config");
6
+ function createTsConfig(host, options, relativePathToRootTsConfig) {
7
+ createAppTsConfig(host, options);
8
+ const json = {
9
+ compilerOptions: {},
10
+ files: [],
11
+ include: [],
12
+ references: [
13
+ {
14
+ path: './tsconfig.app.json',
15
+ },
16
+ ],
17
+ };
18
+ if (options.unitTestRunner !== 'none') {
19
+ json.references.push({
20
+ path: './tsconfig.spec.json',
21
+ });
22
+ }
23
+ // inline tsconfig.base.json into the project
24
+ if (options.rootProject) {
25
+ json.compileOnSave = false;
26
+ json.compilerOptions = {
27
+ ...shared.tsConfigBaseOptions,
28
+ ...json.compilerOptions,
29
+ };
30
+ json.exclude = ['node_modules', 'tmp'];
31
+ }
32
+ else {
33
+ json.extends = relativePathToRootTsConfig;
34
+ }
35
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/tsconfig.json`, json);
36
+ }
37
+ exports.createTsConfig = createTsConfig;
38
+ function createAppTsConfig(host, options) {
39
+ const json = {
40
+ extends: './tsconfig.json',
41
+ compilerOptions: {
42
+ composite: true,
43
+ },
44
+ exclude: [],
45
+ };
46
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/tsconfig.app.json`, json);
47
+ }
@@ -0,0 +1 @@
1
+ export declare function loadNuxtKitDynamicImport(): Promise<typeof import("@nuxt/kit")>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadNuxtKitDynamicImport = void 0;
4
+ function loadNuxtKitDynamicImport() {
5
+ return Function('return import("@nuxt/kit")')();
6
+ }
7
+ exports.loadNuxtKitDynamicImport = loadNuxtKitDynamicImport;
@@ -0,0 +1,7 @@
1
+ export declare const extraEslintDependencies: {
2
+ dependencies: {};
3
+ devDependencies: {
4
+ '@nuxt/eslint-config': string;
5
+ };
6
+ };
7
+ export declare const extendNuxtEslintJson: (json: any) => any;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extendNuxtEslintJson = exports.extraEslintDependencies = void 0;
4
+ const versions_1 = require("./versions");
5
+ exports.extraEslintDependencies = {
6
+ dependencies: {},
7
+ devDependencies: {
8
+ '@nuxt/eslint-config': versions_1.nuxtEslintConfigVersion,
9
+ },
10
+ };
11
+ const extendNuxtEslintJson = (json) => {
12
+ const { extends: pluginExtends, ...config } = json;
13
+ return {
14
+ extends: ['@nuxt/eslint-config', ...(pluginExtends || [])],
15
+ ignorePatterns: ['.nuxt', 'node_modules', '.output'],
16
+ ...config,
17
+ };
18
+ };
19
+ exports.extendNuxtEslintJson = extendNuxtEslintJson;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function updateGitIgnore(tree: Tree): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateGitIgnore = void 0;
4
+ function updateGitIgnore(tree) {
5
+ const contents = tree.read('.gitignore', 'utf-8') ?? '';
6
+ const nuxtEntries = [
7
+ '# Nuxt dev/build outputs',
8
+ '.output',
9
+ '.data',
10
+ '.nuxt',
11
+ '.nitro',
12
+ '.cache',
13
+ ];
14
+ let newContents = contents;
15
+ for (const entry of nuxtEntries) {
16
+ const regex = new RegExp(`^${entry}$`, 'm');
17
+ if (!regex.test(newContents)) {
18
+ newContents += `\n${entry}`;
19
+ }
20
+ }
21
+ tree.write('.gitignore', [newContents].join('\n'));
22
+ }
23
+ exports.updateGitIgnore = updateGitIgnore;
@@ -0,0 +1,6 @@
1
+ export declare const nxVersion: any;
2
+ export declare const h3Version = "^1.8.2";
3
+ export declare const nuxtVersion = "^3.8.1";
4
+ export declare const nuxtDevtoolsVersion = "1.0.0";
5
+ export declare const nuxtUiTemplatesVersion = "^1.3.1";
6
+ export declare const nuxtEslintConfigVersion = "0.2.0";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nuxtEslintConfigVersion = exports.nuxtUiTemplatesVersion = exports.nuxtDevtoolsVersion = exports.nuxtVersion = exports.h3Version = exports.nxVersion = void 0;
4
+ exports.nxVersion = require('../../package.json').version;
5
+ // nuxt deps
6
+ exports.h3Version = '^1.8.2';
7
+ exports.nuxtVersion = '^3.8.1';
8
+ exports.nuxtDevtoolsVersion = '1.0.0';
9
+ exports.nuxtUiTemplatesVersion = '^1.3.1';
10
+ // linting deps
11
+ exports.nuxtEslintConfigVersion = '0.2.0';