@idajs/create-mod 0.1.44-dev.51

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/install.js ADDED
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { exec } = require("child_process");
6
+
7
+ // Function to find the Ida root directory by searching upward
8
+ function findIdaRoot(startDir) {
9
+ let currentDir = startDir;
10
+
11
+ while (currentDir !== path.dirname(currentDir)) {
12
+ // Check if this directory contains characteristic Ida files
13
+ if (
14
+ fs.existsSync(path.join(currentDir, "version.js")) &&
15
+ fs.existsSync(path.join(currentDir, "srcjs", "create-mod"))
16
+ ) {
17
+ return currentDir;
18
+ }
19
+ currentDir = path.dirname(currentDir);
20
+ }
21
+
22
+ console.error("Error: Could not find Ida root directory");
23
+ process.exit(1);
24
+ }
25
+
26
+ // Get configuration from arguments or defaults
27
+ const args = process.argv.slice(2);
28
+ const targetDirArg = args.find((arg) => !arg.startsWith("--"));
29
+ const skipInstall = args.includes("--skip-install");
30
+
31
+ // Get the directory where this script was called from or use provided argument
32
+ const targetDir = targetDirArg ? path.resolve(targetDirArg) : process.cwd();
33
+
34
+ // Find Ida root directory
35
+ const idaRoot = findIdaRoot(__dirname);
36
+ const configDir = path.join(idaRoot, "srcjs", "create-mod", "_project.config");
37
+ const versionScriptPath = path.join(idaRoot, "version.js");
38
+
39
+ const isTypeScriptProject = (() => {
40
+ // Check if there are any .ts files in src/
41
+ const srcDir = path.join(targetDir, "src");
42
+ if (!fs.existsSync(srcDir)) {
43
+ return false;
44
+ }
45
+
46
+ const files = fs.readdirSync(srcDir);
47
+ return files.some((file) => file.endsWith(".ts"));
48
+ })();
49
+
50
+ console.log(`Installing development environment in: ${targetDir}`);
51
+ console.log(`Ida root: ${idaRoot}`);
52
+
53
+ // Step 1: Merge package.template.json files to create package.json
54
+ function mergePackageJson() {
55
+ const packagePath = path.join(targetDir, "package.json");
56
+ const globalTemplatePath = path.join(configDir, "package.template.json");
57
+ const sampleTemplatePath = path.join(targetDir, "package.template.json");
58
+
59
+ if (!fs.existsSync(globalTemplatePath)) {
60
+ console.error("Error: package.template.json not found in config directory");
61
+ process.exit(1);
62
+ }
63
+
64
+ if (!fs.existsSync(sampleTemplatePath)) {
65
+ console.error("Error: package.template.json not found in sample directory");
66
+ process.exit(1);
67
+ }
68
+
69
+ console.log("Merging package.template.json files to create package.json...");
70
+
71
+ // Start with global template
72
+ const packageJson = JSON.parse(fs.readFileSync(globalTemplatePath, "utf8"));
73
+ const sampleTemplate = JSON.parse(fs.readFileSync(sampleTemplatePath, "utf8"));
74
+
75
+ // Get version from version.js
76
+ let version = null;
77
+ if (fs.existsSync(versionScriptPath)) {
78
+ try {
79
+ const { execSync } = require("child_process");
80
+ version = execSync(`node "${versionScriptPath}"`, { encoding: "utf8" }).trim();
81
+ console.log(`Using version: ${version}`);
82
+ } catch (error) {
83
+ console.warn("Warning: Could not read version from version.js");
84
+ }
85
+ }
86
+
87
+ // Set version if available
88
+ if (version) {
89
+ packageJson.version = version;
90
+ }
91
+
92
+ // Merge sample template properties (sample template takes precedence)
93
+ if (sampleTemplate.name) {
94
+ packageJson.name = sampleTemplate.name;
95
+ }
96
+
97
+ if (sampleTemplate.description) {
98
+ packageJson.description = sampleTemplate.description;
99
+ }
100
+
101
+ // Merge scripts (sample template takes precedence)
102
+ if (sampleTemplate.scripts) {
103
+ packageJson.scripts = { ...packageJson.scripts, ...sampleTemplate.scripts };
104
+ }
105
+
106
+ // Merge devDependencies (sample template takes precedence)
107
+ if (sampleTemplate.devDependencies) {
108
+ packageJson.devDependencies = {
109
+ ...packageJson.devDependencies,
110
+ ...sampleTemplate.devDependencies,
111
+ };
112
+ }
113
+
114
+ // Merge dependencies (sample template takes precedence)
115
+ if (sampleTemplate.dependencies) {
116
+ packageJson.dependencies = { ...packageJson.dependencies, ...sampleTemplate.dependencies };
117
+ }
118
+
119
+ // Reorder properties to ensure consistent ordering
120
+ const orderedPackageJson = {};
121
+ const propertyOrder = ["name", "description", "version", "author", "private", "scripts"];
122
+
123
+ // Add properties in the specified order
124
+ propertyOrder.forEach((key) => {
125
+ if (packageJson[key] !== undefined) {
126
+ orderedPackageJson[key] = packageJson[key];
127
+ }
128
+ });
129
+
130
+ // Add all remaining properties
131
+ Object.keys(packageJson).forEach((key) => {
132
+ if (!propertyOrder.includes(key)) {
133
+ orderedPackageJson[key] = packageJson[key];
134
+ }
135
+ });
136
+
137
+ fs.writeFileSync(packagePath, JSON.stringify(orderedPackageJson, null, 2) + "\n");
138
+ console.log("✓ Package.json created successfully");
139
+ }
140
+
141
+ // Step 2: Copy necessary files
142
+ function copyFiles() {
143
+ const filesToCopy = [
144
+ { source: "run.ps1" },
145
+ { source: "watch.js" },
146
+ { source: "sync.js" },
147
+ { source: "build.js" },
148
+ { source: isTypeScriptProject ? "tsconfig.json" : "jsconfig.json" },
149
+ { source: "settings.json", target: ".vscode/settings.json" },
150
+ { source: "extensions.json", target: ".vscode/extensions.json" },
151
+ { source: "template.prettierrc.json", target: ".prettierrc.json" },
152
+ ];
153
+
154
+ filesToCopy.forEach((file) => {
155
+ const sourcePath = path.join(configDir, file.source);
156
+ const targetPath = path.join(targetDir, file.target || file.source);
157
+
158
+ if (!fs.existsSync(sourcePath)) {
159
+ console.error(`Error: ${file.source} not found in config directory`);
160
+ process.exit(1);
161
+ }
162
+
163
+ if (!fs.existsSync(path.dirname(targetPath))) {
164
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
165
+ }
166
+
167
+ console.log(`Copying ${file.source}...`);
168
+ fs.copyFileSync(sourcePath, targetPath);
169
+ console.log(`✓ ${file.source} copied successfully to ${targetPath}`);
170
+ });
171
+ }
172
+
173
+ // Step 3: Run npm install
174
+ function runNpmInstall() {
175
+ console.log("Running npm install...");
176
+
177
+ const npmProcess = exec("npm install", { cwd: targetDir }, (error, stdout, stderr) => {
178
+ if (error) {
179
+ console.error("Error running npm install:", error);
180
+ process.exit(1);
181
+ }
182
+
183
+ if (stderr) {
184
+ console.error("npm install stderr:", stderr);
185
+ }
186
+
187
+ console.log(stdout);
188
+ console.log("✓ npm install completed successfully");
189
+ console.log("\nInstallation complete! You can now use the development scripts.");
190
+ });
191
+
192
+ npmProcess.stdout.pipe(process.stdout);
193
+ npmProcess.stderr.pipe(process.stderr);
194
+ }
195
+
196
+ // Main execution
197
+ try {
198
+ mergePackageJson();
199
+ copyFiles();
200
+ if (!skipInstall) {
201
+ runNpmInstall();
202
+ } else {
203
+ console.log("\nSkipped npm install");
204
+ console.log("\nInstallation complete! Run 'npm install' to install dependencies.");
205
+ }
206
+ } catch (error) {
207
+ console.error("Installation failed:", error.message);
208
+ process.exit(1);
209
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@idajs/create-mod",
3
+ "version": "0.1.44-dev.51",
4
+ "description": "Scaffolding tool for creating IdaJS game mods for Little Big Adventure 2",
5
+ "author": "Andriy Tevelyev",
6
+ "license": "GPL-2.0",
7
+ "keywords": [
8
+ "idajs",
9
+ "lba",
10
+ "lba2",
11
+ "mod",
12
+ "create",
13
+ "scaffold",
14
+ "cli"
15
+ ],
16
+ "bin": {
17
+ "create-mod": "./index.js"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "install.js",
22
+ "_project.config",
23
+ "_project.template",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "dependencies": {
28
+ "@idajs/sync": "^1.1.0",
29
+ "prompts": "^2.4.2"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "engines": {
35
+ "node": ">=14.0.0"
36
+ }
37
+ }