create-thexjs-app 1.2.0 → 1.2.1
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.js +60 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -93,6 +93,65 @@ var BASE_DEV_DEPENDENCIES = {
|
|
|
93
93
|
typescript: "^5.8.0"
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// src/package-json.ts
|
|
97
|
+
var FALLBACK_CORE_VERSION = "1.6.0";
|
|
98
|
+
var FALLBACK_CLI_VERSION = "1.1.2";
|
|
99
|
+
var FALLBACK_HOOKS_VERSION = "0.2.0";
|
|
100
|
+
async function resolveVersions(features, fetchVersion = fetchLatestVersion) {
|
|
101
|
+
const coreVersion = await fetchVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
|
|
102
|
+
const cliVersion = await fetchVersion("@thexjs/cli") ?? FALLBACK_CLI_VERSION;
|
|
103
|
+
const hooksVersion = features.includes("hooks") ? await fetchVersion("@thexjs/hooks") ?? FALLBACK_HOOKS_VERSION : void 0;
|
|
104
|
+
return { coreVersion, cliVersion, ...hooksVersion !== void 0 ? { hooksVersion } : {} };
|
|
105
|
+
}
|
|
106
|
+
async function fetchLatestVersion(pkg) {
|
|
107
|
+
try {
|
|
108
|
+
const controller = new AbortController();
|
|
109
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
110
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
|
|
111
|
+
signal: controller.signal
|
|
112
|
+
});
|
|
113
|
+
clearTimeout(timeout);
|
|
114
|
+
if (!res.ok) return null;
|
|
115
|
+
const data = await res.json();
|
|
116
|
+
return data.version ?? null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function buildPackageJson(name, features, coreVersion, cliVersion, hooksVersion) {
|
|
122
|
+
const dependencies = {
|
|
123
|
+
...BASE_DEPENDENCIES,
|
|
124
|
+
"@thexjs/core": `^${coreVersion}`
|
|
125
|
+
};
|
|
126
|
+
const devDependencies = {
|
|
127
|
+
...BASE_DEV_DEPENDENCIES,
|
|
128
|
+
"@thexjs/cli": `^${cliVersion}`
|
|
129
|
+
};
|
|
130
|
+
if (features.includes("hooks") && hooksVersion) {
|
|
131
|
+
dependencies["@thexjs/hooks"] = `^${hooksVersion}`;
|
|
132
|
+
}
|
|
133
|
+
for (const feature of features) {
|
|
134
|
+
const meta = FEATURES.find((f) => f.id === feature);
|
|
135
|
+
if (!meta) continue;
|
|
136
|
+
Object.assign(dependencies, meta.dependencies);
|
|
137
|
+
Object.assign(devDependencies, meta.devDependencies);
|
|
138
|
+
}
|
|
139
|
+
const pkg = {
|
|
140
|
+
name,
|
|
141
|
+
private: true,
|
|
142
|
+
type: "module",
|
|
143
|
+
scripts: {
|
|
144
|
+
dev: "x dev",
|
|
145
|
+
build: "x build",
|
|
146
|
+
start: "x start"
|
|
147
|
+
},
|
|
148
|
+
dependencies,
|
|
149
|
+
devDependencies
|
|
150
|
+
};
|
|
151
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
96
155
|
// src/index.ts
|
|
97
156
|
function abort(message) {
|
|
98
157
|
cancel(message);
|
|
@@ -102,8 +161,6 @@ var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
102
161
|
var TEMPLATES_ROOT = join(__dirname, "..", "templates");
|
|
103
162
|
var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
|
|
104
163
|
var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
|
|
105
|
-
var FALLBACK_CORE_VERSION = "1.2.2";
|
|
106
|
-
var FALLBACK_HOOKS_VERSION = "0.1.0";
|
|
107
164
|
function parseArgs(argv) {
|
|
108
165
|
const options = {
|
|
109
166
|
features: [],
|
|
@@ -160,21 +217,6 @@ function parseArgs(argv) {
|
|
|
160
217
|
function slugify(name) {
|
|
161
218
|
return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
|
|
162
219
|
}
|
|
163
|
-
async function fetchLatestVersion(pkg) {
|
|
164
|
-
try {
|
|
165
|
-
const controller = new AbortController();
|
|
166
|
-
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
167
|
-
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
|
|
168
|
-
signal: controller.signal
|
|
169
|
-
});
|
|
170
|
-
clearTimeout(timeout);
|
|
171
|
-
if (!res.ok) return null;
|
|
172
|
-
const data = await res.json();
|
|
173
|
-
return data.version ?? null;
|
|
174
|
-
} catch {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
220
|
function ensureDir(path) {
|
|
179
221
|
if (!existsSync(path)) mkdirSync(path, { recursive: true });
|
|
180
222
|
}
|
|
@@ -202,39 +244,6 @@ function finalizeGitignore(targetDir) {
|
|
|
202
244
|
const to = join(targetDir, ".gitignore");
|
|
203
245
|
renameSync(from, to);
|
|
204
246
|
}
|
|
205
|
-
function buildPackageJson(name, features, coreVersion, cliVersion, hooksVersion) {
|
|
206
|
-
const dependencies = {
|
|
207
|
-
...BASE_DEPENDENCIES,
|
|
208
|
-
"@thexjs/core": `^${coreVersion}`
|
|
209
|
-
};
|
|
210
|
-
const devDependencies = {
|
|
211
|
-
...BASE_DEV_DEPENDENCIES,
|
|
212
|
-
"@thexjs/cli": `^${cliVersion}`
|
|
213
|
-
};
|
|
214
|
-
if (features.includes("hooks") && hooksVersion) {
|
|
215
|
-
dependencies["@thexjs/hooks"] = `^${hooksVersion}`;
|
|
216
|
-
}
|
|
217
|
-
for (const feature of features) {
|
|
218
|
-
const meta = FEATURES.find((f) => f.id === feature);
|
|
219
|
-
if (!meta) continue;
|
|
220
|
-
Object.assign(dependencies, meta.dependencies);
|
|
221
|
-
Object.assign(devDependencies, meta.devDependencies);
|
|
222
|
-
}
|
|
223
|
-
const pkg = {
|
|
224
|
-
name,
|
|
225
|
-
private: true,
|
|
226
|
-
type: "module",
|
|
227
|
-
scripts: {
|
|
228
|
-
dev: "x dev",
|
|
229
|
-
build: "x build",
|
|
230
|
-
start: "x start"
|
|
231
|
-
},
|
|
232
|
-
dependencies,
|
|
233
|
-
devDependencies
|
|
234
|
-
};
|
|
235
|
-
return `${JSON.stringify(pkg, null, 2)}
|
|
236
|
-
`;
|
|
237
|
-
}
|
|
238
247
|
function buildXConfig(features) {
|
|
239
248
|
const lines = [];
|
|
240
249
|
lines.push('import { defineConfig } from "@thexjs/core";');
|
|
@@ -313,9 +322,7 @@ async function main() {
|
|
|
313
322
|
copyAddon(feature, targetDir);
|
|
314
323
|
}
|
|
315
324
|
spin.message("Resolving latest @thexjs versions");
|
|
316
|
-
const coreVersion = await
|
|
317
|
-
const cliVersion = await fetchLatestVersion("@thexjs/cli") ?? FALLBACK_CORE_VERSION;
|
|
318
|
-
const hooksVersion = features.includes("hooks") ? await fetchLatestVersion("@thexjs/hooks") ?? FALLBACK_HOOKS_VERSION : void 0;
|
|
325
|
+
const { coreVersion, cliVersion, hooksVersion } = await resolveVersions(features);
|
|
319
326
|
writeFileSync(
|
|
320
327
|
join(targetDir, "package.json"),
|
|
321
328
|
buildPackageJson(slug, features, coreVersion, cliVersion, hooksVersion)
|