@zessjs/cli 1.0.0 → 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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  <div align="center">
2
- <img src="https://pic1.imgdb.cn/item/68c7c093c5157e1a8804fb52.svg" alt="Zess Logo">
2
+ <a href="https://rpsffx.github.io/zess" target="_blank" alt="Zess Logo">
3
+ <img src="https://pic1.imgdb.cn/item/68c7c093c5157e1a8804fb52.svg" alt="Zess Logo">
4
+ </a>
3
5
  </div>
4
6
 
5
7
  # @zessjs/cli
@@ -9,7 +11,7 @@
9
11
  Zess CLI tool 🔨 For easily creating Vite-powered Zess project.
10
12
 
11
13
  <div align="center">
12
- <img src="https://pic1.imgdb.cn/item/68d2c7b7c5157e1a882be39f.gif" alt="Zess CLI Usage" style="max-width: 100%; height: auto;">
14
+ <img src="https://pic1.imgdb.cn/item/68dea750c5157e1a885103f9.gif" alt="Zess CLI Usage" style="max-width: 100%; height: auto;">
13
15
  </div>
14
16
 
15
17
  ## 🚀 Usage
@@ -19,7 +21,7 @@ Zess CLI tool 🔨 For easily creating Vite-powered Zess project.
19
21
  Run the following command to create a new Zess project:
20
22
 
21
23
  ```bash
22
- npx create-zess my-app
24
+ npx -p @zessjs/cli init my-app
23
25
  ```
24
26
 
25
27
  Where `my-app` is the directory where you want to create your project.
@@ -43,7 +45,7 @@ Then open your browser and visit:
43
45
 
44
46
  The Zess CLI is compatible with:
45
47
 
46
- - Node.js >=18.12.0
48
+ - Node.js >=18.0.0
47
49
 
48
50
  ## 📝 License
49
51
 
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.1";
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, "utf-8");
80
+ const destGitignore = await readFile(destPath, "utf-8");
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, "utf-8");
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, "utf-8"));
114
+ if (existsSync(destPath)) {
115
+ const destPackageJson = JSON.parse(await readFile(destPath, "utf-8"));
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
+ }
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": "@zessjs/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Zess CLI tool 🔨 For easily creating Vite-powered Zess project.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -19,8 +19,12 @@
19
19
  "directory": "packages/cli"
20
20
  },
21
21
  "author": "Columsys",
22
+ "files": [
23
+ "dist",
24
+ "template"
25
+ ],
22
26
  "bin": {
23
- "create-zess": "index.ts"
27
+ "init": "./dist/index.js"
24
28
  },
25
29
  "publishConfig": {
26
30
  "access": "public"
@@ -32,6 +36,10 @@
32
36
  "picocolors": "^1.1.1"
33
37
  },
34
38
  "engines": {
35
- "node": ">=18.12.0"
39
+ "node": ">=18.0.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsdown",
43
+ "dev": "tsdown --watch"
36
44
  }
37
45
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zess-app",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -12,20 +12,20 @@
12
12
  "format": "prettier --cache --write ."
13
13
  },
14
14
  "dependencies": {
15
- "@tailwindcss/vite": "^4.1.13",
16
- "@zessjs/core": "^1.0.0",
17
- "@zessjs/router": "^1.0.0",
18
- "tailwindcss": "^4.1.13"
15
+ "@tailwindcss/vite": "^4.1.14",
16
+ "@zessjs/core": "^1.0.2",
17
+ "@zessjs/router": "^1.0.2",
18
+ "tailwindcss": "^4.1.14"
19
19
  },
20
20
  "devDependencies": {
21
- "@sxzz/eslint-config": "^7.2.1",
21
+ "@sxzz/eslint-config": "^7.2.6",
22
22
  "@sxzz/prettier-config": "^2.2.4",
23
- "@zessjs/vite-plugin": "^1.0.0",
23
+ "@zessjs/vite-plugin": "^1.0.2",
24
24
  "eslint": "^9.36.0",
25
25
  "eslint-plugin-react": "^7.37.5",
26
26
  "jsdom": "^27.0.0",
27
27
  "prettier": "^3.6.2",
28
- "typescript": "^5.9.2",
28
+ "typescript": "^5.9.3",
29
29
  "vite": "^6.3.6",
30
30
  "vitest": "^3.2.4"
31
31
  },
package/index.ts DELETED
@@ -1,210 +0,0 @@
1
- #!/usr/bin/env -S npx tsx
2
-
3
- import child_process from 'node:child_process'
4
- import { existsSync } from 'node:fs'
5
- import { copyFile, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
6
- import path from 'node:path'
7
- import process from 'node:process'
8
- import { fileURLToPath } from 'node:url'
9
- import { promisify } from 'node:util'
10
- import {
11
- cancel,
12
- intro,
13
- isCancel,
14
- log,
15
- note,
16
- outro,
17
- select,
18
- spinner,
19
- text,
20
- } from '@clack/prompts'
21
- import { program } from 'commander'
22
- import gradient from 'gradient-string'
23
- import pc from 'picocolors'
24
- import { description, version } from './package.json'
25
- import { name } from './template/common/package.json'
26
-
27
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
28
- const exec = promisify(child_process.exec)
29
-
30
- function showWelcomeMessage(): void {
31
- process.stdout.write('\n')
32
- intro(
33
- gradient(['skyblue', 'khaki'])(
34
- 'Welcome to Zess - A compiler-driven framework for high-performance web apps',
35
- ),
36
- )
37
- }
38
-
39
- async function promptUser(): Promise<{
40
- projectName: string
41
- useTypeScript: boolean
42
- }> {
43
- const projectName = await text({
44
- message: 'Project name:',
45
- placeholder: name,
46
- defaultValue: name,
47
- validate(value) {
48
- if (value && !value.trim()) {
49
- return 'Project name cannot be empty'
50
- }
51
- },
52
- })
53
- if (isCancel(projectName)) {
54
- cancel('Operation cancelled')
55
- return process.exit(0)
56
- }
57
- const useTypeScript = await select({
58
- message: 'Project language:',
59
- options: [
60
- { value: true, label: 'TypeScript' },
61
- { value: false, label: 'JavaScript' },
62
- ],
63
- })
64
- if (isCancel(useTypeScript)) {
65
- cancel('Operation cancelled')
66
- return process.exit(0)
67
- }
68
- return { projectName, useTypeScript }
69
- }
70
-
71
- async function createProject(
72
- directoryName: string,
73
- projectName: string,
74
- useTypeScript: boolean,
75
- ): Promise<void> {
76
- const directoryPath = path.join(process.cwd(), directoryName)
77
- if (existsSync(directoryPath)) {
78
- log.step(`Using existing directory: ${pc.cyan(directoryName)}`)
79
- } else {
80
- log.step(`Creating project directory: ${pc.cyan(directoryName)}`)
81
- await mkdir(directoryPath, { recursive: true })
82
- }
83
- await copyTemplateFiles(directoryPath, projectName, useTypeScript)
84
- await installDependencies(directoryPath)
85
- }
86
-
87
- async function copyTemplateFiles(
88
- projectPath: string,
89
- projectName: string,
90
- useTypeScript: boolean,
91
- ): Promise<void> {
92
- const setupSpinner = spinner()
93
- setupSpinner.start('Setting up project files...')
94
- const templatePath = path.join(__dirname, 'template')
95
- await copyDirectory(path.join(templatePath, 'common'), projectPath, {
96
- '.gitignore': async (srcPath, destPath) => {
97
- if (!existsSync(destPath)) return true
98
- const srcGitignore = await readFile(srcPath, 'utf-8')
99
- const destGitignore = await readFile(destPath, 'utf-8')
100
- await writeFile(destPath, `${destGitignore}\n${srcGitignore}`)
101
- },
102
- 'package.json': async (srcPath, destPath) => {
103
- await mergePackageJson(srcPath, destPath, projectName, useTypeScript)
104
- },
105
- 'README.md': async (srcPath, destPath) => {
106
- if (projectName === name) return true
107
- const srcReadme = await readFile(srcPath, 'utf-8')
108
- await writeFile(destPath, srcReadme.replace(name, projectName))
109
- },
110
- })
111
- await copyDirectory(
112
- path.join(templatePath, useTypeScript ? 'typescript' : 'javascript'),
113
- projectPath,
114
- )
115
- setupSpinner.stop('Project files set up')
116
- }
117
-
118
- async function installDependencies(projectPath: string): Promise<void> {
119
- const installSpinner = spinner()
120
- installSpinner.start('Installing dependencies...')
121
- await exec('npm install', { cwd: projectPath })
122
- installSpinner.stop('Dependencies installed successfully!')
123
- }
124
-
125
- async function copyDirectory(
126
- srcDir: string,
127
- destDir: string,
128
- handlers?: Record<
129
- string,
130
- (src: string, dest: string) => Promise<boolean | void>
131
- >,
132
- ): Promise<void> {
133
- const files = await readdir(srcDir, { withFileTypes: true })
134
- if (!existsSync(destDir)) await mkdir(destDir, { recursive: true })
135
- for (const file of files) {
136
- const srcPath = path.join(srcDir, file.name)
137
- const destPath = path.join(destDir, file.name)
138
- if (
139
- handlers?.[file.name] &&
140
- !(await handlers[file.name](srcPath, destPath))
141
- ) {
142
- continue
143
- }
144
- if (file.isDirectory()) {
145
- await copyDirectory(srcPath, destPath, handlers)
146
- } else {
147
- await copyFile(srcPath, destPath)
148
- }
149
- }
150
- }
151
-
152
- async function mergePackageJson(
153
- srcPath: string,
154
- destPath: string,
155
- projectName: string,
156
- useTypeScript: boolean,
157
- ): Promise<void> {
158
- let srcPackageJson = JSON.parse(await readFile(srcPath, 'utf-8'))
159
- if (existsSync(destPath)) {
160
- const destPackageJson = JSON.parse(await readFile(destPath, 'utf-8'))
161
- Object.assign(destPackageJson.dependencies, srcPackageJson.dependencies)
162
- Object.assign(
163
- destPackageJson.devDependencies,
164
- srcPackageJson.devDependencies,
165
- )
166
- Object.assign(destPackageJson.scripts, srcPackageJson.scripts)
167
- destPackageJson.prettier = srcPackageJson.prettier
168
- srcPackageJson = destPackageJson
169
- }
170
- srcPackageJson.name = projectName
171
- delete srcPackageJson.devDependencies[
172
- useTypeScript ? 'eslint-plugin-react' : 'typescript'
173
- ]
174
- await writeFile(destPath, JSON.stringify(srcPackageJson, null, 2))
175
- }
176
-
177
- function showInstructions(title: string, ...instructions: string[]): void {
178
- note(instructions.map(pc.cyan).join('\n'), title)
179
- }
180
-
181
- function init(): void {
182
- program
183
- .version(version)
184
- .description(description)
185
- .argument('<directory>', 'directory to create the project in')
186
- .action(async (directory: string) => {
187
- showWelcomeMessage()
188
- const { projectName, useTypeScript } = await promptUser()
189
- try {
190
- await createProject(directory, projectName, useTypeScript)
191
- showInstructions(
192
- 'Done! We suggest you start by typing:',
193
- `cd ${directory}`,
194
- 'npm run dev',
195
- )
196
- showInstructions(
197
- 'Then open your browser and visit:',
198
- 'Local: http://localhost:5173/',
199
- 'Network: use --host to expose',
200
- )
201
- outro('Happy coding with your Zess project!')
202
- } catch (error) {
203
- process.stderr.write(error?.message ?? error)
204
- process.exit(1)
205
- }
206
- })
207
- .parse()
208
- }
209
-
210
- init()