nuxt-bake 1.0.1 → 1.0.2
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/dist/helpers/git.js +3 -10
- package/dist/helpers/package-manager.js +2 -4
- package/dist/helpers/template.js +12 -6
- package/dist/helpers/utils.js +35 -8
- package/dist/index.js +17 -30
- package/package.json +58 -58
- package/src/helpers/package-manager.ts +2 -4
- package/src/helpers/template.ts +14 -7
- package/src/helpers/utils.ts +8 -10
- package/src/index.ts +19 -31
- package/templates/base/.env.example +1 -1
- package/dist/helpers/constants.js +0 -28
package/dist/helpers/git.js
CHANGED
|
@@ -2,11 +2,8 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
export function cloneRepoToTemp(repoUrl) {
|
|
5
|
-
const tmpDir = path.join(os.tmpdir(), `
|
|
6
|
-
const result = spawnSync("git", ["clone", "--depth=1", "--quiet", repoUrl, tmpDir], {
|
|
7
|
-
stdio: "pipe",
|
|
8
|
-
shell: true,
|
|
9
|
-
});
|
|
5
|
+
const tmpDir = path.join(os.tmpdir(), `nuxt-bake-${Date.now()}`);
|
|
6
|
+
const result = spawnSync("git", ["clone", "--depth=1", "--quiet", repoUrl, tmpDir], { stdio: "pipe", shell: true });
|
|
10
7
|
if (result.error) {
|
|
11
8
|
console.error("Failed to get project from remote:", result.error.message);
|
|
12
9
|
return null;
|
|
@@ -18,11 +15,7 @@ export function cloneRepoToTemp(repoUrl) {
|
|
|
18
15
|
return tmpDir;
|
|
19
16
|
}
|
|
20
17
|
export function promptAndInitGit(targetDir) {
|
|
21
|
-
const result = spawnSync("git", ["init", "--quiet"], {
|
|
22
|
-
cwd: targetDir,
|
|
23
|
-
stdio: "pipe",
|
|
24
|
-
shell: true,
|
|
25
|
-
});
|
|
18
|
+
const result = spawnSync("git", ["init", "--quiet"], { cwd: targetDir, stdio: "pipe", shell: true });
|
|
26
19
|
if (result.error) {
|
|
27
20
|
console.error("Failed to initialize Git:", result.error.message);
|
|
28
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
|
-
import
|
|
4
|
+
import { select } from "@inquirer/prompts";
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
function mergeObjects(base = {}, extra = {}) {
|
|
7
7
|
return { ...base, ...extra };
|
|
@@ -36,9 +36,7 @@ export function createPackageManagerCommands(pkgManager) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export async function promptForPackageManager() {
|
|
39
|
-
const
|
|
40
|
-
type: "list",
|
|
41
|
-
name: "pkgManager",
|
|
39
|
+
const pkgManager = await select({
|
|
42
40
|
message: "Which package manager do you want to use?",
|
|
43
41
|
choices: [
|
|
44
42
|
{ name: "npm", value: "npm" },
|
package/dist/helpers/template.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { getTemplatesDir } from "./utils.js";
|
|
4
|
+
export async function copyRootTemplate(targetDir) {
|
|
5
|
+
const templatesDir = getTemplatesDir();
|
|
6
|
+
const rootTemplateDir = path.join(templatesDir, "base");
|
|
5
7
|
if (!(await fs.pathExists(rootTemplateDir))) {
|
|
6
|
-
throw new Error(`Root template directory "${rootTemplateDir}" not found
|
|
8
|
+
throw new Error(`Root template directory "${rootTemplateDir}" not found.`);
|
|
7
9
|
}
|
|
8
10
|
await fs.copy(rootTemplateDir, targetDir);
|
|
9
11
|
return rootTemplateDir;
|
|
10
12
|
}
|
|
11
|
-
export async function copyPresetFiles(
|
|
12
|
-
|
|
13
|
+
export async function copyPresetFiles(preset, targetDir) {
|
|
14
|
+
if (preset === "standard") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const templatesDir = getTemplatesDir();
|
|
18
|
+
const presetDir = path.join(templatesDir, preset);
|
|
13
19
|
if (!(await fs.pathExists(presetDir))) {
|
|
14
|
-
throw new Error(`Preset directory "${presetDir}" not found
|
|
20
|
+
throw new Error(`Preset directory "${presetDir}" not found.`);
|
|
15
21
|
}
|
|
16
22
|
const presetRootFiles = await fs.readdir(presetDir);
|
|
17
23
|
for (const file of presetRootFiles) {
|
package/dist/helpers/utils.js
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { confirm, input } from "@inquirer/prompts";
|
|
2
4
|
import fs from "fs-extra";
|
|
3
|
-
|
|
5
|
+
export function getTemplatesDir() {
|
|
6
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
7
|
+
return path.resolve(path.dirname(currentFile), "../..", "templates");
|
|
8
|
+
}
|
|
9
|
+
export const PRESET_EXTRA_SCRIPTS = {
|
|
10
|
+
"standard": {},
|
|
11
|
+
"with-i18n": {},
|
|
12
|
+
"with-tests": {
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"test:e2e": "playwright test",
|
|
15
|
+
"coverage": "vitest --coverage",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export const PRESET_EXTRA_PACKAGES = {
|
|
19
|
+
"standard": {},
|
|
20
|
+
"with-i18n": {
|
|
21
|
+
dependencies: {
|
|
22
|
+
"@nuxtjs/i18n": "10.2.3",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
"with-tests": {
|
|
26
|
+
devDependencies: {
|
|
27
|
+
"@nuxt/test-utils": "3.23.0",
|
|
28
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
29
|
+
"@vue/test-utils": "3.20.0",
|
|
30
|
+
"happy-dom": "20.3.4",
|
|
31
|
+
"@playwright/test": "1.58.2",
|
|
32
|
+
"vitest": "4.0.18",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
4
36
|
export function getProjectNameFromArgs() {
|
|
5
37
|
const args = process.argv.slice(2);
|
|
6
38
|
const nIndex = args.findIndex(a => a === "-n" || a === "--name");
|
|
@@ -12,14 +44,11 @@ export function getProjectNameFromArgs() {
|
|
|
12
44
|
export async function promptForProjectName() {
|
|
13
45
|
let projectName = getProjectNameFromArgs();
|
|
14
46
|
if (!projectName) {
|
|
15
|
-
|
|
16
|
-
type: "input",
|
|
17
|
-
name: "projectName",
|
|
47
|
+
projectName = await input({
|
|
18
48
|
message: "Enter your new project folder name:",
|
|
19
49
|
default: "my-nuxt-app",
|
|
20
50
|
validate: input => (input ? true : "Project folder name cannot be empty"),
|
|
21
51
|
});
|
|
22
|
-
projectName = answerName;
|
|
23
52
|
}
|
|
24
53
|
return projectName;
|
|
25
54
|
}
|
|
@@ -27,9 +56,7 @@ export async function validateTargetDirectory(projectName) {
|
|
|
27
56
|
const targetDir = path.resolve(process.cwd(), projectName);
|
|
28
57
|
const exists = await fs.pathExists(targetDir);
|
|
29
58
|
if (exists) {
|
|
30
|
-
const
|
|
31
|
-
type: "confirm",
|
|
32
|
-
name: "overwrite",
|
|
59
|
+
const overwrite = await confirm({
|
|
33
60
|
message: `Directory "${projectName}" already exists. Overwrite?`,
|
|
34
61
|
default: false,
|
|
35
62
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { confirm, select } from "@inquirer/prompts";
|
|
2
4
|
import fs from "fs-extra";
|
|
3
|
-
import inquirer from "inquirer";
|
|
4
5
|
import ora from "ora";
|
|
5
|
-
import {
|
|
6
|
-
import { cloneRepoToTemp, promptAndInitGit } from "./helpers/git.js";
|
|
6
|
+
import { promptAndInitGit } from "./helpers/git.js";
|
|
7
7
|
import { installDependencies, promptForPackageManager, updatePackageJson } from "./helpers/package-manager.js";
|
|
8
8
|
import { copyPresetFiles, copyRootTemplate } from "./helpers/template.js";
|
|
9
|
-
import { promptForProjectName, validateTargetDirectory } from "./helpers/utils.js";
|
|
9
|
+
import { PRESET_EXTRA_PACKAGES, PRESET_EXTRA_SCRIPTS, promptForProjectName, validateTargetDirectory } from "./helpers/utils.js";
|
|
10
10
|
async function run() {
|
|
11
|
-
let tmpDir;
|
|
12
11
|
try {
|
|
13
12
|
const projectName = await promptForProjectName();
|
|
14
13
|
if (!projectName) {
|
|
@@ -21,16 +20,9 @@ async function run() {
|
|
|
21
20
|
process.exit(1);
|
|
22
21
|
}
|
|
23
22
|
const spinnerClone = ora("Creating project root...").start();
|
|
24
|
-
|
|
25
|
-
if (!tmpDir) {
|
|
26
|
-
spinnerClone.fail("Failed to clone repository.");
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
const rootTemplateDir = await copyRootTemplate(tmpDir, targetDir);
|
|
23
|
+
const rootTemplateDir = await copyRootTemplate(targetDir);
|
|
30
24
|
spinnerClone.succeed();
|
|
31
|
-
const
|
|
32
|
-
type: "list",
|
|
33
|
-
name: "preset",
|
|
25
|
+
const preset = await select({
|
|
34
26
|
message: "Select a preset:",
|
|
35
27
|
choices: [
|
|
36
28
|
{ name: "Standard", value: "standard" },
|
|
@@ -38,15 +30,18 @@ async function run() {
|
|
|
38
30
|
{ name: "With Tests", value: "with-tests" },
|
|
39
31
|
],
|
|
40
32
|
});
|
|
41
|
-
await copyPresetFiles(
|
|
33
|
+
await copyPresetFiles(preset, targetDir);
|
|
42
34
|
await updatePackageJson(rootTemplateDir, targetDir, preset, {
|
|
43
35
|
dependencies: PRESET_EXTRA_PACKAGES[preset]?.dependencies || {},
|
|
44
36
|
devDependencies: PRESET_EXTRA_PACKAGES[preset]?.devDependencies || {},
|
|
45
37
|
scripts: PRESET_EXTRA_SCRIPTS[preset] || {},
|
|
46
38
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
const envExamplePath = path.join(targetDir, ".env.example");
|
|
40
|
+
const envPath = path.join(targetDir, ".env");
|
|
41
|
+
if (await fs.pathExists(envExamplePath)) {
|
|
42
|
+
await fs.copy(envExamplePath, envPath);
|
|
43
|
+
}
|
|
44
|
+
const installDeps = await confirm({
|
|
50
45
|
message: "Install dependencies now?",
|
|
51
46
|
default: true,
|
|
52
47
|
});
|
|
@@ -56,9 +51,7 @@ async function run() {
|
|
|
56
51
|
await installDependencies(targetDir, pkgManager);
|
|
57
52
|
spinnerInstall.succeed("Dependencies installed!");
|
|
58
53
|
}
|
|
59
|
-
const
|
|
60
|
-
type: "confirm",
|
|
61
|
-
name: "initGit",
|
|
54
|
+
const initGit = await confirm({
|
|
62
55
|
message: "Initialize a Git repository?",
|
|
63
56
|
default: true,
|
|
64
57
|
});
|
|
@@ -68,7 +61,7 @@ async function run() {
|
|
|
68
61
|
spinnerGit.succeed(`Git repository initialized for ${projectName}`);
|
|
69
62
|
}
|
|
70
63
|
console.log(`
|
|
71
|
-
|
|
64
|
+
Project setup complete!
|
|
72
65
|
|
|
73
66
|
Next steps:
|
|
74
67
|
1. Navigate to your project:
|
|
@@ -77,20 +70,14 @@ async function run() {
|
|
|
77
70
|
2. Migrate or push database schemas:
|
|
78
71
|
npm run db:migrate
|
|
79
72
|
npm run db:push
|
|
80
|
-
npm run db:generate
|
|
81
73
|
|
|
82
74
|
3. Start the development server:
|
|
83
75
|
npm run dev
|
|
84
76
|
`);
|
|
85
77
|
}
|
|
86
|
-
catch (
|
|
87
|
-
console.error("Error:",
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.error("Error:", err);
|
|
88
80
|
process.exit(1);
|
|
89
81
|
}
|
|
90
|
-
finally {
|
|
91
|
-
if (tmpDir && await fs.pathExists(tmpDir)) {
|
|
92
|
-
await fs.remove(tmpDir);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
82
|
}
|
|
96
83
|
run();
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nuxt-bake",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "A CLI tool to quickly scaffold a Nuxt.js starter project",
|
|
6
|
-
"author": "Matheus Mortari <matheus.felipe.19rt@gmail.com>",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/matimortari/nuxt-bake.git",
|
|
11
|
-
"directory": "package"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"starter",
|
|
15
|
-
"template",
|
|
16
|
-
"nuxt",
|
|
17
|
-
"nuxt4",
|
|
18
|
-
"nuxtjs",
|
|
19
|
-
"vue",
|
|
20
|
-
"typescript",
|
|
21
|
-
"tailwindcss"
|
|
22
|
-
],
|
|
23
|
-
"bin": {
|
|
24
|
-
"nuxt-bake": "dist/index.js"
|
|
25
|
-
},
|
|
26
|
-
"engines": {
|
|
27
|
-
"node": ">=18"
|
|
28
|
-
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"dev": "tsc --watch",
|
|
31
|
-
"build": "tsc",
|
|
32
|
-
"start": "node dist/index.js",
|
|
33
|
-
"typecheck": "tsc --noEmit",
|
|
34
|
-
"lint": "eslint .",
|
|
35
|
-
"lint:fix": "eslint . --fix",
|
|
36
|
-
"clean": "rimraf dist my-nuxt-app",
|
|
37
|
-
"test": "vitest run",
|
|
38
|
-
"coverage": "vitest --coverage",
|
|
39
|
-
"test:e2e": "playwright test",
|
|
40
|
-
"release:patch": "npm version patch && npm publish --access public",
|
|
41
|
-
"release:minor": "npm version minor && npm publish --access public",
|
|
42
|
-
"release:major": "npm version major && npm publish --access public"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"ora": "9.3.0",
|
|
50
|
-
"rimraf": "6.1.3"
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@playwright/test": "1.58.2",
|
|
54
|
-
"@types/fs-extra": "11.0.4",
|
|
55
|
-
"@vitest/coverage-v8": "4.0.18",
|
|
56
|
-
"vitest": "4.0.18"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "nuxt-bake",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "A CLI tool to quickly scaffold a Nuxt.js starter project",
|
|
6
|
+
"author": "Matheus Mortari <matheus.felipe.19rt@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/matimortari/nuxt-bake.git",
|
|
11
|
+
"directory": "package"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"starter",
|
|
15
|
+
"template",
|
|
16
|
+
"nuxt",
|
|
17
|
+
"nuxt4",
|
|
18
|
+
"nuxtjs",
|
|
19
|
+
"vue",
|
|
20
|
+
"typescript",
|
|
21
|
+
"tailwindcss"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"nuxt-bake": "dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"dev": "tsc --watch",
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"start": "node dist/index.js",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"lint:fix": "eslint . --fix",
|
|
36
|
+
"clean": "rimraf dist my-nuxt-app",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"coverage": "vitest --coverage",
|
|
39
|
+
"test:e2e": "playwright test",
|
|
40
|
+
"release:patch": "npm version patch && npm publish --access public",
|
|
41
|
+
"release:minor": "npm version minor && npm publish --access public",
|
|
42
|
+
"release:major": "npm version major && npm publish --access public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@inquirer/prompts": "7.2.0",
|
|
46
|
+
"chalk": "5.6.2",
|
|
47
|
+
"figures": "6.1.0",
|
|
48
|
+
"fs-extra": "11.3.3",
|
|
49
|
+
"ora": "9.3.0",
|
|
50
|
+
"rimraf": "6.1.3"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@playwright/test": "1.58.2",
|
|
54
|
+
"@types/fs-extra": "11.0.4",
|
|
55
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
56
|
+
"vitest": "4.0.18"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync } from "node:child_process"
|
|
2
2
|
import path from "node:path"
|
|
3
3
|
import fs from "fs-extra"
|
|
4
|
-
import
|
|
4
|
+
import { select } from "@inquirer/prompts"
|
|
5
5
|
import ora from "ora"
|
|
6
6
|
|
|
7
7
|
function mergeObjects(base = {}, extra = {}) {
|
|
@@ -39,9 +39,7 @@ export function createPackageManagerCommands(pkgManager: string) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export async function promptForPackageManager() {
|
|
42
|
-
const
|
|
43
|
-
type: "list",
|
|
44
|
-
name: "pkgManager",
|
|
42
|
+
const pkgManager = await select({
|
|
45
43
|
message: "Which package manager do you want to use?",
|
|
46
44
|
choices: [
|
|
47
45
|
{ name: "npm", value: "npm" },
|
package/src/helpers/template.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { Preset } from "./utils"
|
|
1
|
+
import type { Preset } from "./utils.js"
|
|
2
2
|
import path from "node:path"
|
|
3
3
|
import fs from "fs-extra"
|
|
4
|
+
import { getTemplatesDir } from "./utils.js"
|
|
4
5
|
|
|
5
|
-
export async function copyRootTemplate(
|
|
6
|
-
const
|
|
6
|
+
export async function copyRootTemplate(targetDir: string) {
|
|
7
|
+
const templatesDir = getTemplatesDir()
|
|
8
|
+
const rootTemplateDir = path.join(templatesDir, "base")
|
|
7
9
|
if (!(await fs.pathExists(rootTemplateDir))) {
|
|
8
|
-
throw new Error(`Root template directory "${rootTemplateDir}" not found
|
|
10
|
+
throw new Error(`Root template directory "${rootTemplateDir}" not found.`)
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
await fs.copy(rootTemplateDir, targetDir)
|
|
@@ -13,10 +15,15 @@ export async function copyRootTemplate(tmpDir: string, targetDir: string) {
|
|
|
13
15
|
return rootTemplateDir
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export async function copyPresetFiles(
|
|
17
|
-
|
|
18
|
+
export async function copyPresetFiles(preset: Preset, targetDir: string) {
|
|
19
|
+
if (preset === "standard") {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const templatesDir = getTemplatesDir()
|
|
24
|
+
const presetDir = path.join(templatesDir, preset)
|
|
18
25
|
if (!(await fs.pathExists(presetDir))) {
|
|
19
|
-
throw new Error(`Preset directory "${presetDir}" not found
|
|
26
|
+
throw new Error(`Preset directory "${presetDir}" not found.`)
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
const presetRootFiles = await fs.readdir(presetDir)
|
package/src/helpers/utils.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import path from "node:path"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
import { confirm, input } from "@inquirer/prompts"
|
|
2
4
|
import fs from "fs-extra"
|
|
3
|
-
import inquirer from "inquirer"
|
|
4
5
|
|
|
5
6
|
export type Preset = "standard" | "with-i18n" | "with-tests"
|
|
6
7
|
|
|
7
|
-
export
|
|
8
|
+
export function getTemplatesDir() {
|
|
9
|
+
const currentFile = fileURLToPath(import.meta.url)
|
|
10
|
+
return path.resolve(path.dirname(currentFile), "../..", "templates")
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
export const PRESET_EXTRA_SCRIPTS: Record<Preset, Record<string, string>> = {
|
|
10
14
|
"standard": {},
|
|
@@ -48,15 +52,11 @@ export function getProjectNameFromArgs() {
|
|
|
48
52
|
export async function promptForProjectName() {
|
|
49
53
|
let projectName = getProjectNameFromArgs()
|
|
50
54
|
if (!projectName) {
|
|
51
|
-
|
|
52
|
-
type: "input",
|
|
53
|
-
name: "projectName",
|
|
55
|
+
projectName = await input({
|
|
54
56
|
message: "Enter your new project folder name:",
|
|
55
57
|
default: "my-nuxt-app",
|
|
56
58
|
validate: input => (input ? true : "Project folder name cannot be empty"),
|
|
57
59
|
})
|
|
58
|
-
|
|
59
|
-
projectName = answerName
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return projectName
|
|
@@ -66,9 +66,7 @@ export async function validateTargetDirectory(projectName: string) {
|
|
|
66
66
|
const targetDir = path.resolve(process.cwd(), projectName)
|
|
67
67
|
const exists = await fs.pathExists(targetDir)
|
|
68
68
|
if (exists) {
|
|
69
|
-
const
|
|
70
|
-
type: "confirm",
|
|
71
|
-
name: "overwrite",
|
|
69
|
+
const overwrite = await confirm({
|
|
72
70
|
message: `Directory "${projectName}" already exists. Overwrite?`,
|
|
73
71
|
default: false,
|
|
74
72
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { Preset } from "./helpers/utils"
|
|
2
|
+
import type { Preset } from "./helpers/utils.js"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import { confirm, select } from "@inquirer/prompts"
|
|
3
5
|
import fs from "fs-extra"
|
|
4
|
-
import inquirer from "inquirer"
|
|
5
6
|
import ora from "ora"
|
|
6
|
-
import {
|
|
7
|
-
import { installDependencies, promptForPackageManager, updatePackageJson } from "./helpers/package-manager"
|
|
8
|
-
import { copyPresetFiles, copyRootTemplate } from "./helpers/template"
|
|
9
|
-
import { PRESET_EXTRA_PACKAGES, PRESET_EXTRA_SCRIPTS, promptForProjectName,
|
|
7
|
+
import { promptAndInitGit } from "./helpers/git.js"
|
|
8
|
+
import { installDependencies, promptForPackageManager, updatePackageJson } from "./helpers/package-manager.js"
|
|
9
|
+
import { copyPresetFiles, copyRootTemplate } from "./helpers/template.js"
|
|
10
|
+
import { PRESET_EXTRA_PACKAGES, PRESET_EXTRA_SCRIPTS, promptForProjectName, validateTargetDirectory } from "./helpers/utils.js"
|
|
10
11
|
|
|
11
12
|
async function run() {
|
|
12
|
-
let tmpDir
|
|
13
|
-
|
|
14
13
|
try {
|
|
15
14
|
const projectName = await promptForProjectName()
|
|
16
15
|
if (!projectName) {
|
|
@@ -25,36 +24,32 @@ async function run() {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
const spinnerClone = ora("Creating project root...").start()
|
|
28
|
-
|
|
29
|
-
if (!tmpDir) {
|
|
30
|
-
spinnerClone.fail("Failed to clone repository.")
|
|
31
|
-
process.exit(1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const rootTemplateDir = await copyRootTemplate(tmpDir, targetDir)
|
|
27
|
+
const rootTemplateDir = await copyRootTemplate(targetDir)
|
|
35
28
|
spinnerClone.succeed()
|
|
36
29
|
|
|
37
|
-
const
|
|
38
|
-
type: "list",
|
|
39
|
-
name: "preset",
|
|
30
|
+
const preset = await select<Preset>({
|
|
40
31
|
message: "Select a preset:",
|
|
41
32
|
choices: [
|
|
42
|
-
{ name: "Standard", value: "" },
|
|
33
|
+
{ name: "Standard", value: "standard" },
|
|
43
34
|
{ name: "With i18n", value: "with-i18n" },
|
|
44
35
|
{ name: "With Tests", value: "with-tests" },
|
|
45
36
|
],
|
|
46
37
|
})
|
|
47
38
|
|
|
48
|
-
await copyPresetFiles(
|
|
39
|
+
await copyPresetFiles(preset, targetDir)
|
|
49
40
|
await updatePackageJson(rootTemplateDir, targetDir, preset, {
|
|
50
41
|
dependencies: PRESET_EXTRA_PACKAGES[preset]?.dependencies || {},
|
|
51
42
|
devDependencies: PRESET_EXTRA_PACKAGES[preset]?.devDependencies || {},
|
|
52
43
|
scripts: PRESET_EXTRA_SCRIPTS[preset] || {},
|
|
53
44
|
})
|
|
54
45
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
const envExamplePath = path.join(targetDir, ".env.example")
|
|
47
|
+
const envPath = path.join(targetDir, ".env")
|
|
48
|
+
if (await fs.pathExists(envExamplePath)) {
|
|
49
|
+
await fs.copy(envExamplePath, envPath)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const installDeps = await confirm({
|
|
58
53
|
message: "Install dependencies now?",
|
|
59
54
|
default: true,
|
|
60
55
|
})
|
|
@@ -65,9 +60,7 @@ async function run() {
|
|
|
65
60
|
spinnerInstall.succeed("Dependencies installed!")
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
const
|
|
69
|
-
type: "confirm",
|
|
70
|
-
name: "initGit",
|
|
63
|
+
const initGit = await confirm({
|
|
71
64
|
message: "Initialize a Git repository?",
|
|
72
65
|
default: true,
|
|
73
66
|
})
|
|
@@ -96,11 +89,6 @@ async function run() {
|
|
|
96
89
|
console.error("Error:", err)
|
|
97
90
|
process.exit(1)
|
|
98
91
|
}
|
|
99
|
-
finally {
|
|
100
|
-
if (tmpDir && await fs.pathExists(tmpDir)) {
|
|
101
|
-
await fs.remove(tmpDir)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
92
|
}
|
|
105
93
|
|
|
106
94
|
run()
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const REPO_URL = "https://github.com/matimortari/nuxtjs-starter.git";
|
|
2
|
-
export const PRESET_EXTRA_SCRIPTS = {
|
|
3
|
-
"standard": {},
|
|
4
|
-
"with-i18n": {},
|
|
5
|
-
"with-tests": {
|
|
6
|
-
"test": "vitest",
|
|
7
|
-
"test:e2e": "playwright test",
|
|
8
|
-
"coverage": "vitest --coverage",
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
export const PRESET_EXTRA_PACKAGES = {
|
|
12
|
-
"standard": {},
|
|
13
|
-
"with-i18n": {
|
|
14
|
-
dependencies: {
|
|
15
|
-
"@nuxtjs/i18n": "10.2.1",
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
"with-tests": {
|
|
19
|
-
devDependencies: {
|
|
20
|
-
"@nuxt/test-utils": "3.19.2",
|
|
21
|
-
"@vitest/coverage-v8": "4.0.15",
|
|
22
|
-
"@vue/test-utils": "3.20.0",
|
|
23
|
-
"happy-dom": "13.7.6",
|
|
24
|
-
"@playwright/test": "1.57.0",
|
|
25
|
-
"vitest": "4.0.15",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|