create-spfx-tailwind-app 1.0.12 → 1.0.13
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/Template/setup.js +42 -25
- package/index.js +2 -2
- package/package.json +1 -1
package/Template/setup.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const {
|
|
3
|
+
const { randomUUID } = require("crypto");
|
|
4
4
|
|
|
5
|
-
const solutionId =
|
|
6
|
-
const webpartId =
|
|
5
|
+
const solutionId = randomUUID();
|
|
6
|
+
const webpartId = randomUUID();
|
|
7
7
|
|
|
8
8
|
const projectName = process.argv[2];
|
|
9
9
|
|
|
@@ -14,8 +14,17 @@ if (!projectName) {
|
|
|
14
14
|
|
|
15
15
|
const projectNameLower = projectName.toLowerCase();
|
|
16
16
|
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// ✅ Only process safe text files
|
|
21
|
+
const allowedExtensions = [".json", ".js", ".ts", ".tsx", ".scss", ".md"];
|
|
22
|
+
|
|
17
23
|
// 🔁 Replace content inside files
|
|
18
24
|
function replaceInFile(filePath) {
|
|
25
|
+
const ext = path.extname(filePath);
|
|
26
|
+
if (!allowedExtensions.includes(ext)) return;
|
|
27
|
+
|
|
19
28
|
let content = fs.readFileSync(filePath, "utf8");
|
|
20
29
|
|
|
21
30
|
content = content
|
|
@@ -27,12 +36,16 @@ function replaceInFile(filePath) {
|
|
|
27
36
|
fs.writeFileSync(filePath, content);
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
// 🔁 Walk and process files
|
|
39
|
+
// 🔁 Walk and process files safely
|
|
31
40
|
function walk(dir) {
|
|
32
|
-
fs.
|
|
41
|
+
if (!fs.existsSync(dir)) return;
|
|
42
|
+
|
|
43
|
+
fs.readdirSync(dir).forEach((file) => {
|
|
33
44
|
const fullPath = path.join(dir, file);
|
|
34
45
|
|
|
35
|
-
|
|
46
|
+
const stat = fs.statSync(fullPath);
|
|
47
|
+
|
|
48
|
+
if (stat.isDirectory()) {
|
|
36
49
|
walk(fullPath);
|
|
37
50
|
} else {
|
|
38
51
|
replaceInFile(fullPath);
|
|
@@ -40,23 +53,24 @@ function walk(dir) {
|
|
|
40
53
|
});
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
// 🔁 Rename files
|
|
56
|
+
// 🔁 Rename files safely
|
|
44
57
|
function renameFiles(dir) {
|
|
45
|
-
fs.
|
|
58
|
+
if (!fs.existsSync(dir)) return;
|
|
59
|
+
|
|
60
|
+
fs.readdirSync(dir).forEach((file) => {
|
|
46
61
|
const fullPath = path.join(dir, file);
|
|
47
62
|
|
|
48
|
-
|
|
63
|
+
const stat = fs.statSync(fullPath);
|
|
64
|
+
|
|
65
|
+
if (stat.isDirectory()) {
|
|
49
66
|
renameFiles(fullPath);
|
|
50
67
|
} else {
|
|
51
|
-
|
|
68
|
+
const newName = file
|
|
52
69
|
.replace(/__PROJECT_NAME__/g, projectName)
|
|
53
70
|
.replace(/__PROJECT_NAME_LOWER__/g, projectNameLower);
|
|
54
71
|
|
|
55
72
|
if (newName !== file) {
|
|
56
|
-
fs.renameSync(
|
|
57
|
-
fullPath,
|
|
58
|
-
path.join(dir, newName)
|
|
59
|
-
);
|
|
73
|
+
fs.renameSync(fullPath, path.join(dir, newName));
|
|
60
74
|
}
|
|
61
75
|
}
|
|
62
76
|
});
|
|
@@ -65,27 +79,30 @@ function renameFiles(dir) {
|
|
|
65
79
|
// 🔁 Run replacements
|
|
66
80
|
walk("./");
|
|
67
81
|
|
|
82
|
+
// 🔁 Force update package.json name
|
|
68
83
|
const pkgPath = path.join("./package.json");
|
|
69
84
|
|
|
70
85
|
if (fs.existsSync(pkgPath)) {
|
|
71
86
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
72
|
-
|
|
73
|
-
pkg.name = projectNameLower; // force update
|
|
74
|
-
|
|
87
|
+
pkg.name = projectNameLower;
|
|
75
88
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
// 🔁 Rename files AFTER replacing content
|
|
79
92
|
renameFiles("./");
|
|
80
93
|
|
|
81
|
-
// 🔁 Rename webpart folder
|
|
94
|
+
// 🔁 Rename webpart folder safely
|
|
82
95
|
const webpartsDir = "./src/webparts";
|
|
83
96
|
|
|
84
|
-
fs.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
if (fs.existsSync(webpartsDir)) {
|
|
98
|
+
fs.readdirSync(webpartsDir).forEach((folder) => {
|
|
99
|
+
if (folder.includes("__PROJECT_NAME_LOWER__")) {
|
|
100
|
+
const oldPath = path.join(webpartsDir, folder);
|
|
101
|
+
const newPath = path.join(webpartsDir, projectNameLower);
|
|
102
|
+
|
|
103
|
+
fs.renameSync(oldPath, newPath);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
88
107
|
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
});
|
|
108
|
+
console.log("🎉 Setup complete!");
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
@@ -58,7 +58,7 @@ async function run() {
|
|
|
58
58
|
// ⚙ Run setup script
|
|
59
59
|
execSync(`node setup.js "${projectName}"`, {
|
|
60
60
|
cwd: targetDir,
|
|
61
|
-
stdio: "
|
|
61
|
+
stdio: "inherit",
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
spinner.succeed(chalk.green("✔ Project setup complete"));
|