create-newt-app 0.35.2 → 0.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +34 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
8
|
import { execa } from "execa";
|
|
9
9
|
import ejs from "ejs";
|
|
10
|
-
import { existsSync, promises } from "fs";
|
|
10
|
+
import { existsSync, promises, readdirSync } from "fs";
|
|
11
11
|
import path from "path";
|
|
12
12
|
import https from "node:https";
|
|
13
13
|
//#region package.json
|
|
14
|
-
var version = "0.35.
|
|
14
|
+
var version = "0.35.3";
|
|
15
15
|
var engines = { "node": ">=24.0.0" };
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/templates/root/index.ts
|
|
@@ -13899,27 +13899,41 @@ function validateNodeVersion(current, requirement) {
|
|
|
13899
13899
|
function normalizeProjectName(projectName) {
|
|
13900
13900
|
return projectName.trim().normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9\-._~]/g, "-").replace(/-+/g, "-").replace(/^[-._]+/, "").replace(/-+$/, "").slice(0, 214);
|
|
13901
13901
|
}
|
|
13902
|
+
function projectTarget(projectName) {
|
|
13903
|
+
if ([".", "./"].includes(projectName.trim())) return {
|
|
13904
|
+
name: normalizeProjectName(path.basename(process.cwd())),
|
|
13905
|
+
dir: "."
|
|
13906
|
+
};
|
|
13907
|
+
const name = normalizeProjectName(projectName);
|
|
13908
|
+
return {
|
|
13909
|
+
name,
|
|
13910
|
+
dir: name
|
|
13911
|
+
};
|
|
13912
|
+
}
|
|
13902
13913
|
function validateProjectName(projectName) {
|
|
13903
13914
|
if (!projectName) return {
|
|
13904
13915
|
valid: false,
|
|
13905
13916
|
error: "Project name is required"
|
|
13906
13917
|
};
|
|
13907
|
-
const
|
|
13908
|
-
if (!
|
|
13918
|
+
const { name, dir } = projectTarget(projectName);
|
|
13919
|
+
if (!name) return {
|
|
13909
13920
|
valid: false,
|
|
13910
13921
|
error: `"${projectName}" has nothing left after normalizing. Include a letter or a digit.`
|
|
13911
13922
|
};
|
|
13912
|
-
|
|
13913
|
-
|
|
13923
|
+
if (dir === ".") return readdirSync(process.cwd()).length === 0 ? { valid: true } : {
|
|
13924
|
+
valid: false,
|
|
13925
|
+
error: "The current directory is not empty"
|
|
13926
|
+
};
|
|
13927
|
+
if (existsSync(path.resolve(process.cwd(), dir))) return {
|
|
13914
13928
|
valid: false,
|
|
13915
|
-
error: `Directory "${
|
|
13929
|
+
error: `Directory "${dir}" already exists`
|
|
13916
13930
|
};
|
|
13917
13931
|
return { valid: true };
|
|
13918
13932
|
}
|
|
13919
13933
|
//#endregion
|
|
13920
13934
|
//#region src/tasks.ts
|
|
13921
13935
|
async function scaffold(modules, options) {
|
|
13922
|
-
const validation = validateProjectName(options.
|
|
13936
|
+
const validation = validateProjectName(options.dir);
|
|
13923
13937
|
if (!validation.valid) {
|
|
13924
13938
|
console.error(`Error: ${validation.error}`);
|
|
13925
13939
|
process.exit(1);
|
|
@@ -13936,12 +13950,12 @@ async function scaffold(modules, options) {
|
|
|
13936
13950
|
authSecret: randomBytes(32).toString("base64url"),
|
|
13937
13951
|
versions
|
|
13938
13952
|
};
|
|
13939
|
-
await renderTemplatesToDisk(modules, options.
|
|
13953
|
+
await renderTemplatesToDisk(modules, options.dir, templateData, options.selection);
|
|
13940
13954
|
const packages = modules.map((mod) => mod.packages).filter((ele) => ele !== void 0).flat();
|
|
13941
|
-
if (packages.length > 0) await updatePackageJson(options.
|
|
13955
|
+
if (packages.length > 0) await updatePackageJson(options.dir, packages, templateData);
|
|
13942
13956
|
const scripts = modules.map((mod) => mod.scripts).filter((ele) => ele !== void 0).flat();
|
|
13943
|
-
if (scripts.length > 0) await updateScripts(options.
|
|
13944
|
-
await sortPackageJsons(options.
|
|
13957
|
+
if (scripts.length > 0) await updateScripts(options.dir, scripts, templateData);
|
|
13958
|
+
await sortPackageJsons(options.dir);
|
|
13945
13959
|
}
|
|
13946
13960
|
async function hasCommand(command) {
|
|
13947
13961
|
try {
|
|
@@ -14229,13 +14243,14 @@ async function doInit(options) {
|
|
|
14229
14243
|
const rawName = answers.name ?? options.name ?? "";
|
|
14230
14244
|
const nameCheck = validateProjectName(rawName);
|
|
14231
14245
|
if (!nameCheck.valid) throw new Error(nameCheck.error);
|
|
14232
|
-
const name =
|
|
14246
|
+
const { name, dir } = projectTarget(rawName);
|
|
14233
14247
|
const taskBuilder = new TaskBuilder();
|
|
14234
14248
|
taskBuilder.add({
|
|
14235
14249
|
title: "Scaffolding project",
|
|
14236
14250
|
task: async () => {
|
|
14237
14251
|
await scaffold(allModules, {
|
|
14238
14252
|
name,
|
|
14253
|
+
dir,
|
|
14239
14254
|
testing,
|
|
14240
14255
|
database,
|
|
14241
14256
|
deployment,
|
|
@@ -14250,14 +14265,14 @@ async function doInit(options) {
|
|
|
14250
14265
|
taskBuilder.add({
|
|
14251
14266
|
title: "Installing with pnpm",
|
|
14252
14267
|
task: async () => {
|
|
14253
|
-
await pnpmInstall(
|
|
14268
|
+
await pnpmInstall(dir);
|
|
14254
14269
|
return "Installed.";
|
|
14255
14270
|
}
|
|
14256
14271
|
});
|
|
14257
14272
|
taskBuilder.add({
|
|
14258
14273
|
title: "Formatting",
|
|
14259
14274
|
task: async () => {
|
|
14260
|
-
await pnpmFormat(
|
|
14275
|
+
await pnpmFormat(dir);
|
|
14261
14276
|
return "Formatted.";
|
|
14262
14277
|
}
|
|
14263
14278
|
});
|
|
@@ -14266,19 +14281,19 @@ async function doInit(options) {
|
|
|
14266
14281
|
if (options.git) taskBuilder.add({
|
|
14267
14282
|
title: "Initializing git",
|
|
14268
14283
|
task: async () => {
|
|
14269
|
-
committed = await initGit(
|
|
14284
|
+
committed = await initGit(dir);
|
|
14270
14285
|
return committed ? "Initialized git." : "Initialized git, but could not commit.";
|
|
14271
14286
|
}
|
|
14272
14287
|
});
|
|
14273
14288
|
await p.tasks(taskBuilder.tasks);
|
|
14274
14289
|
p.outro(`Done!`);
|
|
14275
|
-
if (
|
|
14276
|
-
console.log(`Note: the project directory is "${
|
|
14290
|
+
if (dir !== "." && dir !== rawName) {
|
|
14291
|
+
console.log(`Note: the project directory is "${dir}", not "${rawName}".`);
|
|
14277
14292
|
console.log();
|
|
14278
14293
|
}
|
|
14279
14294
|
console.log("Next steps:");
|
|
14280
14295
|
console.log();
|
|
14281
|
-
console.log(chalk.blue(` cd ${
|
|
14296
|
+
if (dir !== ".") console.log(chalk.blue(` cd ${dir}`));
|
|
14282
14297
|
if (!options.install) {
|
|
14283
14298
|
console.log(chalk.blue(` pnpm install`));
|
|
14284
14299
|
console.log(chalk.blue(` pnpm format:fix`));
|