sprint-es 0.0.116 → 0.0.118
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/cjs/cli.cjs +48 -13
- package/dist/esm/cli.js +49 -14
- package/dist/types/cli.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const fs = require("fs");
|
|
|
5
5
|
const crypto = require("crypto");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const child_process = require("child_process");
|
|
8
|
+
const module$1 = require("module");
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
9
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
11
|
if (e) {
|
|
@@ -175,6 +176,40 @@ function runCommand(cmd, envVars) {
|
|
|
175
176
|
});
|
|
176
177
|
});
|
|
177
178
|
}
|
|
179
|
+
function collectEntryPoints(dir) {
|
|
180
|
+
const entries = [];
|
|
181
|
+
if (!fs.existsSync(dir)) return entries;
|
|
182
|
+
for (const file of fs.readdirSync(dir)) {
|
|
183
|
+
const fullPath = path.join(dir, file);
|
|
184
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
185
|
+
entries.push(...collectEntryPoints(fullPath));
|
|
186
|
+
} else if (file.endsWith(".ts") && !file.endsWith(".d.ts")) {
|
|
187
|
+
entries.push(fullPath);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return entries;
|
|
191
|
+
}
|
|
192
|
+
async function buildWithEsbuild(srcPath, distPath, external) {
|
|
193
|
+
const requireFromProject = module$1.createRequire(path.join(projectRoot, "package.json"));
|
|
194
|
+
const esbuild = requireFromProject("esbuild");
|
|
195
|
+
const entryPoints = collectEntryPoints(srcPath);
|
|
196
|
+
await esbuild.build({
|
|
197
|
+
entryPoints,
|
|
198
|
+
outdir: distPath,
|
|
199
|
+
outbase: srcPath,
|
|
200
|
+
platform: "node",
|
|
201
|
+
format: "cjs",
|
|
202
|
+
bundle: true,
|
|
203
|
+
// bundle=true es necesario para que external funcione
|
|
204
|
+
sourcemap: true,
|
|
205
|
+
external,
|
|
206
|
+
// todos los paquetes npm marcados como externos
|
|
207
|
+
treeShaking: false,
|
|
208
|
+
// no eliminar exports, queremos todos los archivos
|
|
209
|
+
packages: "external"
|
|
210
|
+
// cualquier paquete de node_modules es externo automáticamente
|
|
211
|
+
});
|
|
212
|
+
}
|
|
178
213
|
function generateJWTSecret() {
|
|
179
214
|
const chars = crypto__namespace.randomBytes(24).toString("hex").split("");
|
|
180
215
|
const positions = /* @__PURE__ */ new Set();
|
|
@@ -406,25 +441,25 @@ async function main() {
|
|
|
406
441
|
console.log("[Sprint] Cleaning dist...");
|
|
407
442
|
fs.rmSync(distPath, { recursive: true, force: true });
|
|
408
443
|
console.log("[Sprint] dist cleaned ✓");
|
|
444
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
|
|
445
|
+
const external = [
|
|
446
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
447
|
+
...Object.keys(packageJson.devDependencies ?? {}),
|
|
448
|
+
...Object.keys(packageJson.optionalDependencies ?? {}),
|
|
449
|
+
...Object.keys(packageJson.peerDependencies ?? {})
|
|
450
|
+
];
|
|
409
451
|
console.log("[Sprint] Compiling with esbuild...");
|
|
410
|
-
await
|
|
411
|
-
`esbuild "${srcPath}/**/*.ts" --outdir="${distPath}" --platform=node --format=cjs --bundle=false --sourcemap --outbase="${srcPath}"`,
|
|
412
|
-
{ NODE_ENV: "production" }
|
|
413
|
-
);
|
|
452
|
+
await buildWithEsbuild(srcPath, distPath, external);
|
|
414
453
|
console.log("[Sprint] Compilation completed ✓");
|
|
415
454
|
console.log("[Sprint] Type checking...");
|
|
416
455
|
await runCommand(`tsc --project "${tsconfigPath}" --noEmit`, { NODE_ENV: "production" });
|
|
417
456
|
console.log("[Sprint] Type check completed ✓");
|
|
418
457
|
console.log("[Sprint] Resolving aliases...");
|
|
419
|
-
const aliasConfig = {
|
|
420
|
-
extends: "./tsconfig.json",
|
|
421
|
-
compilerOptions: {
|
|
422
|
-
outDir: "./dist",
|
|
423
|
-
noEmit: false
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
458
|
const aliasConfigPath = path.join(projectRoot, "tsconfig.alias.json");
|
|
427
|
-
fs.writeFileSync(aliasConfigPath, JSON.stringify(
|
|
459
|
+
fs.writeFileSync(aliasConfigPath, JSON.stringify({
|
|
460
|
+
extends: "./tsconfig.json",
|
|
461
|
+
compilerOptions: { outDir: "./dist", noEmit: false }
|
|
462
|
+
}, null, 4));
|
|
428
463
|
try {
|
|
429
464
|
await runCommand(`tsc-alias --project "${aliasConfigPath}"`, { NODE_ENV: "production" });
|
|
430
465
|
console.log("[Sprint] Aliases resolved ✓");
|
|
@@ -434,7 +469,7 @@ async function main() {
|
|
|
434
469
|
if (isTS) {
|
|
435
470
|
console.log("[Sprint] Compiling sprint.config.ts...");
|
|
436
471
|
await runCommand(
|
|
437
|
-
`esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=
|
|
472
|
+
`esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=true ${external.map((e) => `--external:${e}`).join(" ")}`,
|
|
438
473
|
{ NODE_ENV: "production" }
|
|
439
474
|
);
|
|
440
475
|
console.log("[Sprint] sprint.config.js generated ✓");
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, rmSync,
|
|
2
|
+
import { existsSync, rmSync, readFileSync, writeFileSync, readdirSync, statSync } from "fs";
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
4
|
import { resolve, join } from "path";
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
|
+
import { createRequire } from "module";
|
|
6
7
|
const args = process.argv.slice(2);
|
|
7
8
|
const command = args[0];
|
|
8
9
|
const pc = {
|
|
@@ -156,6 +157,40 @@ function runCommand(cmd, envVars) {
|
|
|
156
157
|
});
|
|
157
158
|
});
|
|
158
159
|
}
|
|
160
|
+
function collectEntryPoints(dir) {
|
|
161
|
+
const entries = [];
|
|
162
|
+
if (!existsSync(dir)) return entries;
|
|
163
|
+
for (const file of readdirSync(dir)) {
|
|
164
|
+
const fullPath = join(dir, file);
|
|
165
|
+
if (statSync(fullPath).isDirectory()) {
|
|
166
|
+
entries.push(...collectEntryPoints(fullPath));
|
|
167
|
+
} else if (file.endsWith(".ts") && !file.endsWith(".d.ts")) {
|
|
168
|
+
entries.push(fullPath);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return entries;
|
|
172
|
+
}
|
|
173
|
+
async function buildWithEsbuild(srcPath, distPath, external) {
|
|
174
|
+
const requireFromProject = createRequire(join(projectRoot, "package.json"));
|
|
175
|
+
const esbuild = requireFromProject("esbuild");
|
|
176
|
+
const entryPoints = collectEntryPoints(srcPath);
|
|
177
|
+
await esbuild.build({
|
|
178
|
+
entryPoints,
|
|
179
|
+
outdir: distPath,
|
|
180
|
+
outbase: srcPath,
|
|
181
|
+
platform: "node",
|
|
182
|
+
format: "cjs",
|
|
183
|
+
bundle: true,
|
|
184
|
+
// bundle=true es necesario para que external funcione
|
|
185
|
+
sourcemap: true,
|
|
186
|
+
external,
|
|
187
|
+
// todos los paquetes npm marcados como externos
|
|
188
|
+
treeShaking: false,
|
|
189
|
+
// no eliminar exports, queremos todos los archivos
|
|
190
|
+
packages: "external"
|
|
191
|
+
// cualquier paquete de node_modules es externo automáticamente
|
|
192
|
+
});
|
|
193
|
+
}
|
|
159
194
|
function generateJWTSecret() {
|
|
160
195
|
const chars = crypto.randomBytes(24).toString("hex").split("");
|
|
161
196
|
const positions = /* @__PURE__ */ new Set();
|
|
@@ -387,25 +422,25 @@ async function main() {
|
|
|
387
422
|
console.log("[Sprint] Cleaning dist...");
|
|
388
423
|
rmSync(distPath, { recursive: true, force: true });
|
|
389
424
|
console.log("[Sprint] dist cleaned ✓");
|
|
425
|
+
const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8"));
|
|
426
|
+
const external = [
|
|
427
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
428
|
+
...Object.keys(packageJson.devDependencies ?? {}),
|
|
429
|
+
...Object.keys(packageJson.optionalDependencies ?? {}),
|
|
430
|
+
...Object.keys(packageJson.peerDependencies ?? {})
|
|
431
|
+
];
|
|
390
432
|
console.log("[Sprint] Compiling with esbuild...");
|
|
391
|
-
await
|
|
392
|
-
`esbuild "${srcPath}/**/*.ts" --outdir="${distPath}" --platform=node --format=cjs --bundle=false --sourcemap --outbase="${srcPath}"`,
|
|
393
|
-
{ NODE_ENV: "production" }
|
|
394
|
-
);
|
|
433
|
+
await buildWithEsbuild(srcPath, distPath, external);
|
|
395
434
|
console.log("[Sprint] Compilation completed ✓");
|
|
396
435
|
console.log("[Sprint] Type checking...");
|
|
397
436
|
await runCommand(`tsc --project "${tsconfigPath}" --noEmit`, { NODE_ENV: "production" });
|
|
398
437
|
console.log("[Sprint] Type check completed ✓");
|
|
399
438
|
console.log("[Sprint] Resolving aliases...");
|
|
400
|
-
const aliasConfig = {
|
|
401
|
-
extends: "./tsconfig.json",
|
|
402
|
-
compilerOptions: {
|
|
403
|
-
outDir: "./dist",
|
|
404
|
-
noEmit: false
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
439
|
const aliasConfigPath = join(projectRoot, "tsconfig.alias.json");
|
|
408
|
-
writeFileSync(aliasConfigPath, JSON.stringify(
|
|
440
|
+
writeFileSync(aliasConfigPath, JSON.stringify({
|
|
441
|
+
extends: "./tsconfig.json",
|
|
442
|
+
compilerOptions: { outDir: "./dist", noEmit: false }
|
|
443
|
+
}, null, 4));
|
|
409
444
|
try {
|
|
410
445
|
await runCommand(`tsc-alias --project "${aliasConfigPath}"`, { NODE_ENV: "production" });
|
|
411
446
|
console.log("[Sprint] Aliases resolved ✓");
|
|
@@ -415,7 +450,7 @@ async function main() {
|
|
|
415
450
|
if (isTS) {
|
|
416
451
|
console.log("[Sprint] Compiling sprint.config.ts...");
|
|
417
452
|
await runCommand(
|
|
418
|
-
`esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=
|
|
453
|
+
`esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=true ${external.map((e) => `--external:${e}`).join(" ")}`,
|
|
419
454
|
{ NODE_ENV: "production" }
|
|
420
455
|
);
|
|
421
456
|
console.log("[Sprint] sprint.config.js generated ✓");
|
package/dist/types/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAsDA,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAiB,EAAE,cAAsB,EAAE;;;CAAK,UAoGrD"}
|