@zessjs/cli 1.0.5 → 1.0.6
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 +146 -0
- package/package.json +1 -1
- package/template/common/package.json +4 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import child_process from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
|
+
import { cancel, intro, isCancel, log, note, outro, select, spinner, text } from "@clack/prompts";
|
|
10
|
+
import { program } from "commander";
|
|
11
|
+
import gradient from "gradient-string";
|
|
12
|
+
import pc from "picocolors";
|
|
13
|
+
|
|
14
|
+
//#region package.json
|
|
15
|
+
var version = "1.0.6";
|
|
16
|
+
var description = "Zess CLI tool 🔨 For easily creating Vite-powered Zess project.";
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region template/common/package.json
|
|
20
|
+
var name = "zess-app";
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/index.ts
|
|
24
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const exec = promisify(child_process.exec);
|
|
26
|
+
function showWelcomeMessage() {
|
|
27
|
+
process.stdout.write("\n");
|
|
28
|
+
intro(gradient(["skyblue", "khaki"])("Welcome to Zess - A compiler-driven framework for high-performance web apps"));
|
|
29
|
+
}
|
|
30
|
+
async function promptUser() {
|
|
31
|
+
const projectName = await text({
|
|
32
|
+
message: "Project name:",
|
|
33
|
+
placeholder: name,
|
|
34
|
+
defaultValue: name,
|
|
35
|
+
validate(value) {
|
|
36
|
+
if (value && !value.trim()) return "Project name cannot be empty";
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (isCancel(projectName)) {
|
|
40
|
+
cancel("Operation cancelled");
|
|
41
|
+
return process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
const useTypeScript = await select({
|
|
44
|
+
message: "Project language:",
|
|
45
|
+
options: [{
|
|
46
|
+
value: true,
|
|
47
|
+
label: "TypeScript"
|
|
48
|
+
}, {
|
|
49
|
+
value: false,
|
|
50
|
+
label: "JavaScript"
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
if (isCancel(useTypeScript)) {
|
|
54
|
+
cancel("Operation cancelled");
|
|
55
|
+
return process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
projectName,
|
|
59
|
+
useTypeScript
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function createProject(directoryName, projectName, useTypeScript) {
|
|
63
|
+
const directoryPath = path.join(process.cwd(), directoryName);
|
|
64
|
+
if (existsSync(directoryPath)) log.step(`Using existing directory: ${pc.cyan(directoryName)}`);
|
|
65
|
+
else {
|
|
66
|
+
log.step(`Creating project directory: ${pc.cyan(directoryName)}`);
|
|
67
|
+
await mkdir(directoryPath, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
await copyTemplateFiles(directoryPath, projectName, useTypeScript);
|
|
70
|
+
await installDependencies(directoryPath);
|
|
71
|
+
}
|
|
72
|
+
async function copyTemplateFiles(projectPath, projectName, useTypeScript) {
|
|
73
|
+
const setupSpinner = spinner();
|
|
74
|
+
setupSpinner.start("Setting up project files...");
|
|
75
|
+
const templatePath = path.join(__dirname, "..", "template");
|
|
76
|
+
await copyDirectory(path.join(templatePath, "common"), projectPath, {
|
|
77
|
+
".gitignore": async (srcPath, destPath) => {
|
|
78
|
+
if (!existsSync(destPath)) return true;
|
|
79
|
+
const srcGitignore = await readFile(srcPath, "utf8");
|
|
80
|
+
const destGitignore = await readFile(destPath, "utf8");
|
|
81
|
+
await writeFile(destPath, `${destGitignore}\n${srcGitignore}`);
|
|
82
|
+
},
|
|
83
|
+
"package.json": async (srcPath, destPath) => {
|
|
84
|
+
await mergePackageJson(srcPath, destPath, projectName, useTypeScript);
|
|
85
|
+
},
|
|
86
|
+
"README.md": async (srcPath, destPath) => {
|
|
87
|
+
if (projectName === name) return true;
|
|
88
|
+
const srcReadme = await readFile(srcPath, "utf8");
|
|
89
|
+
await writeFile(destPath, srcReadme.replace(name, projectName));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
await copyDirectory(path.join(templatePath, useTypeScript ? "typescript" : "javascript"), projectPath);
|
|
93
|
+
setupSpinner.stop("Project files set up");
|
|
94
|
+
}
|
|
95
|
+
async function installDependencies(projectPath) {
|
|
96
|
+
const installSpinner = spinner();
|
|
97
|
+
installSpinner.start("Installing dependencies...");
|
|
98
|
+
await exec("npm install", { cwd: projectPath });
|
|
99
|
+
installSpinner.stop("Dependencies installed successfully!");
|
|
100
|
+
}
|
|
101
|
+
async function copyDirectory(srcDir, destDir, handlers) {
|
|
102
|
+
const files = await readdir(srcDir, { withFileTypes: true });
|
|
103
|
+
if (!existsSync(destDir)) await mkdir(destDir, { recursive: true });
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
const srcPath = path.join(srcDir, file.name);
|
|
106
|
+
const destPath = path.join(destDir, file.name);
|
|
107
|
+
if (handlers?.[file.name] && !await handlers[file.name](srcPath, destPath)) continue;
|
|
108
|
+
if (file.isDirectory()) await copyDirectory(srcPath, destPath, handlers);
|
|
109
|
+
else await copyFile(srcPath, destPath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function mergePackageJson(srcPath, destPath, projectName, useTypeScript) {
|
|
113
|
+
let srcPackageJson = JSON.parse(await readFile(srcPath, "utf8"));
|
|
114
|
+
if (existsSync(destPath)) {
|
|
115
|
+
const destPackageJson = JSON.parse(await readFile(destPath, "utf8"));
|
|
116
|
+
Object.assign(destPackageJson.dependencies, srcPackageJson.dependencies);
|
|
117
|
+
Object.assign(destPackageJson.devDependencies, srcPackageJson.devDependencies);
|
|
118
|
+
Object.assign(destPackageJson.scripts, srcPackageJson.scripts);
|
|
119
|
+
destPackageJson.prettier = srcPackageJson.prettier;
|
|
120
|
+
srcPackageJson = destPackageJson;
|
|
121
|
+
} else srcPackageJson.version = "0.0.0";
|
|
122
|
+
srcPackageJson.name = projectName;
|
|
123
|
+
delete srcPackageJson.devDependencies[useTypeScript ? "eslint-plugin-react" : "typescript"];
|
|
124
|
+
await writeFile(destPath, JSON.stringify(srcPackageJson, null, 2));
|
|
125
|
+
}
|
|
126
|
+
function showInstructions(title, ...instructions) {
|
|
127
|
+
note(instructions.map(pc.cyan).join("\n"), title);
|
|
128
|
+
}
|
|
129
|
+
function init() {
|
|
130
|
+
program.version(version).description(description).argument("<directory>", "directory to create the project in").action(async (directory) => {
|
|
131
|
+
showWelcomeMessage();
|
|
132
|
+
const { projectName, useTypeScript } = await promptUser();
|
|
133
|
+
try {
|
|
134
|
+
await createProject(directory, projectName, useTypeScript);
|
|
135
|
+
showInstructions("Done! We suggest you start by typing:", `cd ${directory}`, "npm run dev");
|
|
136
|
+
showInstructions("Then open your browser and visit:", "Local: http://localhost:5173/", "Network: use --host to expose");
|
|
137
|
+
outro("Happy coding with your Zess project!");
|
|
138
|
+
} catch (error) {
|
|
139
|
+
process.stderr.write(error?.message ?? error);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
}).parse();
|
|
143
|
+
}
|
|
144
|
+
init();
|
|
145
|
+
|
|
146
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zess-app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@tailwindcss/vite": "^4.1.14",
|
|
16
|
-
"@zessjs/core": "^1.0.
|
|
17
|
-
"@zessjs/router": "^1.0.
|
|
16
|
+
"@zessjs/core": "^1.0.6",
|
|
17
|
+
"@zessjs/router": "^1.0.6",
|
|
18
18
|
"tailwindcss": "^4.1.14"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@sxzz/eslint-config": "^7.2.6",
|
|
22
22
|
"@sxzz/prettier-config": "^2.2.4",
|
|
23
|
-
"@zessjs/vite-plugin": "^1.0.
|
|
23
|
+
"@zessjs/vite-plugin": "^1.0.6",
|
|
24
24
|
"eslint": "^9.36.0",
|
|
25
25
|
"eslint-plugin-react": "^7.37.5",
|
|
26
26
|
"jsdom": "^27.0.0",
|