create-revo 1.2.5 → 1.2.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/cli.js +33 -15
- package/package.json +1 -1
- package/template/package-lock.json +3 -3
- package/template/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
5
|
-
import { fileURLToPath } from
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
6
|
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
@@ -10,7 +10,7 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
const projectName = process.argv[2];
|
|
11
11
|
|
|
12
12
|
if (!projectName) {
|
|
13
|
-
console.error(
|
|
13
|
+
console.error("Please provide a project name: npx create-revo [project-name]");
|
|
14
14
|
process.exit(1);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,13 +19,13 @@ const targetDir = path.join(process.cwd(), projectName);
|
|
|
19
19
|
function replacePlaceholders(content, placeholderValues) {
|
|
20
20
|
Object.keys(placeholderValues).forEach((key) => {
|
|
21
21
|
const placeholder = `{{${key}}}`;
|
|
22
|
-
content = content.replace(new RegExp(placeholder,
|
|
22
|
+
content = content.replace(new RegExp(placeholder, "g"), placeholderValues[key]);
|
|
23
23
|
});
|
|
24
24
|
return content;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function copyTemplateFiles() {
|
|
28
|
-
const templateDir = path.join(__dirname,
|
|
28
|
+
const templateDir = path.join(__dirname, "template");
|
|
29
29
|
|
|
30
30
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
31
31
|
|
|
@@ -45,30 +45,48 @@ function copyRecursive(source, target) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function sanitizeProjectName(name) {
|
|
49
|
+
return name
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.replace(/[^a-z0-9-_~]/g, '-')
|
|
52
|
+
.replace(/^-+|-+$/g, '');
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
function replacePlaceholdersInDirectory(directory, placeholderValues) {
|
|
56
|
+
|
|
57
|
+
const sanitizedProjectName = sanitizeProjectName(placeholderValues.projectName);
|
|
58
|
+
|
|
49
59
|
fs.readdirSync(directory).forEach((file) => {
|
|
50
60
|
const filePath = path.join(directory, file);
|
|
51
61
|
if (fs.statSync(filePath).isDirectory()) {
|
|
52
62
|
replacePlaceholdersInDirectory(filePath, placeholderValues);
|
|
53
63
|
} else {
|
|
54
|
-
let content = fs.readFileSync(filePath,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
let content = fs.readFileSync(filePath, "utf8");
|
|
65
|
+
|
|
66
|
+
if (file === "package.json" || file === "package-lock.json") {
|
|
67
|
+
const jsonContent = JSON.parse(content);
|
|
68
|
+
jsonContent.name = sanitizedProjectName;
|
|
69
|
+
content = JSON.stringify(jsonContent, null, 2);
|
|
70
|
+
} else {
|
|
71
|
+
Object.keys(placeholderValues).forEach((key) => {
|
|
72
|
+
const placeholder = `{{${key}}}`;
|
|
73
|
+
content = content.replace(new RegExp(placeholder, "g"), placeholderValues[key]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
fs.writeFileSync(filePath, content);
|
|
60
78
|
}
|
|
61
79
|
});
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
try {
|
|
65
|
-
console.log(
|
|
83
|
+
console.log("Setting up project...");
|
|
66
84
|
copyTemplateFiles();
|
|
67
85
|
console.log(`Project created at ${targetDir}`);
|
|
68
86
|
process.chdir(targetDir);
|
|
69
|
-
console.log(
|
|
70
|
-
console.log(
|
|
87
|
+
console.log("Project setup complete!");
|
|
88
|
+
console.log("Run npm install and you are set.");
|
|
71
89
|
} catch (error) {
|
|
72
|
-
console.error(
|
|
90
|
+
console.error("Error creating project:", error);
|
|
73
91
|
process.exit(1);
|
|
74
92
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
3
|
-
"version": "
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
|
-
"name": "
|
|
8
|
+
"name": "vite",
|
|
9
9
|
"version": "0.0.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"motion": "^11.11.15",
|
package/template/package.json
CHANGED