@idajs/create-mod 0.2.15 → 0.2.16
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 +6 -0
- package/_project.config/archive.js +107 -0
- package/_project.config/build.js +22 -37
- package/_project.config/package.template.json +14 -14
- package/_project.config/project.js +120 -0
- package/_project.config/remote.js +157 -0
- package/_project.config/run-remote.js +75 -0
- package/_project.config/start.js +60 -0
- package/_project.config/sync.js +21 -60
- package/_project.config/watch.js +90 -24
- package/index.js +145 -19
- package/install.js +158 -45
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const { exec } = require("child_process");
|
|
5
|
+
const { exec, execSync } = require("child_process");
|
|
6
6
|
|
|
7
7
|
// Get configuration from arguments or defaults
|
|
8
8
|
const args = process.argv.slice(2);
|
|
9
9
|
const targetDirArg = args.find((arg) => !arg.startsWith("--"));
|
|
10
10
|
const skipInstall = args.includes("--skip-install");
|
|
11
|
+
const updateMode = args.includes("--update");
|
|
11
12
|
const idaRootArg = args.find((arg) => arg.startsWith("--ida-root="));
|
|
12
13
|
|
|
13
14
|
// Get the directory where this script was called from or use provided argument
|
|
@@ -30,48 +31,34 @@ const isTypeScriptProject = (() => {
|
|
|
30
31
|
const files = fs.readdirSync(srcDir);
|
|
31
32
|
return files.some((file) => file.endsWith(".ts"));
|
|
32
33
|
})();
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const protectedUpdateFields = new Set([
|
|
35
|
+
"name",
|
|
36
|
+
"description",
|
|
37
|
+
"version",
|
|
38
|
+
"author",
|
|
39
|
+
"private",
|
|
40
|
+
"license",
|
|
41
|
+
]);
|
|
42
|
+
const obsoleteScaffolderDevDependencies = ["archiver"];
|
|
43
|
+
|
|
44
|
+
console.log(`${updateMode ? "Updating" : "Installing"} development environment in: ${targetDir}`);
|
|
35
45
|
if (idaRoot) {
|
|
36
46
|
console.log(`Ida root: ${idaRoot}`);
|
|
37
47
|
} else {
|
|
38
48
|
console.log(`Running in standalone mode`);
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
function mergePackageJson() {
|
|
43
|
-
const packagePath = path.join(targetDir, "package.json");
|
|
44
|
-
const globalTemplatePath = path.join(configDir, "package.template.json");
|
|
45
|
-
const sampleTemplatePath = path.join(targetDir, "package.template.json");
|
|
46
|
-
|
|
47
|
-
if (!fs.existsSync(globalTemplatePath)) {
|
|
48
|
-
console.error("Error: package.template.json not found in config directory");
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!fs.existsSync(sampleTemplatePath)) {
|
|
53
|
-
console.error("Error: package.template.json not found in sample directory");
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
console.log("Merging package.template.json files to create package.json...");
|
|
58
|
-
|
|
59
|
-
// Start with global template
|
|
60
|
-
const packageJson = JSON.parse(fs.readFileSync(globalTemplatePath, "utf8"));
|
|
61
|
-
const sampleTemplate = JSON.parse(fs.readFileSync(sampleTemplatePath, "utf8"));
|
|
62
|
-
|
|
63
|
-
// Get version from version.js or package.json (standalone mode)
|
|
51
|
+
function getPackageVersion() {
|
|
64
52
|
let version = null;
|
|
53
|
+
|
|
65
54
|
if (versionScriptPath && fs.existsSync(versionScriptPath)) {
|
|
66
55
|
try {
|
|
67
|
-
const { execSync } = require("child_process");
|
|
68
56
|
version = execSync(`node "${versionScriptPath}"`, { encoding: "utf8" }).trim();
|
|
69
57
|
console.log(`Using version from version.js: ${version}`);
|
|
70
58
|
} catch (error) {
|
|
71
59
|
console.warn("Warning: Could not read version from version.js");
|
|
72
60
|
}
|
|
73
61
|
} else {
|
|
74
|
-
// Standalone mode: get version from package.json in the same directory as this script
|
|
75
62
|
const localPackagePath = path.join(__dirname, "package.json");
|
|
76
63
|
if (fs.existsSync(localPackagePath)) {
|
|
77
64
|
try {
|
|
@@ -84,7 +71,51 @@ function mergePackageJson() {
|
|
|
84
71
|
}
|
|
85
72
|
}
|
|
86
73
|
|
|
87
|
-
|
|
74
|
+
return version;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function orderPackageJson(packageJson) {
|
|
78
|
+
const orderedPackageJson = {};
|
|
79
|
+
const propertyOrder = ["name", "description", "version", "author", "license", "private", "scripts"];
|
|
80
|
+
|
|
81
|
+
propertyOrder.forEach((key) => {
|
|
82
|
+
if (packageJson[key] !== undefined) {
|
|
83
|
+
orderedPackageJson[key] = packageJson[key];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
Object.keys(packageJson).forEach((key) => {
|
|
88
|
+
if (!propertyOrder.includes(key)) {
|
|
89
|
+
orderedPackageJson[key] = packageJson[key];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return orderedPackageJson;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Step 1: Merge package.template.json files to create package.json
|
|
97
|
+
function mergePackageJsonForCreate() {
|
|
98
|
+
const packagePath = path.join(targetDir, "package.json");
|
|
99
|
+
const globalTemplatePath = path.join(configDir, "package.template.json");
|
|
100
|
+
const sampleTemplatePath = path.join(targetDir, "package.template.json");
|
|
101
|
+
|
|
102
|
+
if (!fs.existsSync(globalTemplatePath)) {
|
|
103
|
+
console.error("Error: package.template.json not found in config directory");
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!fs.existsSync(sampleTemplatePath)) {
|
|
108
|
+
console.error("Error: package.template.json not found in sample directory");
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log("Merging package.template.json files to create package.json...");
|
|
113
|
+
|
|
114
|
+
// Start with global template
|
|
115
|
+
const packageJson = JSON.parse(fs.readFileSync(globalTemplatePath, "utf8"));
|
|
116
|
+
const sampleTemplate = JSON.parse(fs.readFileSync(sampleTemplatePath, "utf8"));
|
|
117
|
+
|
|
118
|
+
const version = getPackageVersion();
|
|
88
119
|
if (version) {
|
|
89
120
|
packageJson.version = version;
|
|
90
121
|
}
|
|
@@ -116,32 +147,76 @@ function mergePackageJson() {
|
|
|
116
147
|
packageJson.dependencies = { ...packageJson.dependencies, ...sampleTemplate.dependencies };
|
|
117
148
|
}
|
|
118
149
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
150
|
+
fs.writeFileSync(packagePath, JSON.stringify(orderPackageJson(packageJson), null, 2) + "\n");
|
|
151
|
+
console.log("✓ Package.json created successfully");
|
|
152
|
+
}
|
|
122
153
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
154
|
+
function mergePackageJsonForUpdate() {
|
|
155
|
+
const packagePath = path.join(targetDir, "package.json");
|
|
156
|
+
const globalTemplatePath = path.join(configDir, "package.template.json");
|
|
157
|
+
|
|
158
|
+
if (!fs.existsSync(globalTemplatePath)) {
|
|
159
|
+
console.error("Error: package.template.json not found in config directory");
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!fs.existsSync(packagePath)) {
|
|
164
|
+
console.error("Error: package.json not found in target directory");
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.log("Refreshing package.json from scaffolder template...");
|
|
169
|
+
|
|
170
|
+
const existingPackageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
171
|
+
const configTemplate = JSON.parse(fs.readFileSync(globalTemplatePath, "utf8"));
|
|
172
|
+
const packageJson = { ...existingPackageJson };
|
|
173
|
+
const existingDevDependencies = existingPackageJson.devDependencies || {};
|
|
174
|
+
|
|
175
|
+
Object.entries(configTemplate).forEach(([key, value]) => {
|
|
176
|
+
if (protectedUpdateFields.has(key)) {
|
|
177
|
+
return;
|
|
127
178
|
}
|
|
128
|
-
});
|
|
129
179
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
180
|
+
if (key === "scripts" || key === "devDependencies") {
|
|
181
|
+
const templateValue = { ...value };
|
|
182
|
+
|
|
183
|
+
if (
|
|
184
|
+
key === "devDependencies" &&
|
|
185
|
+
!isTypeScriptProject &&
|
|
186
|
+
!Object.prototype.hasOwnProperty.call(existingDevDependencies, "typescript")
|
|
187
|
+
) {
|
|
188
|
+
delete templateValue.typescript;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
packageJson[key] = {
|
|
192
|
+
...(existingPackageJson[key] || {}),
|
|
193
|
+
...templateValue,
|
|
194
|
+
};
|
|
195
|
+
return;
|
|
134
196
|
}
|
|
197
|
+
|
|
198
|
+
packageJson[key] = value;
|
|
135
199
|
});
|
|
136
200
|
|
|
137
|
-
|
|
138
|
-
|
|
201
|
+
if (packageJson.devDependencies) {
|
|
202
|
+
obsoleteScaffolderDevDependencies.forEach((dependency) => {
|
|
203
|
+
delete packageJson.devDependencies[dependency];
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fs.writeFileSync(packagePath, JSON.stringify(orderPackageJson(packageJson), null, 2) + "\n");
|
|
208
|
+
console.log("✓ Package.json refreshed successfully");
|
|
139
209
|
}
|
|
140
210
|
|
|
141
211
|
// Step 2: Copy necessary files
|
|
142
212
|
function copyFiles() {
|
|
143
213
|
const filesToCopy = [
|
|
214
|
+
{ source: "archive.js" },
|
|
215
|
+
{ source: "project.js" },
|
|
216
|
+
{ source: "remote.js" },
|
|
144
217
|
{ source: "run.ps1" },
|
|
218
|
+
{ source: "run-remote.js" },
|
|
219
|
+
{ source: "start.js" },
|
|
145
220
|
{ source: "watch.js" },
|
|
146
221
|
{ source: "sync.js" },
|
|
147
222
|
{ source: "build.js" },
|
|
@@ -200,11 +275,49 @@ function runNpmInstall() {
|
|
|
200
275
|
npmProcess.stderr.pipe(process.stderr);
|
|
201
276
|
}
|
|
202
277
|
|
|
278
|
+
function runCommand(command, errorMessage) {
|
|
279
|
+
try {
|
|
280
|
+
execSync(command, {
|
|
281
|
+
cwd: targetDir,
|
|
282
|
+
stdio: "inherit",
|
|
283
|
+
});
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.error(errorMessage);
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function runUpdatePostInstall() {
|
|
291
|
+
if (skipInstall) {
|
|
292
|
+
console.log("\nSkipped npm install and update:types");
|
|
293
|
+
console.log("\nInfrastructure update complete.");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
console.log("Running npm install...");
|
|
298
|
+
runCommand("npm install", "Error running npm install");
|
|
299
|
+
console.log("✓ npm install completed successfully");
|
|
300
|
+
|
|
301
|
+
console.log("Running npm run update:types...");
|
|
302
|
+
runCommand(
|
|
303
|
+
"npm run update:types",
|
|
304
|
+
"Error running npm run update:types. Infrastructure refresh and npm install already completed."
|
|
305
|
+
);
|
|
306
|
+
console.log("✓ npm run update:types completed successfully");
|
|
307
|
+
console.log("\nInfrastructure update complete! You can now use the refreshed development scripts.");
|
|
308
|
+
}
|
|
309
|
+
|
|
203
310
|
// Main execution
|
|
204
311
|
try {
|
|
205
|
-
|
|
312
|
+
if (updateMode) {
|
|
313
|
+
mergePackageJsonForUpdate();
|
|
314
|
+
} else {
|
|
315
|
+
mergePackageJsonForCreate();
|
|
316
|
+
}
|
|
206
317
|
copyFiles();
|
|
207
|
-
if (
|
|
318
|
+
if (updateMode) {
|
|
319
|
+
runUpdatePostInstall();
|
|
320
|
+
} else if (!skipInstall) {
|
|
208
321
|
runNpmInstall();
|
|
209
322
|
} else {
|
|
210
323
|
console.log("\nSkipped npm install");
|
package/package.json
CHANGED