@40rty/ams-cli 0.2.0 → 0.2.1
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 +9 -2
- package/bin/commands/init.mjs +13 -2
- package/package.json +1 -1
package/bin/commands/dev.mjs
CHANGED
|
@@ -13,12 +13,19 @@
|
|
|
13
13
|
import { watch } from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import { cwd, deployment, fail, readConfig, readConfigIfPresent, writeDotenv } from '../lib/context.mjs';
|
|
16
|
-
import { call } from '../lib/credentials.mjs';
|
|
16
|
+
import { call, request } from '../lib/credentials.mjs';
|
|
17
17
|
import { init } from './init.mjs';
|
|
18
18
|
import { buildRelease } from './publish.mjs';
|
|
19
19
|
|
|
20
20
|
const SETTLE_MS = 150;
|
|
21
21
|
|
|
22
|
+
/** The console of the deployment this space lives on: `FORTY_CONSOLE_URL`, else the one the api names. */
|
|
23
|
+
async function previewConsole(config) {
|
|
24
|
+
if (process.env.FORTY_CONSOLE_URL) return deployment(config).consoleUrl;
|
|
25
|
+
const me = await request(config.apiUrl, 'GET', '/org/me');
|
|
26
|
+
return me.ok && typeof me.body.consoleUrl === 'string' ? me.body.consoleUrl : deployment(config).consoleUrl;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
export async function dev() {
|
|
23
30
|
if ((await readConfigIfPresent()) === null) await init();
|
|
24
31
|
const config = await readConfig();
|
|
@@ -65,7 +72,7 @@ export async function dev() {
|
|
|
65
72
|
await writeDotenv('FORTY_DEV_TOKEN', token);
|
|
66
73
|
console.log('\n wrote FORTY_DEV_TOKEN to .env — your app previews the draft. Keep it out of version control.\n');
|
|
67
74
|
} else {
|
|
68
|
-
console.log(`\n ${
|
|
75
|
+
console.log(`\n ${await previewConsole(config)}/${config.spaceSlug}?preview=${token}\n`);
|
|
69
76
|
}
|
|
70
77
|
// `--once`: store the draft and stop — for a script, or an agent, that cannot hold a watcher open.
|
|
71
78
|
if (process.argv.includes('--once')) return;
|
package/bin/commands/init.mjs
CHANGED
|
@@ -67,11 +67,22 @@ async function createSpace(apiUrl, { slug, name }) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/** An existing space, or `{ create: { slug, name } }` for one to make once everything else is known. */
|
|
70
|
+
const titleCase = (words) => words.split(/[-_\s]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join(' ');
|
|
71
|
+
|
|
72
|
+
/** A person-readable name from package.json: `@hosted-test/spacefront` → "Hosted Test", not "spacefront". */
|
|
73
|
+
function displayName(name) {
|
|
74
|
+
if (typeof name !== 'string' || name === '') return undefined;
|
|
75
|
+
const match = /^@([^/]+)\/(.+)$/.exec(name);
|
|
76
|
+
if (match === null) return titleCase(name);
|
|
77
|
+
return titleCase(/^(spacefront|storefront|web|app|site)$/.test(match[2]) ? match[1] : match[2]);
|
|
78
|
+
}
|
|
79
|
+
|
|
70
80
|
async function pickSpace(spaces, appName) {
|
|
71
81
|
const wanted = option('space');
|
|
72
82
|
const create = option('create');
|
|
73
83
|
if (wanted !== undefined && create !== undefined) fail('pass --space OR --create, not both');
|
|
74
|
-
|
|
84
|
+
// The slug the developer typed names the space better than a package name does.
|
|
85
|
+
if (create !== undefined) return { create: { slug: create, name: titleCase(create) } };
|
|
75
86
|
if (wanted !== undefined) {
|
|
76
87
|
const space = spaces.find((candidate) => candidate.slug === wanted);
|
|
77
88
|
const has = spaces.length === 0 ? 'none' : spaces.map((candidate) => candidate.slug).join(', ');
|
|
@@ -115,7 +126,7 @@ async function run() {
|
|
|
115
126
|
const manifest = JSON.parse(await readFile(path.join(cwd, 'package.json'), 'utf8'));
|
|
116
127
|
const dependencies = manifest.dependencies === undefined ? {} : manifest.dependencies;
|
|
117
128
|
const selfHosted = dependencies['@shopify/hydrogen'] !== undefined;
|
|
118
|
-
const appName =
|
|
129
|
+
const appName = displayName(manifest.name);
|
|
119
130
|
|
|
120
131
|
const me = await call(apiUrl, 'GET', '/org/me');
|
|
121
132
|
const picked = await pickSpace(me.spaces, appName);
|