@40rty/ams-cli 0.5.5 → 0.5.6
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/bin/commands/dev.mjs +32 -3
- package/bin/commands/publish.mjs +1 -1
- package/bin/lib/credentials.d.mts +12 -0
- package/package.json +1 -1
package/bin/commands/dev.mjs
CHANGED
|
@@ -10,12 +10,38 @@
|
|
|
10
10
|
// swaps it in place. An app that hosts its own spacefront already hot-reloads
|
|
11
11
|
// its components; only its catalog and manifests travel, and the token goes
|
|
12
12
|
// into its `.env`.
|
|
13
|
+
import { execFileSync } from 'node:child_process';
|
|
13
14
|
import { watch } from 'node:fs';
|
|
14
15
|
import path from 'node:path';
|
|
15
|
-
import { cwd, fail, readConfig, readConfigIfPresent, writeDotenv } from '../lib/context.mjs';
|
|
16
|
+
import { cwd, fail, option, readConfig, readConfigIfPresent, writeDotenv } from '../lib/context.mjs';
|
|
16
17
|
import { call } from '../lib/credentials.mjs';
|
|
17
18
|
import { init } from './init.mjs';
|
|
18
|
-
import { buildRelease } from './publish.mjs';
|
|
19
|
+
import { buildRelease, MAX_MESSAGE } from './publish.mjs';
|
|
20
|
+
|
|
21
|
+
function git(args) {
|
|
22
|
+
try {
|
|
23
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.warn(`forty: git ${args.join(' ')} failed — the draft goes without a description (${String(err).split('\n')[0]})`);
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* What the draft is, for the console's version menu: `--message "…"`, else the
|
|
32
|
+
* branch and its last commit (and whether the tree has more), read on every
|
|
33
|
+
* save. Two drafts from one credential looked identical there (2026-10-15).
|
|
34
|
+
*/
|
|
35
|
+
function draftMessage() {
|
|
36
|
+
const message = option('message');
|
|
37
|
+
if (typeof message === 'string' && message.trim() !== '') return message.trim().slice(0, MAX_MESSAGE);
|
|
38
|
+
const subject = git(['log', '-1', '--format=%s']);
|
|
39
|
+
if (subject === '') return undefined;
|
|
40
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
41
|
+
const head = branch === 'HEAD' || branch === '' ? git(['rev-parse', '--short', 'HEAD']) : branch;
|
|
42
|
+
const dirty = git(['status', '--porcelain', '--', '.']) === '' ? '' : ' (+ uncommitted)';
|
|
43
|
+
return `${head} · ${subject}${dirty}`.slice(0, MAX_MESSAGE);
|
|
44
|
+
}
|
|
19
45
|
|
|
20
46
|
const SETTLE_MS = 150;
|
|
21
47
|
|
|
@@ -45,7 +71,10 @@ export async function dev() {
|
|
|
45
71
|
running = true;
|
|
46
72
|
const started = Date.now();
|
|
47
73
|
try {
|
|
48
|
-
const
|
|
74
|
+
const release = await buildRelease(config);
|
|
75
|
+
const description = draftMessage();
|
|
76
|
+
if (description !== undefined) release.description = description;
|
|
77
|
+
const result = await call(config.apiUrl, 'PUT', `/org/spaces/${config.spaceSlug}/draft`, release);
|
|
49
78
|
console.log(`${new Date().toLocaleTimeString()} ${result.types.length} types → preview of ${config.spaceSlug} (${Date.now() - started} ms)`);
|
|
50
79
|
if (token === undefined) {
|
|
51
80
|
token = result.token;
|
package/bin/commands/publish.mjs
CHANGED
|
@@ -60,7 +60,7 @@ function warnShapeTokenExamples(catalog) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** A release's summary is one line a person can read in a version list. */
|
|
63
|
-
const MAX_MESSAGE = 140;
|
|
63
|
+
export const MAX_MESSAGE = 140;
|
|
64
64
|
|
|
65
65
|
/** `--message "…"`: what this release changed — mandatory; the console's version list shows it. */
|
|
66
66
|
export function releaseMessage() {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Types for `credentials.mjs`, for the TypeScript tooling that calls the api as the CLI does (scripts/create-space/promote.ts). */
|
|
2
|
+
export interface ApiResponse {
|
|
3
|
+
status: number;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
body: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** The key to send, and where it came from — `null` when there is none. */
|
|
9
|
+
export function findCredential(apiUrl: string): Promise<{ key: string; source: string; organization?: string } | null>;
|
|
10
|
+
|
|
11
|
+
/** One request to the api as the organization. Never throws on a refusal. */
|
|
12
|
+
export function request(apiUrl: string, method: string, route: string, body?: unknown): Promise<ApiResponse>;
|