@elaraai/create-e3 1.0.41 → 1.0.43
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 +99 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -446,19 +446,90 @@ function runInstall(kind, projectDir, enabled, log) {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
// ../scaffold-core/dist/cli.js
|
|
449
|
-
import { existsSync as
|
|
450
|
-
import { dirname, join as
|
|
449
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
|
|
450
|
+
import { dirname, join as join4, resolve } from "node:path";
|
|
451
451
|
import { createInterface } from "node:readline/promises";
|
|
452
452
|
import { fileURLToPath } from "node:url";
|
|
453
|
+
|
|
454
|
+
// ../scaffold-core/dist/update.js
|
|
455
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3, rmSync } from "node:fs";
|
|
456
|
+
import { join as join3 } from "node:path";
|
|
457
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
458
|
+
var DEP_BUCKETS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
459
|
+
function updateStack(options) {
|
|
460
|
+
const { cwd, version, install = false } = options;
|
|
461
|
+
const log = options.log ?? ((msg) => console.log(msg));
|
|
462
|
+
const pkgPath = join3(cwd, "package.json");
|
|
463
|
+
if (!existsSync3(pkgPath)) {
|
|
464
|
+
throw new Error(`no package.json in ${cwd} \u2014 run this inside an East / e3 project`);
|
|
465
|
+
}
|
|
466
|
+
const raw = readFileSync3(pkgPath, "utf8");
|
|
467
|
+
const pkg = JSON.parse(raw);
|
|
468
|
+
const changed = [];
|
|
469
|
+
let found = 0;
|
|
470
|
+
for (const bucket of DEP_BUCKETS) {
|
|
471
|
+
const deps = pkg[bucket];
|
|
472
|
+
if (!deps)
|
|
473
|
+
continue;
|
|
474
|
+
for (const name of Object.keys(deps)) {
|
|
475
|
+
if (!name.startsWith("@elaraai/"))
|
|
476
|
+
continue;
|
|
477
|
+
found++;
|
|
478
|
+
const from = deps[name];
|
|
479
|
+
if (from === version)
|
|
480
|
+
continue;
|
|
481
|
+
deps[name] = version;
|
|
482
|
+
changed.push({ name, from, to: version });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (found === 0) {
|
|
486
|
+
throw new Error(`no @elaraai/* dependencies in ${pkgPath} \u2014 is this an East / e3 project?`);
|
|
487
|
+
}
|
|
488
|
+
if (changed.length > 0) {
|
|
489
|
+
const indent = /^\{\n( +)/.exec(raw)?.[1].length ?? 2;
|
|
490
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
491
|
+
writeFileSync3(pkgPath, JSON.stringify(pkg, null, indent) + trailingNewline);
|
|
492
|
+
log(`Updated ${changed.length} @elaraai/* ${changed.length === 1 ? "dependency" : "dependencies"} to ${version}.`);
|
|
493
|
+
} else {
|
|
494
|
+
log(`All ${found} @elaraai/* dependencies already at ${version}.`);
|
|
495
|
+
}
|
|
496
|
+
if (changed.length > 0) {
|
|
497
|
+
rmSync(join3(cwd, "package-lock.json"), { force: true });
|
|
498
|
+
}
|
|
499
|
+
let installed = false;
|
|
500
|
+
if (install) {
|
|
501
|
+
log("Reinstalling (npm install)...");
|
|
502
|
+
const npm = spawnSync2("npm", ["install"], { cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
503
|
+
if (npm.status !== 0) {
|
|
504
|
+
throw new Error(`npm install failed (exit ${npm.status ?? "unknown"})`);
|
|
505
|
+
}
|
|
506
|
+
installed = true;
|
|
507
|
+
}
|
|
508
|
+
return { projectName: pkg.name ?? "project", changed, found, installed };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// ../scaffold-core/dist/cli.js
|
|
453
512
|
async function runCreateCli(kind, moduleUrl) {
|
|
454
|
-
const pkgRoot =
|
|
513
|
+
const pkgRoot = join4(dirname(fileURLToPath(moduleUrl)), "..");
|
|
455
514
|
const args = process.argv.slice(2);
|
|
456
515
|
if (args.includes("--help") || args.includes("-h")) {
|
|
457
516
|
printHelp(kind);
|
|
458
517
|
return;
|
|
459
518
|
}
|
|
460
|
-
const version = JSON.parse(
|
|
461
|
-
|
|
519
|
+
const version = JSON.parse(readFileSync4(join4(pkgRoot, "package.json"), "utf8")).version;
|
|
520
|
+
if (args.includes("--update")) {
|
|
521
|
+
const target = args.find((a) => !a.startsWith("-")) ?? ".";
|
|
522
|
+
const install2 = args.includes("--no-install") ? false : args.includes("--install") ? true : Boolean(process.stdout.isTTY);
|
|
523
|
+
try {
|
|
524
|
+
const result = updateStack({ cwd: resolve(target), version, install: install2 });
|
|
525
|
+
printUpdateNextSteps(result, install2);
|
|
526
|
+
} catch (err) {
|
|
527
|
+
console.error(`error: ${err instanceof Error ? err.message : String(err)}`);
|
|
528
|
+
process.exit(1);
|
|
529
|
+
}
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const templateDir = join4(pkgRoot, "templates", kind);
|
|
462
533
|
const name = args.find((a) => !a.startsWith("-")) ?? ".";
|
|
463
534
|
const install = args.includes("--install") ? true : args.includes("--no-install") ? false : Boolean(process.stdout.isTTY);
|
|
464
535
|
try {
|
|
@@ -472,10 +543,10 @@ async function runCreateCli(kind, moduleUrl) {
|
|
|
472
543
|
}
|
|
473
544
|
}
|
|
474
545
|
async function resolveFeatures(templateDir, args, packages) {
|
|
475
|
-
const manifestPath =
|
|
476
|
-
if (!
|
|
546
|
+
const manifestPath = join4(templateDir, "template.json");
|
|
547
|
+
if (!existsSync4(manifestPath))
|
|
477
548
|
return {};
|
|
478
|
-
const manifest = JSON.parse(
|
|
549
|
+
const manifest = JSON.parse(readFileSync4(manifestPath, "utf8"));
|
|
479
550
|
const features = {};
|
|
480
551
|
for (const [key, spec] of Object.entries(manifest.features)) {
|
|
481
552
|
if (spec.allOf)
|
|
@@ -586,8 +657,14 @@ function printHelp(kind) {
|
|
|
586
657
|
console.log(`Usage: npm create @elaraai/${kind} <project-name> [-- <options>]`);
|
|
587
658
|
console.log(` create-${kind} <project-name|.> [options]`);
|
|
588
659
|
console.log("");
|
|
660
|
+
console.log("Update an existing project's @elaraai/* stack (run inside the project):");
|
|
661
|
+
console.log(` npm create @elaraai/${kind}@<version> -- --update (@latest for newest)`);
|
|
662
|
+
console.log(" Rewrites every @elaraai/* dependency to <version> and regenerates the lock,");
|
|
663
|
+
console.log(" keeping the stack in lockstep without an ERESOLVE on bump.");
|
|
664
|
+
console.log("");
|
|
589
665
|
console.log("Options:");
|
|
590
|
-
console.log(" --
|
|
666
|
+
console.log(" --update bump this project's @elaraai/* deps instead of scaffolding");
|
|
667
|
+
console.log(" --install | --no-install install dependencies after scaffolding / updating (default: TTY)");
|
|
591
668
|
console.log(" --eslint | --no-eslint include ESLint with the East lint rules (default: yes)");
|
|
592
669
|
console.log(" --editor-diagnostics | --no-editor-diagnostics include the East tsserver plugin for editor squiggles (default: yes)");
|
|
593
670
|
if (kind === "e3") {
|
|
@@ -618,6 +695,19 @@ function printNextSteps(kind, projectName, inPlace, installed, features) {
|
|
|
618
695
|
}
|
|
619
696
|
console.log(kind === "e3" ? " npm run start" : " npm run test");
|
|
620
697
|
}
|
|
698
|
+
function printUpdateNextSteps(result, installed) {
|
|
699
|
+
if (result.changed.length > 0) {
|
|
700
|
+
console.log("");
|
|
701
|
+
for (const dep of result.changed) {
|
|
702
|
+
console.log(` ${dep.name} ${dep.from} -> ${dep.to}`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (!installed) {
|
|
706
|
+
console.log("");
|
|
707
|
+
console.log("Next steps:");
|
|
708
|
+
console.log(" npm install");
|
|
709
|
+
}
|
|
710
|
+
}
|
|
621
711
|
|
|
622
712
|
// src/index.ts
|
|
623
713
|
await runCreateCli("e3", import.meta.url);
|