create-esmx 3.0.0-rc.35 → 3.0.0-rc.37

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 ADDED
@@ -0,0 +1,52 @@
1
+ <div align="center">
2
+ <img src="https://www.esmnext.com/logo.svg?t=2025" width="120" alt="Esmx Logo" />
3
+ <h1>create-esmx</h1>
4
+
5
+ <div>
6
+ <a href="https://www.npmjs.com/package/create-esmx">
7
+ <img src="https://img.shields.io/npm/v/create-esmx.svg" alt="npm version" />
8
+ </a>
9
+ <a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
10
+ <img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
11
+ </a>
12
+ <a href="https://www.esmnext.com/coverage/">
13
+ <img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
14
+ </a>
15
+ <a href="https://nodejs.org/">
16
+ <img src="https://img.shields.io/node/v/@esmx/core.svg" alt="node version" />
17
+ </a>
18
+ <a href="https://bundlephobia.com/package/create-esmx">
19
+ <img src="https://img.shields.io/bundlephobia/minzip/create-esmx" alt="size" />
20
+ </a>
21
+ </div>
22
+
23
+ <p>A scaffold tool for creating Esmx projects</p>
24
+
25
+ <p>
26
+ English | <a href="https://github.com/esmnext/esmx/blob/master/packages/create-esmx/README.zh-CN.md">中文</a>
27
+ </p>
28
+ </div>
29
+
30
+ ## Features
31
+
32
+ - Interactive command-line interface
33
+ - Support for multiple project templates
34
+ - Complete TypeScript support
35
+ - Automatic project structure configuration
36
+
37
+ ## Usage
38
+
39
+ ```bash
40
+ # Using npm
41
+ npm create esmx@latest my-project
42
+
43
+ # Using yarn
44
+ yarn create esmx my-project
45
+
46
+ # Using pnpm
47
+ pnpm create esmx my-project
48
+ ```
49
+
50
+ ## License
51
+
52
+ MIT © Esmx Team
@@ -0,0 +1,52 @@
1
+ <div align="center">
2
+ <img src="https://www.esmnext.com/logo.svg?t=2025" width="120" alt="Esmx Logo" />
3
+ <h1>create-esmx</h1>
4
+
5
+ <div>
6
+ <a href="https://www.npmjs.com/package/create-esmx">
7
+ <img src="https://img.shields.io/npm/v/create-esmx.svg" alt="npm version" />
8
+ </a>
9
+ <a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
10
+ <img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
11
+ </a>
12
+ <a href="https://www.esmnext.com/coverage/">
13
+ <img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
14
+ </a>
15
+ <a href="https://nodejs.org/">
16
+ <img src="https://img.shields.io/node/v/@esmx/core.svg" alt="node version" />
17
+ </a>
18
+ <a href="https://bundlephobia.com/package/create-esmx">
19
+ <img src="https://img.shields.io/bundlephobia/minzip/create-esmx" alt="size" />
20
+ </a>
21
+ </div>
22
+
23
+ <p>用于创建 Esmx 项目的脚手架工具</p>
24
+
25
+ <p>
26
+ <a href="https://github.com/esmnext/esmx/blob/master/packages/create-esmx/README.md">English</a> | 中文
27
+ </p>
28
+ </div>
29
+
30
+ ## 功能特性
31
+
32
+ - 交互式命令行界面
33
+ - 支持多种项目模板
34
+ - 完整的 TypeScript 支持
35
+ - 自动配置项目结构
36
+
37
+ ## 安装使用
38
+
39
+ ```bash
40
+ # 使用 npm
41
+ npm create esmx@latest my-project
42
+
43
+ # 使用 yarn
44
+ yarn create esmx my-project
45
+
46
+ # 使用 pnpm
47
+ pnpm create esmx my-project
48
+ ```
49
+
50
+ ## 许可证
51
+
52
+ MIT © Esmx Team
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ import type { CliOptions } from './types';
2
+ /**
3
+ * Main function to create a project
4
+ */
5
+ export declare function cli(options?: CliOptions): Promise<void>;
@@ -1,9 +1,11 @@
1
1
  import { existsSync } from "node:fs";
2
+ import { readFileSync } from "node:fs";
2
3
  import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join } from "node:path";
5
6
  import { afterEach, beforeEach, describe, expect, it } from "vitest";
6
- import { createProject } from "./index.mjs";
7
+ import { cli } from "./cli.mjs";
8
+ import { getAvailableTemplates } from "./template.mjs";
7
9
  async function createTempDir(prefix = "esmx-test-") {
8
10
  return mkdtemp(join(tmpdir(), prefix));
9
11
  }
@@ -14,7 +16,75 @@ async function cleanupTempDir(tempDir) {
14
16
  console.warn(`Failed to cleanup temp directory: ${tempDir}`, error);
15
17
  }
16
18
  }
17
- describe("create-esmx integration tests", () => {
19
+ async function verifyProjectStructure(projectPath, projectName) {
20
+ expect(existsSync(projectPath)).toBe(true);
21
+ expect(existsSync(join(projectPath, "src"))).toBe(true);
22
+ const requiredFiles = [
23
+ "package.json",
24
+ "tsconfig.json",
25
+ "README.md",
26
+ "src/entry.client.ts",
27
+ "src/entry.node.ts",
28
+ "src/create-app.ts"
29
+ ];
30
+ for (const file of requiredFiles) {
31
+ expect(existsSync(join(projectPath, file))).toBe(true);
32
+ if (!existsSync(join(projectPath, file))) {
33
+ throw new Error(`Missing required file: ${file}`);
34
+ }
35
+ }
36
+ const packageJson = JSON.parse(
37
+ readFileSync(join(projectPath, "package.json"), "utf-8")
38
+ );
39
+ const typeCheckCommands = ["vue-tsc --noEmit", "tsc --noEmit"];
40
+ const typeGenCommands = [
41
+ "vue-tsc --declaration --emitDeclarationOnly --noEmit false --outDir dist/src && tsc-alias -p tsconfig.json --outDir dist/src",
42
+ "tsc --declaration --emitDeclarationOnly --outDir dist/src && tsc-alias -p tsconfig.json --outDir dist/src"
43
+ ];
44
+ expect(packageJson).toMatchObject({
45
+ name: projectName,
46
+ type: "module",
47
+ private: true,
48
+ scripts: {
49
+ dev: "esmx dev",
50
+ build: "esmx build",
51
+ preview: "esmx preview",
52
+ start: "NODE_ENV=production node dist/index.mjs"
53
+ },
54
+ dependencies: {
55
+ "@esmx/core": expect.any(String)
56
+ },
57
+ devDependencies: {
58
+ typescript: expect.any(String),
59
+ "@types/node": expect.any(String),
60
+ "tsc-alias": expect.any(String)
61
+ }
62
+ });
63
+ expect(packageJson.scripts["lint:type"]).toBeOneOf(typeCheckCommands);
64
+ expect(packageJson.scripts["build:type"]).toBeOneOf(typeGenCommands);
65
+ const tsconfig = JSON.parse(
66
+ readFileSync(join(projectPath, "tsconfig.json"), "utf-8")
67
+ );
68
+ expect(tsconfig).toMatchObject({
69
+ compilerOptions: {
70
+ module: "ESNext",
71
+ moduleResolution: "node",
72
+ target: "ESNext",
73
+ strict: true,
74
+ baseUrl: ".",
75
+ paths: {
76
+ [`${projectName}/src/*`]: ["./src/*"],
77
+ [`${projectName}/*`]: ["./*"]
78
+ }
79
+ },
80
+ include: ["src"],
81
+ exclude: ["dist", "node_modules"]
82
+ });
83
+ const readmeContent = readFileSync(join(projectPath, "README.md"), "utf-8");
84
+ expect(readmeContent.length).toBeGreaterThan(0);
85
+ expect(readmeContent).toContain(projectName);
86
+ }
87
+ describe("create-esmx CLI integration tests", () => {
18
88
  let tmpDir;
19
89
  beforeEach(async () => {
20
90
  tmpDir = await createTempDir();
@@ -22,32 +92,29 @@ describe("create-esmx integration tests", () => {
22
92
  afterEach(async () => {
23
93
  await cleanupTempDir(tmpDir);
24
94
  });
25
- it("should create project with vue2 template", async () => {
26
- const projectPath = join(tmpDir, "test-project");
27
- await createProject({
28
- argv: ["test-project", "--template", "vue2"],
29
- cwd: tmpDir,
30
- userAgent: "npm/test"
31
- });
32
- expect(existsSync(projectPath)).toBe(true);
33
- expect(existsSync(join(projectPath, "package.json"))).toBe(true);
34
- expect(existsSync(join(projectPath, "tsconfig.json"))).toBe(true);
35
- expect(existsSync(join(projectPath, "README.md"))).toBe(true);
36
- expect(existsSync(join(projectPath, "src"))).toBe(true);
37
- expect(existsSync(join(projectPath, "src/entry.client.ts"))).toBe(true);
38
- expect(existsSync(join(projectPath, "src/entry.node.ts"))).toBe(true);
39
- expect(existsSync(join(projectPath, "src/entry.server.ts"))).toBe(true);
40
- expect(existsSync(join(projectPath, "src/create-app.ts"))).toBe(true);
95
+ it("should create project with all available templates", async () => {
96
+ const templates = getAvailableTemplates();
97
+ expect(templates.length).toBeGreaterThan(0);
98
+ for (const template of templates) {
99
+ const projectName = `test-${template.folder}`;
100
+ const projectPath = join(tmpDir, projectName);
101
+ await cli({
102
+ argv: [projectName, "--template", template.folder],
103
+ cwd: tmpDir,
104
+ userAgent: "npm/test"
105
+ });
106
+ await verifyProjectStructure(projectPath, projectName);
107
+ }
41
108
  });
42
109
  it("should handle --force parameter correctly", async () => {
43
110
  const projectPath = join(tmpDir, "test-project");
44
- await createProject({
111
+ await cli({
45
112
  argv: ["test-project", "--template", "vue2"],
46
113
  cwd: tmpDir,
47
114
  userAgent: "npm/test"
48
115
  });
49
116
  expect(existsSync(join(projectPath, "package.json"))).toBe(true);
50
- await createProject({
117
+ await cli({
51
118
  argv: ["test-project", "--template", "vue2", "--force"],
52
119
  cwd: tmpDir,
53
120
  userAgent: "npm/test"
@@ -66,7 +133,7 @@ describe("create-esmx integration tests", () => {
66
133
  logOutput.push(args.join(" "));
67
134
  };
68
135
  try {
69
- await createProject({
136
+ await cli({
70
137
  argv: ["--help"],
71
138
  cwd: tmpDir,
72
139
  userAgent: "npm/test"
@@ -86,7 +153,7 @@ describe("create-esmx integration tests", () => {
86
153
  logOutput.push(args.join(" "));
87
154
  };
88
155
  try {
89
- await createProject({
156
+ await cli({
90
157
  argv: ["--version"],
91
158
  cwd: tmpDir,
92
159
  userAgent: "npm/test"
@@ -99,7 +166,7 @@ describe("create-esmx integration tests", () => {
99
166
  });
100
167
  it("should handle creating directory when target directory does not exist", async () => {
101
168
  const projectPath = join(tmpDir, "non-existent-parent", "test-project");
102
- await createProject({
169
+ await cli({
103
170
  argv: ["non-existent-parent/test-project", "--template", "vue2"],
104
171
  cwd: tmpDir,
105
172
  userAgent: "npm/test"
@@ -115,7 +182,7 @@ describe("create-esmx integration tests", () => {
115
182
  join(projectPath, "existing-file.txt"),
116
183
  "existing content"
117
184
  );
118
- await createProject({
185
+ await cli({
119
186
  argv: ["test-project", "--template", "vue2", "--force"],
120
187
  cwd: tmpDir,
121
188
  userAgent: "npm/test"
@@ -126,7 +193,7 @@ describe("create-esmx integration tests", () => {
126
193
  it("should handle force overwrite in current directory", async () => {
127
194
  const testFile = join(tmpDir, "existing-file.txt");
128
195
  await writeFile(testFile, "existing content");
129
- await createProject({
196
+ await cli({
130
197
  argv: [".", "--template", "vue2", "--force"],
131
198
  cwd: tmpDir,
132
199
  userAgent: "npm/test"
@@ -136,7 +203,7 @@ describe("create-esmx integration tests", () => {
136
203
  expect(existsSync(join(tmpDir, "src/entry.client.ts"))).toBe(true);
137
204
  });
138
205
  it('should create project in current directory when target is "."', async () => {
139
- await createProject({
206
+ await cli({
140
207
  argv: [".", "--template", "vue2"],
141
208
  cwd: tmpDir,
142
209
  userAgent: "npm/test"
@@ -153,7 +220,7 @@ describe("create-esmx integration tests", () => {
153
220
  ];
154
221
  for (const projectName of testCases) {
155
222
  const projectPath = join(tmpDir, projectName);
156
- await createProject({
223
+ await cli({
157
224
  argv: [projectName, "--template", "vue2"],
158
225
  cwd: tmpDir,
159
226
  userAgent: "npm/test"
package/dist/cli.mjs CHANGED
@@ -1,6 +1,156 @@
1
- #!/usr/bin/env node
2
- import { createProject } from "./index.mjs";
3
- createProject().catch((error) => {
4
- console.error("Error creating project:", error);
5
- process.exit(1);
6
- });
1
+ import {
2
+ cancel,
3
+ intro,
4
+ isCancel,
5
+ note,
6
+ outro,
7
+ select,
8
+ text
9
+ } from "@clack/prompts";
10
+ import minimist from "minimist";
11
+ import color from "picocolors";
12
+ import { createProjectFromTemplate } from "./project.mjs";
13
+ import { getAvailableTemplates, getEsmxVersion } from "./template.mjs";
14
+ import { formatProjectName, getCommand } from "./utils/index.mjs";
15
+ function showHelp(userAgent) {
16
+ const createCmd = getCommand("create", userAgent);
17
+ console.log(`
18
+ ${color.reset(color.bold(color.blue("\u{1F680} Create Esmx Project")))}
19
+
20
+ ${color.bold("Usage:")}
21
+ ${createCmd} [project-name]
22
+ ${createCmd} [project-name] [options]
23
+
24
+ ${color.bold("Options:")}
25
+ -t, --template <template> Template to use (default: vue2)
26
+ -n, --name <name> Project name or path
27
+ -f, --force Force overwrite existing directory
28
+ -h, --help Show help information
29
+ -v, --version Show version number
30
+
31
+ ${color.bold("Examples:")}
32
+ ${createCmd} my-project
33
+ ${createCmd} my-project -t vue2
34
+ ${createCmd} my-project --force
35
+ ${createCmd} . -f -t vue2
36
+
37
+ ${color.bold("Available Templates:")}
38
+ ${getAvailableTemplates().map((t) => ` ${t.folder.padEnd(25)} ${t.description}`).join("\n")}
39
+
40
+ For more information, visit: ${color.cyan("https://esmnext.com")}
41
+ `);
42
+ }
43
+ async function getProjectName(argName, positionalName) {
44
+ const providedName = argName || positionalName;
45
+ if (providedName) {
46
+ return providedName;
47
+ }
48
+ const projectName = await text({
49
+ message: "Project name or path:",
50
+ placeholder: "my-esmx-project",
51
+ validate: (value) => {
52
+ if (!value.trim()) {
53
+ return "Project name or path is required";
54
+ }
55
+ if (!/^[a-zA-Z0-9_.\/@-]+$/.test(value.trim())) {
56
+ return "Project name or path should only contain letters, numbers, hyphens, underscores, dots, and slashes";
57
+ }
58
+ }
59
+ });
60
+ return String(projectName).trim();
61
+ }
62
+ async function getTemplateType(argTemplate) {
63
+ const availableTemplates = getAvailableTemplates();
64
+ if (argTemplate && availableTemplates.some((t) => t.folder === argTemplate)) {
65
+ return argTemplate;
66
+ }
67
+ const options = availableTemplates.map((t) => ({
68
+ label: color.reset(color.gray(`${t.folder} - `) + color.bold(t.name)),
69
+ value: t.folder,
70
+ hint: t.description
71
+ }));
72
+ const template = await select({
73
+ message: "Select a template:",
74
+ options
75
+ });
76
+ return template;
77
+ }
78
+ export async function cli(options = {}) {
79
+ const { argv, cwd, userAgent } = options;
80
+ const commandLineArgs = argv || process.argv.slice(2);
81
+ const workingDir = cwd || process.cwd();
82
+ const parsedArgs = minimist(commandLineArgs, {
83
+ string: ["template", "name"],
84
+ boolean: ["help", "version", "force"],
85
+ alias: {
86
+ t: "template",
87
+ n: "name",
88
+ f: "force",
89
+ h: "help",
90
+ v: "version"
91
+ }
92
+ });
93
+ if (parsedArgs.help) {
94
+ showHelp(userAgent);
95
+ return;
96
+ }
97
+ if (parsedArgs.version) {
98
+ console.log(getEsmxVersion());
99
+ return;
100
+ }
101
+ console.log();
102
+ intro(
103
+ color.reset(
104
+ color.bold(color.blue("\u{1F680} Welcome to Esmx Project Creator!"))
105
+ )
106
+ );
107
+ const projectNameInput = await getProjectName(
108
+ parsedArgs.name,
109
+ parsedArgs._[0]
110
+ );
111
+ if (isCancel(projectNameInput)) {
112
+ cancel("Operation cancelled");
113
+ return;
114
+ }
115
+ const { packageName, targetDir } = formatProjectName(
116
+ projectNameInput,
117
+ workingDir
118
+ );
119
+ const templateType = await getTemplateType(parsedArgs.template);
120
+ if (isCancel(templateType)) {
121
+ cancel("Operation cancelled");
122
+ return;
123
+ }
124
+ const installCommand = getCommand("install", userAgent);
125
+ const devCommand = getCommand("dev", userAgent);
126
+ const buildCommand = getCommand("build", userAgent);
127
+ const startCommand = getCommand("start", userAgent);
128
+ const buildTypeCommand = getCommand("build:type", userAgent);
129
+ const lintTypeCommand = getCommand("lint:type", userAgent);
130
+ await createProjectFromTemplate(
131
+ targetDir,
132
+ templateType,
133
+ workingDir,
134
+ parsedArgs.force,
135
+ {
136
+ projectName: packageName,
137
+ esmxVersion: getEsmxVersion(),
138
+ installCommand,
139
+ devCommand,
140
+ buildCommand,
141
+ startCommand,
142
+ buildTypeCommand,
143
+ lintTypeCommand
144
+ }
145
+ );
146
+ const installCmd = installCommand;
147
+ const devCmd = devCommand;
148
+ const nextSteps = [
149
+ color.reset(`1. ${color.cyan(`cd ${targetDir}`)}`),
150
+ color.reset(`2. ${color.cyan(installCmd)}`),
151
+ color.reset(`3. ${color.cyan("git init")} ${color.gray("(optional)")}`),
152
+ color.reset(`4. ${color.cyan(devCmd)}`)
153
+ ];
154
+ note(nextSteps.join("\n"), "Next steps");
155
+ outro(color.reset(color.green("Happy coding! \u{1F389}")));
156
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from "./cli.mjs";
3
+ cli().catch((error) => {
4
+ console.error("Error creating project:", error);
5
+ process.exit(1);
6
+ });
package/dist/index.d.ts CHANGED
@@ -1,8 +1 @@
1
- #!/usr/bin/env node
2
- interface CreateProjectOptions {
3
- argv?: string[];
4
- cwd?: string;
5
- userAgent?: string;
6
- }
7
- export declare function createProject(options?: CreateProjectOptions): Promise<void>;
8
- export default createProject;
1
+ export { cli } from './cli';