packdog 0.1.2 → 0.1.4

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.
@@ -2,22 +2,18 @@ import { writeFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { getToken } from "../config.js";
4
4
  import { fetchJson } from "../api.js";
5
- export async function init(name) {
6
- if (!name) {
7
- console.error("Missing --name argument");
8
- console.error("Usage: packdog init --name=my-pack");
5
+ export async function init(id) {
6
+ if (!id) {
7
+ console.error("Missing --id argument");
8
+ console.error("Usage: packdog init --id=<packageId>");
9
+ console.error(" Run 'packdog list' to see packages you have access to.");
9
10
  process.exit(1);
10
11
  }
11
12
  const token = getToken();
12
- console.log(`Registering pack: ${name}`);
13
- const result = await fetchJson("/packages", token, {
14
- method: "POST",
15
- headers: { "Content-Type": "application/json" },
16
- body: JSON.stringify({ name })
17
- });
18
- const config = { packageId: result.packageId };
13
+ const pkg = await fetchJson(`/packages/${id}`, token);
14
+ const config = { packageId: pkg.id };
19
15
  const configPath = join(process.cwd(), "packdog.json");
20
16
  await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
21
- console.log(`Pack registered: ${result.packageId}`);
17
+ console.log(`Package: ${pkg.name}`);
22
18
  console.log(`Created packdog.json`);
23
19
  }
@@ -0,0 +1,14 @@
1
+ import { getToken } from "../config.js";
2
+ import { fetchJson } from "../api.js";
3
+ export async function listCmd() {
4
+ const token = getToken();
5
+ const packages = await fetchJson("/packages", token);
6
+ if (packages.length === 0) {
7
+ console.log("No packages found.");
8
+ return;
9
+ }
10
+ console.log("Packages:");
11
+ for (const p of packages) {
12
+ console.log(` ${p.name.padEnd(30)} ${p.id}`);
13
+ }
14
+ }
@@ -1,9 +1,13 @@
1
1
  import { getToken, getPackConfig } from "../config.js";
2
2
  import { fetchJson, fetchPackageName } from "../api.js";
3
3
  export async function rollback(channel) {
4
+ if (!channel) {
5
+ console.error("Error: --channel is required. Example: packdog rollback --channel=stable");
6
+ process.exit(1);
7
+ }
4
8
  const token = getToken();
5
9
  const config = await getPackConfig();
6
- const ch = channel ?? "stable";
10
+ const ch = channel;
7
11
  const name = await fetchPackageName(config.packageId, token);
8
12
  console.log(`Package: ${name}`);
9
13
  console.log(` Channel: ${ch}`);
@@ -1,7 +1,7 @@
1
1
  import { readdir, readFile, stat } from "node:fs/promises";
2
2
  import { join, relative } from "node:path";
3
3
  import { getToken, getPackConfig } from "../config.js";
4
- import { fetchApi, fetchPackageName } from "../api.js";
4
+ import { fetchApi, fetchJson, fetchPackageName } from "../api.js";
5
5
  async function getAllFiles(dir, baseDir = dir) {
6
6
  const files = [];
7
7
  const entries = await readdir(dir, { withFileTypes: true });
@@ -61,4 +61,11 @@ export async function upload() {
61
61
  const data = result;
62
62
  console.log(`\nUploaded: ${data.versionId}`);
63
63
  console.log(`Files: ${data.filesUploaded}, Size: ${(data.totalSize / 1024).toFixed(2)} KB`);
64
+ // Auto-publish to stage
65
+ const publishResult = await fetchJson(`/packages/${config.packageId}/channels/stage`, token, {
66
+ method: "POST",
67
+ headers: { "Content-Type": "application/json" },
68
+ body: JSON.stringify({ versionId: data.versionId })
69
+ });
70
+ console.log(`Published to ${publishResult.channel}: ${publishResult.versionId}`);
64
71
  }
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { init } from "./commands/init.js";
3
+ import { listCmd } from "./commands/list.js";
3
4
  import { upload } from "./commands/upload.js";
4
5
  import { publish } from "./commands/publish.js";
5
6
  import { rollback } from "./commands/rollback.js";
@@ -15,27 +16,31 @@ function getArg(name) {
15
16
  const HELP = `packdog — CLI for the Packdog package registry
16
17
 
17
18
  Commands:
18
- init Register a new pack and create packdog.json
19
+ list List packages you have access to (name + ID)
20
+ init Set up packdog.json for an existing package
19
21
  info Show pack name, versions and channels
20
- upload Upload dist/ as a new version
21
- publish Publish latest version to a channel
22
- rollback Roll back a channel to its previous version
22
+ upload Upload dist/ as a new version (auto-publishes to stage)
23
+ publish Publish latest version to a channel (default: stable)
24
+ rollback Roll back a channel to its previous version (--channel required)
23
25
  versions List all versions
24
26
  channels List all channels
25
27
 
26
28
  Options:
27
- --channel=<name> Channel name (default: stable)
29
+ --id=<packageId> Package ID (for init)
30
+ --channel=<name> Channel name (default: stable for publish; required for rollback)
28
31
  --version=<id> Specific version ID (for publish)
29
- --name=<name> Pack name (for init)
30
32
 
31
33
  Environment (set in .env or .env.development):
32
- PACKDOG_TOKEN API token (required)
34
+ PACKDOG_TOKEN Developer token (dev_...) — get one from your admin
33
35
  PACKDOG_URL API URL (default: https://packdog.dev)
34
36
  `;
35
37
  async function main() {
36
38
  switch (command) {
39
+ case "list":
40
+ await listCmd();
41
+ break;
37
42
  case "init":
38
- await init(getArg("name"));
43
+ await init(getArg("id"));
39
44
  break;
40
45
  case "upload":
41
46
  await upload();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "packdog",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "CLI for the Packdog package registry",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,