create-antd-layout 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/bin/index.js +35 -39
  2. package/package.json +2 -1
package/bin/index.js CHANGED
@@ -13,23 +13,9 @@ const execa_1 = require("execa");
13
13
  const inquirer_1 = __importDefault(require("inquirer"));
14
14
  const degit_1 = __importDefault(require("degit"));
15
15
  const TEMPLATES = [
16
- {
17
- name: "SPA + Vite (Simple)",
18
- value: "antd-layout-vite-simple",
19
- type: "local",
20
- },
21
- {
22
- name: "SPA + Vite (Max)",
23
- value: "antd-layout-vite-max",
24
- type: "remote",
25
- repo: "zhouwenqi/adminui-demo-antd-layout-max",
26
- },
27
- {
28
- name: "SSR + Next (Pro)",
29
- value: "antd-layout-pro",
30
- type: "remote",
31
- repo: "zhouwenqi/adminui-demo-antd-layout-pro",
32
- },
16
+ { name: "SPA + Vite (Simple)", value: "antd-layout-vite-simple", type: "local" },
17
+ { name: "SPA + Vite (Max)", value: "antd-layout-vite-max", type: "private", repo: "zhouwenqi/adminui-demo-antd-layout-max" },
18
+ { name: "SSR + Next (Pro)", value: "antd-layout-pro", type: "public", repo: "adminui-demo-antd-layout-pro" },
33
19
  ];
34
20
  const PACKAGE_MANAGERS = [
35
21
  { name: 'npm', value: 'npm' },
@@ -75,7 +61,7 @@ ${packageManager} install`));
75
61
  const program = new commander_1.Command();
76
62
  program
77
63
  .name('create-antd-layout')
78
- .description("Create a new antd-layout project from local or remote templates")
64
+ .description("Create a new antd-layout project from local, private, or public templates")
79
65
  .version("1.0.0")
80
66
  .argument("<project-directory>", 'Project directory name')
81
67
  .action(async (projectDir) => {
@@ -96,14 +82,14 @@ program
96
82
  ]);
97
83
  const selectedValue = answers.template;
98
84
  const template = TEMPLATES.find(t => t.value === selectedValue);
99
- let copySpinner;
100
- if (template.type === 'local') {
85
+ let copySpinner = (0, ora_1.default)();
86
+ if (template.type === "local") {
101
87
  const templatePath = path_1.default.join(__dirname, `../templates/${template.value}`);
102
88
  if (!fs_extra_1.default.existsSync(templatePath)) {
103
89
  console.error(chalk_1.default.red(`❌ Local template '${template.value}' does not exist in templates/ directory.`));
104
90
  process.exit(1);
105
91
  }
106
- copySpinner = (0, ora_1.default)(`Copying local template "${template.value}"...`).start();
92
+ copySpinner.start(`Copying local template "${template.value}"...`);
107
93
  try {
108
94
  await fs_extra_1.default.copy(templatePath, targetDir);
109
95
  copySpinner.succeed(`Local template "${template.value}" copied!`);
@@ -114,11 +100,7 @@ program
114
100
  process.exit(1);
115
101
  }
116
102
  }
117
- else if (template.type === 'remote') {
118
- if (!template.repo) {
119
- console.error(chalk_1.default.red(`❌ Remote template '${template.value}' missing repo field.`));
120
- process.exit(1);
121
- }
103
+ else if (template.type === "private") {
122
104
  const tokenAnswer = await inquirer_1.default.prompt([
123
105
  {
124
106
  type: 'password',
@@ -129,30 +111,44 @@ program
129
111
  ]);
130
112
  const token = tokenAnswer.token.trim();
131
113
  const repoUrl = `https://${token}@github.com/${template.repo}.git`;
132
- copySpinner = (0, ora_1.default)(`Downloading private template from ${template.repo}...`).start();
114
+ copySpinner.start(`Cloning private template from ${template.repo}...`);
133
115
  try {
134
- const emitter = (0, degit_1.default)(repoUrl, {
135
- cache: false,
136
- force: true,
137
- verbose: false,
138
- });
139
- await emitter.clone(targetDir);
140
- copySpinner.succeed(`Private template from ${template.repo} downloaded!`);
116
+ await (0, execa_1.execa)('git', ['clone', repoUrl, targetDir], { stdio: 'ignore' });
117
+ await fs_extra_1.default.remove(path_1.default.join(targetDir, '.git')); // 清理 .git
118
+ copySpinner.succeed(`Private template cloned and cleaned!`);
141
119
  }
142
120
  catch (err) {
143
- copySpinner.fail("Failed to download private template.");
144
- if (err.message?.includes('404')) {
145
- console.error(chalk_1.default.red('❌ Repository not found. Please check owner/repo name and token permissions.'));
146
- }
147
- else if (err.message?.includes('403') || err.message?.includes('Authentication failed')) {
121
+ copySpinner.fail("Failed to clone private template.");
122
+ if (err.stderr?.includes('403') || err.message?.includes('Authentication failed')) {
148
123
  console.error(chalk_1.default.red('❌ Invalid token or insufficient permissions. Token needs "repo" scope.'));
149
124
  }
125
+ else if (err.stderr?.includes('404')) {
126
+ console.error(chalk_1.default.red('❌ Repository not found. Check owner/repo name.'));
127
+ }
150
128
  else {
151
129
  console.error(err);
152
130
  }
153
131
  process.exit(1);
154
132
  }
155
133
  }
134
+ else if (template.type === "public") {
135
+ // 公开模板:使用 degit
136
+ copySpinner.start(`Downloading public template from ${template.repo}...`);
137
+ try {
138
+ const emitter = (0, degit_1.default)(template.repo, {
139
+ cache: false,
140
+ force: true,
141
+ verbose: false,
142
+ });
143
+ await emitter.clone(targetDir);
144
+ copySpinner.succeed(`Public template from ${template.repo} downloaded!`);
145
+ }
146
+ catch (err) {
147
+ copySpinner.fail("Failed to download public template.");
148
+ console.error(err);
149
+ process.exit(1);
150
+ }
151
+ }
156
152
  const pkgPath = path_1.default.join(targetDir, 'package.json');
157
153
  if (fs_extra_1.default.existsSync(pkgPath)) {
158
154
  const pkg = await fs_extra_1.default.readJSON(pkgPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-antd-layout",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "this is create project for @adminui-dev/antd-layout's template proejct",
5
5
  "keywords": [
6
6
  "create-antd-layout",
@@ -25,6 +25,7 @@
25
25
  "homepage": "https://demo.adminui.dev",
26
26
  "scripts": {
27
27
  "build": "tsc",
28
+ "bw": "tsc -w",
28
29
  "dev": "ts-node src/index.ts",
29
30
  "test": "echo \"Error: no test specified\" && exit 1"
30
31
  },