create-vixt 0.4.0 → 0.4.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/dist/index.mjs +65 -0
- package/package.json +1 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { cac } from 'cac';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
|
|
7
|
+
const version = "0.4.2";
|
|
8
|
+
|
|
9
|
+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
10
|
+
const argv = cac().parse();
|
|
11
|
+
const projectName = argv.args[0] || "vixt-project";
|
|
12
|
+
const templateName = argv.options.template || "monorepo-ts";
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
const projectPath = path.join(cwd, projectName);
|
|
15
|
+
const templatePath = path.join(__dirname, `../template-${templateName}`);
|
|
16
|
+
if (!fs.existsSync(templatePath)) {
|
|
17
|
+
console.error(`"${templateName}" isn't a valid template. Please confirm the template name.`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
if (!fs.existsSync(projectPath)) {
|
|
21
|
+
fs.mkdirSync(projectPath);
|
|
22
|
+
console.log(`Project directory ${projectName} created.`);
|
|
23
|
+
} else {
|
|
24
|
+
console.error(`Directory ${projectName} already exists.`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
function editPackageJson(destDir, fn) {
|
|
28
|
+
const packageJsonPath = path.join(destDir, "package.json");
|
|
29
|
+
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
30
|
+
const result = fn(packageJson) || packageJson;
|
|
31
|
+
fs.writeJSONSync(packageJsonPath, result, { spaces: 2 });
|
|
32
|
+
}
|
|
33
|
+
function copyTemplateFiles(srcDir, destDir) {
|
|
34
|
+
fs.copySync(srcDir, destDir);
|
|
35
|
+
editPackageJson(destDir, (json) => {
|
|
36
|
+
json.name = projectName;
|
|
37
|
+
Object.entries(json.dependencies).forEach(([key, value]) => {
|
|
38
|
+
if (value === "workspace:*") {
|
|
39
|
+
json.dependencies[key] = `^${version}`;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
copyTemplateFiles(templatePath, projectPath);
|
|
45
|
+
if (templateName === "monorepo-ts") {
|
|
46
|
+
const vueTemplatePath = path.join(__dirname, `../template-vue-ts`);
|
|
47
|
+
const vueProjectPath = path.join(projectPath, "packages/vue");
|
|
48
|
+
fs.copySync(vueTemplatePath, vueProjectPath);
|
|
49
|
+
editPackageJson(vueProjectPath, (json) => {
|
|
50
|
+
delete json.dependencies.vixt;
|
|
51
|
+
});
|
|
52
|
+
const uniTemplatePath = path.join(__dirname, `../template-uni-ts`);
|
|
53
|
+
const uniProjectPath = path.join(projectPath, "packages/uni");
|
|
54
|
+
fs.copySync(uniTemplatePath, uniProjectPath);
|
|
55
|
+
editPackageJson(uniProjectPath, (json) => {
|
|
56
|
+
delete json.dependencies.vixt;
|
|
57
|
+
});
|
|
58
|
+
const reactTemplatePath = path.join(__dirname, `../template-react-ts`);
|
|
59
|
+
const reactProjectPath = path.join(projectPath, "packages/react");
|
|
60
|
+
fs.copySync(reactTemplatePath, reactProjectPath);
|
|
61
|
+
editPackageJson(reactProjectPath, (json) => {
|
|
62
|
+
delete json.dependencies.vixt;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
console.log("Template project initialized.");
|