@cityholdings/minicube-dev 0.1.1 → 0.1.2
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/README.md +6 -2
- package/package.json +1 -1
- package/src/act.js +6 -7
- package/src/build.js +39 -13
package/README.md
CHANGED
|
@@ -36,8 +36,12 @@ npm publish
|
|
|
36
36
|
|
|
37
37
|
Optional tools, used only by the commands that need them: `adb` (Android preview), Xcode
|
|
38
38
|
command-line tools (`xcrun`, iOS simulator/device preview), `kubectl` (token administration or
|
|
39
|
-
`transport: "kube"`),
|
|
40
|
-
|
|
39
|
+
`transport: "kube"`), `cube-pack` (inline card images), and the mini program compiler
|
|
40
|
+
`mini-pkg-builder`.
|
|
41
|
+
|
|
42
|
+
Card projects must install ACT v4 themselves (`npm i -D @antdigital/cube@4`). minicube-dev uses only
|
|
43
|
+
that copy, found from the card directory upwards, and stops if it is missing or older than v4; a
|
|
44
|
+
global `act` (often ACT v2, which the apps cannot load) is never used.
|
|
41
45
|
|
|
42
46
|
## Configuration
|
|
43
47
|
|
package/package.json
CHANGED
package/src/act.js
CHANGED
|
@@ -2,10 +2,10 @@ import { mkdirSync, openSync } from 'node:fs';
|
|
|
2
2
|
import { createConnection } from 'node:net';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { cardDir, resolveAct } from './build.js';
|
|
5
|
+
import { cardDir, resolveAct, runAct } from './build.js';
|
|
6
6
|
import { adb, androidSerial } from './device.js';
|
|
7
7
|
import { CliError, log } from './log.js';
|
|
8
|
-
import { delay,
|
|
8
|
+
import { delay, runSync, spawnDetached } from './proc.js';
|
|
9
9
|
|
|
10
10
|
const DEFAULT_PORT = 9001;
|
|
11
11
|
const CONNECT_TIMEOUT_MS = 45_000;
|
|
@@ -55,8 +55,7 @@ export function advertisedHost(target) {
|
|
|
55
55
|
* address is restarted.
|
|
56
56
|
*/
|
|
57
57
|
export async function ensureActServer(project, port = DEFAULT_PORT, host = null) {
|
|
58
|
-
const act = resolveAct(project.root);
|
|
59
|
-
if (!act) throw new CliError('ACT not found', 'Install it in the card project: npm i -D @antdigital/cube');
|
|
58
|
+
const act = resolveAct(cardDir(project), project.root);
|
|
60
59
|
if (await isListening(port)) {
|
|
61
60
|
const current = (await serverAddress(port)).host;
|
|
62
61
|
if (!host || current === host) {
|
|
@@ -64,13 +63,13 @@ export async function ensureActServer(project, port = DEFAULT_PORT, host = null)
|
|
|
64
63
|
return act;
|
|
65
64
|
}
|
|
66
65
|
log.detail(`Restarting the ACT server: it advertises ${current}, this device needs ${host}`);
|
|
67
|
-
await
|
|
66
|
+
await runAct(act, ['prepare'], { cwd: project.root, capture: true });
|
|
68
67
|
const freed = Date.now() + 10_000;
|
|
69
68
|
while ((await isListening(port)) && Date.now() < freed) await delay(300);
|
|
70
69
|
}
|
|
71
70
|
mkdirSync(path.join(project.root, '.minicube'), { recursive: true });
|
|
72
71
|
const logFile = path.join(project.root, '.minicube', 'act-server.log');
|
|
73
|
-
spawnDetached(act,
|
|
72
|
+
spawnDetached(process.execPath, [act.script, 'server'], { cwd: project.root, logFd: openSync(logFile, 'a'), env: host ? { HOST: host } : undefined });
|
|
74
73
|
const deadline = Date.now() + 20_000;
|
|
75
74
|
while (Date.now() < deadline) {
|
|
76
75
|
await delay(500);
|
|
@@ -145,6 +144,6 @@ export async function attachDevice(target, env, devices, port = DEFAULT_PORT) {
|
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
export async function deliverCard(project, act) {
|
|
148
|
-
const result = await
|
|
147
|
+
const result = await runAct(act, ['preview', cardDir(project)], { cwd: project.root });
|
|
149
148
|
if (result.code !== 0) throw new CliError(`act preview failed (exit ${result.code})`);
|
|
150
149
|
}
|
package/src/build.js
CHANGED
|
@@ -176,10 +176,39 @@ async function buildH5(project, outRoot) {
|
|
|
176
176
|
// ---------------------------------------------------------------------------------------------
|
|
177
177
|
// Cards: cube-pack (inlines local images) when installed, otherwise the project's own `act build`.
|
|
178
178
|
|
|
179
|
-
export
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
export const ACT_MIN_MAJOR = 4;
|
|
180
|
+
const ACT_INSTALL_HINT = 'Install ACT v4 in the card project: npm i -D @antdigital/cube@4';
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The card project's own ACT v4 CLI script (`@antdigital/cube`), looked up like Node resolves
|
|
184
|
+
* packages: from each start directory up through its parents. A global `act` is never used — it is
|
|
185
|
+
* often ACT v2, whose builds and server the apps' v4 Cube host cannot load.
|
|
186
|
+
*/
|
|
187
|
+
export function resolveAct(...startDirs) {
|
|
188
|
+
for (const start of startDirs) {
|
|
189
|
+
for (let dir = path.resolve(start); ; dir = path.dirname(dir)) {
|
|
190
|
+
const pkgDir = path.join(dir, 'node_modules', '@antdigital', 'cube');
|
|
191
|
+
const pkgFile = path.join(pkgDir, 'package.json');
|
|
192
|
+
if (existsSync(pkgFile)) {
|
|
193
|
+
const pkg = JSON.parse(readFileSync(pkgFile, 'utf8'));
|
|
194
|
+
const major = Number.parseInt(String(pkg.version), 10);
|
|
195
|
+
if (!(major >= ACT_MIN_MAJOR)) {
|
|
196
|
+
throw new CliError(`${pkgDir} is ACT ${pkg.version}; ACT v${ACT_MIN_MAJOR} or newer is required`, ACT_INSTALL_HINT);
|
|
197
|
+
}
|
|
198
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.act;
|
|
199
|
+
const script = bin && path.join(pkgDir, bin);
|
|
200
|
+
if (!script || !existsSync(script)) throw new CliError(`${pkgDir} has no act CLI`, ACT_INSTALL_HINT);
|
|
201
|
+
return { script, version: pkg.version };
|
|
202
|
+
}
|
|
203
|
+
if (path.dirname(dir) === dir) break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
throw new CliError(`ACT v${ACT_MIN_MAJOR} (@antdigital/cube) is not installed in the card project`, ACT_INSTALL_HINT);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Run the project's ACT CLI with the current Node (also on Windows, where cli.js is not executable). */
|
|
210
|
+
export function runAct(act, args, options) {
|
|
211
|
+
return run(process.execPath, [act.script, ...args], options);
|
|
183
212
|
}
|
|
184
213
|
|
|
185
214
|
export function cardDir(project) {
|
|
@@ -189,16 +218,13 @@ export function cardDir(project) {
|
|
|
189
218
|
async function buildCard(project, outRoot) {
|
|
190
219
|
const dir = cardDir(project);
|
|
191
220
|
if (!existsSync(path.join(dir, 'manifest.json'))) throw new CliError(`${dir} is not a card (no manifest.json)`);
|
|
221
|
+
// Checked even when cube-pack builds: it runs the project's act, so a missing v4 must stop here.
|
|
222
|
+
const act = resolveAct(dir, project.root);
|
|
192
223
|
const cubePack = project.data.card?.useCubePack === false ? null : which('cube-pack');
|
|
193
|
-
log.step(`Building card ${project.data.resourceId}`);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
} else {
|
|
198
|
-
const act = resolveAct(project.root);
|
|
199
|
-
if (!act) throw new CliError('ACT not found', 'Install it in the card project: npm i -D @antdigital/cube');
|
|
200
|
-
result = await run(act, ['build', dir], { cwd: project.root });
|
|
201
|
-
}
|
|
224
|
+
log.step(`Building card ${project.data.resourceId} (ACT ${act.version})`);
|
|
225
|
+
const result = cubePack
|
|
226
|
+
? await run(cubePack, ['build'], { cwd: project.root })
|
|
227
|
+
: await runAct(act, ['build', dir], { cwd: project.root });
|
|
202
228
|
if (result.code !== 0) throw new CliError(`Card build failed (exit ${result.code})`);
|
|
203
229
|
const zip = findCardZip(dir);
|
|
204
230
|
const file = path.join(outRoot, `${project.data.resourceId}.zip`);
|