@aspects-ai/workspace-cli 0.1.3 → 0.1.5
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 +86 -2
- package/package.json +3 -3
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 Command6 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/init.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -431,11 +431,95 @@ Use 'workspace-cli add ${libraryName}' to install it first.`
|
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
+
// src/commands/create-frame.ts
|
|
435
|
+
import chalk5 from "chalk";
|
|
436
|
+
import { Command as Command5 } from "commander";
|
|
437
|
+
import fs5 from "fs-extra";
|
|
438
|
+
import path5 from "path";
|
|
439
|
+
function parseManifestOption(manifestStr) {
|
|
440
|
+
try {
|
|
441
|
+
return JSON.parse(manifestStr);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
throw new Error(`Invalid manifest JSON: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function validateAndFixManifest(manifest, toolName, frameName) {
|
|
447
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
448
|
+
const validatedManifest = {
|
|
449
|
+
id: manifest.id || frameName,
|
|
450
|
+
projectId: manifest.projectId || "default-project",
|
|
451
|
+
title: manifest.title || frameName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" "),
|
|
452
|
+
description: manifest.description || `Frame for ${toolName}`,
|
|
453
|
+
createdAt: now,
|
|
454
|
+
// Always update createdAt
|
|
455
|
+
type: manifest.type || "animationComposition"
|
|
456
|
+
};
|
|
457
|
+
if (toolName === "animate-core") {
|
|
458
|
+
validatedManifest.type = "animationComposition";
|
|
459
|
+
}
|
|
460
|
+
return validatedManifest;
|
|
461
|
+
}
|
|
462
|
+
async function getNextFrameName(framesDir, baseName) {
|
|
463
|
+
if (!await fs5.pathExists(path5.join(framesDir, baseName))) {
|
|
464
|
+
return baseName;
|
|
465
|
+
}
|
|
466
|
+
let counter = 1;
|
|
467
|
+
let nextName = `${baseName}-${counter}`;
|
|
468
|
+
while (await fs5.pathExists(path5.join(framesDir, nextName))) {
|
|
469
|
+
counter++;
|
|
470
|
+
nextName = `${baseName}-${counter}`;
|
|
471
|
+
}
|
|
472
|
+
return nextName;
|
|
473
|
+
}
|
|
474
|
+
async function fetchExampleFrame(toolName, targetPath) {
|
|
475
|
+
const library = await getLibrary(toolName);
|
|
476
|
+
const token = getToken();
|
|
477
|
+
logger.info(`Fetching example frame from ${chalk5.cyan(library.repository.url)}`);
|
|
478
|
+
const exampleFrameDirectory = library.repository.directory.replace("/src", "/example-frame");
|
|
479
|
+
await fetchDirectory({
|
|
480
|
+
repository: library.repository.url,
|
|
481
|
+
directory: exampleFrameDirectory,
|
|
482
|
+
branch: library.repository.branch,
|
|
483
|
+
token,
|
|
484
|
+
targetPath
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
function createCreateFrameCommand() {
|
|
488
|
+
return new Command5("create-frame").description("Create a new frame for a given tool").argument("<tool>", "Name of the tool (e.g., animate-core)").argument("<manifest>", "Manifest data as JSON string").option("-n, --name <name>", "Name for the new frame", "new-frame").action(async (toolName, manifestStr, options) => {
|
|
489
|
+
try {
|
|
490
|
+
const workspaceRoot = await ensureWorkspaceRoot();
|
|
491
|
+
const framesDir = path5.join(workspaceRoot, "frames");
|
|
492
|
+
await fs5.ensureDir(framesDir);
|
|
493
|
+
const baseName = options.name || "new-frame";
|
|
494
|
+
const frameName = await getNextFrameName(framesDir, baseName);
|
|
495
|
+
const frameDir = path5.join(framesDir, frameName);
|
|
496
|
+
logger.info(`Creating frame: ${chalk5.cyan(frameName)} for ${chalk5.cyan(toolName)}`);
|
|
497
|
+
await fetchExampleFrame(toolName, frameDir);
|
|
498
|
+
const manifestData = parseManifestOption(manifestStr);
|
|
499
|
+
const validatedManifest = validateAndFixManifest(manifestData, toolName, frameName);
|
|
500
|
+
const manifestPath = path5.join(frameDir, "manifest.json");
|
|
501
|
+
await fs5.writeJson(manifestPath, validatedManifest, { spaces: 4 });
|
|
502
|
+
logger.success(`Frame created at: ${chalk5.green(path5.relative(workspaceRoot, frameDir))}`);
|
|
503
|
+
logger.log("");
|
|
504
|
+
logger.log(chalk5.bold("Manifest:"));
|
|
505
|
+
logger.log(JSON.stringify(validatedManifest, null, 2));
|
|
506
|
+
logger.log("");
|
|
507
|
+
logger.log(chalk5.bold("Next steps:"));
|
|
508
|
+
logger.log(` ${chalk5.gray("Edit frame:")} ${path5.relative(workspaceRoot, path5.join(frameDir, "main.tsx"))}`);
|
|
509
|
+
logger.log("");
|
|
510
|
+
} catch (error) {
|
|
511
|
+
logger.error(error.message);
|
|
512
|
+
process.exit(1);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
434
517
|
// src/index.ts
|
|
435
|
-
var program = new
|
|
518
|
+
var program = new Command6();
|
|
436
519
|
program.name("workspace-cli").description("Lightweight CLI for installing libraries into workspaces").version("0.1.0");
|
|
437
520
|
program.addCommand(createInitCommand());
|
|
438
521
|
program.addCommand(createListCommand());
|
|
439
522
|
program.addCommand(createAddCommand());
|
|
440
523
|
program.addCommand(createUpdateCommand());
|
|
524
|
+
program.addCommand(createCreateFrameCommand());
|
|
441
525
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aspects-ai/workspace-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Lightweight CLI for installing libraries into workspaces",
|
|
6
6
|
"type": "module",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"src/registry"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"commander": "^12.0.0",
|
|
22
21
|
"chalk": "^5.3.0",
|
|
22
|
+
"commander": "^12.0.0",
|
|
23
23
|
"execa": "^8.0.0",
|
|
24
24
|
"fs-extra": "^11.2.0",
|
|
25
25
|
"zod": "^3.22.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^20",
|
|
29
28
|
"@types/fs-extra": "^11.0.0",
|
|
29
|
+
"@types/node": "^20",
|
|
30
30
|
"tsup": "^8.0.0",
|
|
31
31
|
"typescript": "^5"
|
|
32
32
|
},
|