@aspects-ai/workspace-cli 0.1.5 → 0.1.7
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 +116 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command7 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/init.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -514,12 +514,125 @@ function createCreateFrameCommand() {
|
|
|
514
514
|
});
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
// src/commands/update-template.ts
|
|
518
|
+
import { Command as Command6 } from "commander";
|
|
519
|
+
import path6 from "path";
|
|
520
|
+
import fs6 from "fs-extra";
|
|
521
|
+
import { execa as execa2 } from "execa";
|
|
522
|
+
import os2 from "os";
|
|
523
|
+
import chalk6 from "chalk";
|
|
524
|
+
var NOODLE_BASE_REPO = "https://github.com/aspects-ai/noodle-templates";
|
|
525
|
+
var NOODLE_BASE_BRANCH = "main";
|
|
526
|
+
var EDITING_FILE_PATH = "noodle-base/EDITING.md";
|
|
527
|
+
function createUpdateTemplateCommand() {
|
|
528
|
+
return new Command6("update-template").description("Update EDITING.md file from noodle-base template").action(async () => {
|
|
529
|
+
try {
|
|
530
|
+
const workspaceRoot = await ensureWorkspaceRoot();
|
|
531
|
+
const targetFile = path6.join(workspaceRoot, "EDITING.md");
|
|
532
|
+
const token = getToken();
|
|
533
|
+
const targetExists = await fs6.pathExists(targetFile);
|
|
534
|
+
if (targetExists) {
|
|
535
|
+
logger.info("Existing EDITING.md found, it will be overwritten.");
|
|
536
|
+
}
|
|
537
|
+
logger.info("Fetching EDITING.md from noodle-base...");
|
|
538
|
+
const content = await fetchFileFromGit({
|
|
539
|
+
repository: NOODLE_BASE_REPO,
|
|
540
|
+
filePath: EDITING_FILE_PATH,
|
|
541
|
+
branch: NOODLE_BASE_BRANCH,
|
|
542
|
+
token
|
|
543
|
+
});
|
|
544
|
+
await fs6.writeFile(targetFile, content, "utf-8");
|
|
545
|
+
logger.success(
|
|
546
|
+
`Successfully ${targetExists ? "updated" : "copied"} EDITING.md to workspace`
|
|
547
|
+
);
|
|
548
|
+
logger.log("\n" + chalk6.bold("Next steps:"));
|
|
549
|
+
logger.log(` ${chalk6.gray("Review the file:")} cat EDITING.md`);
|
|
550
|
+
logger.log("");
|
|
551
|
+
} catch (error) {
|
|
552
|
+
logger.error(error.message);
|
|
553
|
+
process.exit(1);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
async function fetchFileFromGit(options) {
|
|
558
|
+
const tempDir = await fs6.mkdtemp(path6.join(os2.tmpdir(), "workspace-cli-"));
|
|
559
|
+
try {
|
|
560
|
+
const repoUrl = options.repository.replace(
|
|
561
|
+
"https://github.com/",
|
|
562
|
+
`https://${options.token}@github.com/`
|
|
563
|
+
);
|
|
564
|
+
await execa2("git", ["init"], { cwd: tempDir });
|
|
565
|
+
await execa2("git", ["remote", "add", "origin", repoUrl], { cwd: tempDir });
|
|
566
|
+
await execa2("git", ["config", "core.sparseCheckout", "true"], { cwd: tempDir });
|
|
567
|
+
const sparseFile = path6.join(tempDir, ".git", "info", "sparse-checkout");
|
|
568
|
+
await fs6.writeFile(sparseFile, `${options.filePath}
|
|
569
|
+
`);
|
|
570
|
+
await execa2("git", ["pull", "origin", options.branch, "--depth=1"], {
|
|
571
|
+
cwd: tempDir,
|
|
572
|
+
stderr: "pipe"
|
|
573
|
+
});
|
|
574
|
+
const sourceFile = path6.join(tempDir, options.filePath);
|
|
575
|
+
if (!await fs6.pathExists(sourceFile)) {
|
|
576
|
+
throw new Error(`File '${options.filePath}' not found in repository`);
|
|
577
|
+
}
|
|
578
|
+
return await fs6.readFile(sourceFile, "utf-8");
|
|
579
|
+
} catch (error) {
|
|
580
|
+
if (error.stderr && error.stderr.includes("Authentication failed")) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
"Git authentication failed. Please check your WORKSPACE_CLI_TOKEN.\nThe token must have access to the repository."
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
throw new Error(`Failed to fetch file from git: ${error.message}`);
|
|
586
|
+
} finally {
|
|
587
|
+
await fs6.remove(tempDir);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// package.json
|
|
592
|
+
var package_default = {
|
|
593
|
+
name: "@aspects-ai/workspace-cli",
|
|
594
|
+
version: "0.1.6",
|
|
595
|
+
private: false,
|
|
596
|
+
description: "Lightweight CLI for installing libraries into workspaces",
|
|
597
|
+
type: "module",
|
|
598
|
+
bin: {
|
|
599
|
+
"workspace-cli": "./dist/index.js"
|
|
600
|
+
},
|
|
601
|
+
scripts: {
|
|
602
|
+
build: "tsup src/index.ts --format esm --dts --clean && npm run copy:registry",
|
|
603
|
+
"copy:registry": "mkdir -p dist/registry && cp src/registry/libraries.json dist/registry/",
|
|
604
|
+
dev: "tsup src/index.ts --format esm --watch",
|
|
605
|
+
typecheck: "tsc --noEmit"
|
|
606
|
+
},
|
|
607
|
+
files: [
|
|
608
|
+
"dist",
|
|
609
|
+
"src/registry"
|
|
610
|
+
],
|
|
611
|
+
dependencies: {
|
|
612
|
+
chalk: "^5.3.0",
|
|
613
|
+
commander: "^12.0.0",
|
|
614
|
+
execa: "^8.0.0",
|
|
615
|
+
"fs-extra": "^11.2.0",
|
|
616
|
+
zod: "^3.22.0"
|
|
617
|
+
},
|
|
618
|
+
devDependencies: {
|
|
619
|
+
"@types/fs-extra": "^11.0.0",
|
|
620
|
+
"@types/node": "^20",
|
|
621
|
+
tsup: "^8.0.0",
|
|
622
|
+
typescript: "^5"
|
|
623
|
+
},
|
|
624
|
+
engines: {
|
|
625
|
+
node: ">=18.0.0"
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
517
629
|
// src/index.ts
|
|
518
|
-
var program = new
|
|
519
|
-
program.name("workspace-cli").description("Lightweight CLI for installing libraries into workspaces").version(
|
|
630
|
+
var program = new Command7();
|
|
631
|
+
program.name("workspace-cli").description("Lightweight CLI for installing libraries into workspaces").version(package_default.version);
|
|
520
632
|
program.addCommand(createInitCommand());
|
|
521
633
|
program.addCommand(createListCommand());
|
|
522
634
|
program.addCommand(createAddCommand());
|
|
523
635
|
program.addCommand(createUpdateCommand());
|
|
524
636
|
program.addCommand(createCreateFrameCommand());
|
|
637
|
+
program.addCommand(createUpdateTemplateCommand());
|
|
525
638
|
program.parse(process.argv);
|