@finesoft/create-app 0.1.17 → 0.1.18
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/bin/create-finesoft-app.js +5 -0
- package/dist/index.mjs +35 -13
- package/package.json +3 -2
- package/templates/react/package.json +1 -1
- package/templates/react-minimal/package.json +1 -1
- package/templates/svelte/package.json +1 -1
- package/templates/svelte-minimal/package.json +1 -1
- package/templates/vue/package.json +1 -1
- package/templates/vue-minimal/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import * as prompts from "@clack/prompts";
|
|
|
2
2
|
import { bold, cyan, green, red } from "kolorist";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
//#region src/index.ts
|
|
6
7
|
const FRAMEWORKS = [
|
|
7
8
|
{
|
|
@@ -41,18 +42,35 @@ const FRAMEWORKS = [
|
|
|
41
42
|
}]
|
|
42
43
|
}
|
|
43
44
|
];
|
|
44
|
-
|
|
45
|
+
const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
46
|
+
function validateProjectName(value) {
|
|
47
|
+
if (!value) return "Project name is required";
|
|
48
|
+
if (/[^\w\-.]/.test(value)) return "Invalid project name";
|
|
49
|
+
}
|
|
50
|
+
function getProjectNameFromArgs(argv) {
|
|
51
|
+
return argv.find((arg) => !arg.startsWith("-"));
|
|
52
|
+
}
|
|
53
|
+
function resolveTemplateDir(templateName) {
|
|
54
|
+
return path.resolve(CURRENT_DIR, "..", "templates", templateName);
|
|
55
|
+
}
|
|
56
|
+
async function run(argv = process.argv.slice(2)) {
|
|
45
57
|
prompts.intro(bold("Create Finesoft App"));
|
|
58
|
+
const cliProjectName = getProjectNameFromArgs(argv);
|
|
59
|
+
const projectNameError = cliProjectName ? validateProjectName(cliProjectName) : void 0;
|
|
60
|
+
if (projectNameError) {
|
|
61
|
+
prompts.log.error(projectNameError);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
46
64
|
const project = await prompts.group({
|
|
47
|
-
name: () =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
65
|
+
name: () => {
|
|
66
|
+
if (cliProjectName) return Promise.resolve(cliProjectName);
|
|
67
|
+
return prompts.text({
|
|
68
|
+
message: "Project name",
|
|
69
|
+
placeholder: "my-finesoft-app",
|
|
70
|
+
defaultValue: "my-finesoft-app",
|
|
71
|
+
validate: validateProjectName
|
|
72
|
+
});
|
|
73
|
+
},
|
|
56
74
|
framework: () => prompts.select({
|
|
57
75
|
message: "Framework",
|
|
58
76
|
options: FRAMEWORKS.map((f) => ({
|
|
@@ -76,7 +94,7 @@ async function main() {
|
|
|
76
94
|
} });
|
|
77
95
|
const targetDir = path.resolve(process.cwd(), project.name);
|
|
78
96
|
const templateName = project.variant;
|
|
79
|
-
const templateDir =
|
|
97
|
+
const templateDir = resolveTemplateDir(templateName);
|
|
80
98
|
if (!fs.existsSync(templateDir)) {
|
|
81
99
|
prompts.log.error(`Template "${templateName}" not found at ${templateDir}`);
|
|
82
100
|
process.exit(1);
|
|
@@ -123,9 +141,13 @@ function copyDir(src, dest) {
|
|
|
123
141
|
else fs.copyFileSync(srcPath, destPath);
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
|
-
|
|
144
|
+
function isDirectExecution() {
|
|
145
|
+
if (!process.argv[1]) return false;
|
|
146
|
+
return path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
147
|
+
}
|
|
148
|
+
if (isDirectExecution()) run().catch((err) => {
|
|
127
149
|
console.error(err);
|
|
128
150
|
process.exit(1);
|
|
129
151
|
});
|
|
130
152
|
//#endregion
|
|
131
|
-
export {};
|
|
153
|
+
export { getProjectNameFromArgs, resolveTemplateDir, run, validateProjectName };
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finesoft/create-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Scaffold a new Finesoft Front project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
|
-
"create-finesoft-app": "
|
|
7
|
+
"create-finesoft-app": "bin/create-finesoft-app.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
+
"bin",
|
|
10
11
|
"dist",
|
|
11
12
|
"templates"
|
|
12
13
|
],
|