@swipt/cli 0.1.0-nightly.22 → 0.1.0-nightly.24

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.
Files changed (2) hide show
  1. package/cli.mjs +18 -14
  2. package/package.json +2 -2
package/cli.mjs CHANGED
@@ -265,15 +265,14 @@ async function buildCommand(root) {
265
265
 
266
266
  const manifestEntry = /^(?:[^/]+\/)?manifest\.json$/;
267
267
 
268
- function sourceCommand(files, base, output) {
269
- if (!base) {
270
- throw new UsageError("source needs --url, the address the swiplets are published under");
271
- }
268
+ function sourceCommand(files, base, output, name) {
272
269
  let prefix;
273
- try {
274
- prefix = new URL(base.endsWith("/") ? base : `${base}/`);
275
- } catch {
276
- throw new UsageError(`--url ${JSON.stringify(base)} is not an absolute URL`);
270
+ if (base !== undefined) {
271
+ try {
272
+ prefix = new URL(base.endsWith("/") ? base : `${base}/`);
273
+ } catch {
274
+ throw new UsageError(`--url ${JSON.stringify(base)} is not an absolute URL`);
275
+ }
277
276
  }
278
277
  const swiplets = new Map();
279
278
  for (const file of files) {
@@ -291,10 +290,15 @@ function sourceCommand(files, base, output) {
291
290
  const data = fs.readFileSync(file);
292
291
  swiplets.set(manifest.id, {
293
292
  file,
294
- entry: { ...manifest, url: new URL(path.basename(file), prefix).href, size: data.length, sha256: createHash("sha256").update(data).digest("hex") },
293
+ entry: {
294
+ ...manifest,
295
+ ...(prefix ? { url: new URL(path.basename(file), prefix).href } : {}),
296
+ size: data.length,
297
+ sha256: createHash("sha256").update(data).digest("hex"),
298
+ },
295
299
  });
296
300
  }
297
- const listed = `${JSON.stringify({ swiplets: [...swiplets.keys()].sort().map(id => swiplets.get(id).entry) }, null, 2)}\n`;
301
+ const listed = `${JSON.stringify({ ...(name ? { name } : {}), swiplets: [...swiplets.keys()].sort().map(id => swiplets.get(id).entry) }, null, 2)}\n`;
298
302
  if (output) {
299
303
  fs.writeFileSync(output, listed);
300
304
  } else {
@@ -396,11 +400,11 @@ function createCommand(directory) {
396
400
 
397
401
  const usage = `usage: swiplet create <directory>
398
402
  swiplet build
399
- swiplet source --url <address> [--output <file>] <swiplet>...
403
+ swiplet source [--name <name>] [--url <address>] [--output <file>] <swiplet>...
400
404
 
401
405
  create make a swiplet project in a new or empty directory
402
406
  build bundle the project in this directory into dist/<swiplet.id>.swiplet
403
- source list built swiplets in a source that Swipt installs and updates from
407
+ source list built swiplets in a source; --url is where they are published
404
408
 
405
409
  Type-check a project with its "check" script.`;
406
410
 
@@ -411,7 +415,7 @@ class UsageError extends Error {}
411
415
  try {
412
416
  let parsed;
413
417
  try {
414
- parsed = parseArgs({ allowPositionals: true, options: { help: { type: "boolean", short: "h" }, url: { type: "string" }, output: { type: "string" } } });
418
+ parsed = parseArgs({ allowPositionals: true, options: { help: { type: "boolean", short: "h" }, name: { type: "string" }, url: { type: "string" }, output: { type: "string" } } });
415
419
  } catch (error) {
416
420
  throw new UsageError(error.message);
417
421
  }
@@ -429,7 +433,7 @@ try {
429
433
  } else if (command === "create") {
430
434
  createCommand(rest[0]);
431
435
  } else if (command === "source") {
432
- sourceCommand(rest, parsed.values.url, parsed.values.output);
436
+ sourceCommand(rest, parsed.values.url, parsed.values.output, parsed.values.name);
433
437
  } else {
434
438
  await buildCommand(process.cwd());
435
439
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swipt/cli",
3
- "version": "0.1.0-nightly.22",
3
+ "version": "0.1.0-nightly.24",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,6 +21,6 @@
21
21
  "esbuild": "^0.28.2"
22
22
  },
23
23
  "peerDependencies": {
24
- "@swipt/api": "0.1.0-nightly.22"
24
+ "@swipt/api": "0.1.0-nightly.24"
25
25
  }
26
26
  }