@cli-skill/cli 0.0.1-beta-d3a2d41 → 0.0.1-beta-16d46c3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cli-skill/cli",
3
- "version": "0.0.1-beta-d3a2d41",
3
+ "version": "0.0.1-beta-16d46c3",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -18,7 +18,7 @@
18
18
  "check": "tsc --noEmit -p tsconfig.json"
19
19
  },
20
20
  "dependencies": {
21
- "@cli-skill/core": "^0.0.1-beta-d3a2d41",
21
+ "@cli-skill/core": "^0.0.1-beta-16d46c3",
22
22
  "cac": "^6.7.14",
23
23
  "lodash": "^4.17.21"
24
24
  }
package/src/app.ts CHANGED
@@ -9,7 +9,7 @@ import { registerListCommand } from "./commands/list";
9
9
  import { registerPublishCommand } from "./commands/publish";
10
10
  import { registerUninstallCommand } from "./commands/uninstall";
11
11
 
12
- export function createApp() {
12
+ export function createApp(version: string) {
13
13
  const cli = cac("cli-skill");
14
14
 
15
15
  registerCreateCommand(cli);
@@ -23,6 +23,6 @@ export function createApp() {
23
23
  registerPublishCommand(cli);
24
24
 
25
25
  cli.help();
26
- cli.version("0.1.0");
26
+ cli.version(version);
27
27
  return cli;
28
28
  }
package/src/constants.ts CHANGED
@@ -1,10 +1,20 @@
1
1
  import path from "node:path";
2
+ import { access } from "node:fs/promises";
2
3
  import { getResolvedBrowserSkillCliConfig } from "./config";
3
4
 
4
5
  export const LOCAL_CORE_PACKAGE_PATH = path.resolve(import.meta.dirname, "../../core");
5
6
  export const LOCAL_TEMPLATE_PACKAGE_PATH = path.resolve(import.meta.dirname, "../../templates");
6
7
  export const DEFAULT_TEMPLATE_NAME = "basic";
7
8
 
9
+ export async function hasLocalTemplatesPackage(): Promise<boolean> {
10
+ try {
11
+ await access(path.join(LOCAL_TEMPLATE_PACKAGE_PATH, "package.json"));
12
+ return true;
13
+ } catch {
14
+ return false;
15
+ }
16
+ }
17
+
8
18
  export async function getDefaultSkillsRoot(): Promise<string> {
9
19
  const config = await getResolvedBrowserSkillCliConfig();
10
20
  return config.skillsRoot;
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { createApp } from "./app";
2
2
  import { ensureBrowserSkillCliConfig } from "./config";
3
+ import { getCliVersion } from "./version";
3
4
  export { createSkillProject } from "./project";
4
5
 
5
6
  async function main(argv = process.argv.slice(2)): Promise<void> {
6
7
  await ensureBrowserSkillCliConfig();
7
- const cli = createApp();
8
+ const cli = createApp(await getCliVersion());
8
9
  cli.parse(["node", "cli-skill", ...argv], { run: false });
9
10
  await cli.runMatchedCommand();
10
11
  }
package/src/project.ts CHANGED
@@ -4,6 +4,7 @@ import { pathToFileURL } from "node:url";
4
4
  import type { SkillDefinition } from "@cli-skill/core";
5
5
  import {
6
6
  DEFAULT_TEMPLATE_NAME,
7
+ hasLocalTemplatesPackage,
7
8
  LOCAL_CORE_PACKAGE_PATH,
8
9
  LOCAL_TEMPLATE_PACKAGE_PATH,
9
10
  getDefaultSkillsRoot,
@@ -30,6 +31,17 @@ async function getLocalCorePackageVersion(): Promise<string> {
30
31
  return corePackageJson.version;
31
32
  }
32
33
 
34
+ async function getCliPackageVersion(): Promise<string> {
35
+ const cliPackageJsonPath = path.resolve(import.meta.dirname, "..", "package.json");
36
+ const cliPackageJson = JSON.parse(await readFile(cliPackageJsonPath, "utf8")) as SkillPackageJson;
37
+
38
+ if (typeof cliPackageJson.version !== "string" || cliPackageJson.version.length === 0) {
39
+ throw new Error(`Missing version in ${cliPackageJsonPath}`);
40
+ }
41
+
42
+ return cliPackageJson.version;
43
+ }
44
+
33
45
  export async function createSkillProject(
34
46
  skillName: string,
35
47
  cliName = skillName,
@@ -38,12 +50,19 @@ export async function createSkillProject(
38
50
  ): Promise<string> {
39
51
  const resolvedTargetRoot = targetRoot ?? (await getDefaultSkillsRoot());
40
52
  const targetDir = path.join(resolvedTargetRoot, skillName);
41
- const corePackageVersion = await getLocalCorePackageVersion();
53
+ const usingLocalTemplates = await hasLocalTemplatesPackage();
54
+ const cliPackageVersion = usingLocalTemplates ? undefined : await getCliPackageVersion();
55
+ const corePackageVersion = usingLocalTemplates
56
+ ? await getLocalCorePackageVersion()
57
+ : cliPackageVersion!;
58
+ const templatePackageSpec = usingLocalTemplates
59
+ ? `file:${LOCAL_TEMPLATE_PACKAGE_PATH}`
60
+ : `@cli-skill/templates@${cliPackageVersion!}`;
42
61
  await runBunx(
43
62
  [
44
63
  "--bun",
45
64
  "--package",
46
- `file:${LOCAL_TEMPLATE_PACKAGE_PATH}`,
65
+ templatePackageSpec,
47
66
  "cli-skill-create-template",
48
67
  "--template",
49
68
  templateName,
package/src/version.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ let cachedVersion: string | undefined;
5
+
6
+ export async function getCliVersion(): Promise<string> {
7
+ if (cachedVersion) {
8
+ return cachedVersion;
9
+ }
10
+
11
+ const packageJsonPath = path.resolve(import.meta.dirname, "..", "package.json");
12
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8")) as { version?: string };
13
+
14
+ if (typeof packageJson.version !== "string" || packageJson.version.length === 0) {
15
+ throw new Error(`Missing version in ${packageJsonPath}`);
16
+ }
17
+
18
+ cachedVersion = packageJson.version;
19
+ return cachedVersion;
20
+ }