quiesco 0.4.0 → 0.4.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/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/doctor.d.ts +2 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +141 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts +2 -10
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +22 -179
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/upgrade.d.ts +8 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +185 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/setup-steps.d.ts +95 -0
- package/dist/setup-steps.d.ts.map +1 -0
- package/dist/setup-steps.js +289 -0
- package/dist/setup-steps.js.map +1 -0
- package/package.json +2 -2
- package/src/cli.ts +2 -0
- package/src/commands/doctor.ts +145 -4
- package/src/commands/init.ts +23 -199
- package/src/commands/upgrade.ts +189 -0
- package/src/setup-steps.ts +330 -0
package/src/commands/doctor.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* project's Quiesco setup. Every check says what is wrong and how to fix it; exit code 1 when a check
|
|
4
4
|
* fails (warnings do not fail).
|
|
5
5
|
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
6
7
|
import net from 'node:net';
|
|
7
8
|
import path from 'node:path';
|
|
8
9
|
|
|
@@ -14,7 +15,8 @@ import { PLATFORMS, parsePlatform, takeOption } from '../context.js';
|
|
|
14
15
|
import { CLI_COMMANDS, installedVersion, isQuiescoPackage, scriptCommands } from '../packages.js';
|
|
15
16
|
import { rootSourceFiles } from '../project.js';
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
/** `info`: worth knowing, nothing is wrong (counted neither as a warning nor as a failure). */
|
|
19
|
+
export type CheckStatus = 'ok' | 'info' | 'warn' | 'fail';
|
|
18
20
|
|
|
19
21
|
export interface CheckResult {
|
|
20
22
|
name: string;
|
|
@@ -29,7 +31,9 @@ export interface DoctorDeps {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
const MIN_NODE_MAJOR = 24;
|
|
32
|
-
const ICON: Record<CheckStatus, string> = { ok: '✅', warn: '⚠️ ', fail: '❌' };
|
|
34
|
+
const ICON: Record<CheckStatus, string> = { ok: '✅', info: 'ℹ️ ', warn: '⚠️ ', fail: '❌' };
|
|
35
|
+
/** How the fixes for older setups end (issues #34, #35). */
|
|
36
|
+
const UPGRADE_HINT = 'npx quiesco@latest init --upgrade fixes this';
|
|
33
37
|
|
|
34
38
|
interface PackageJson {
|
|
35
39
|
main?: string;
|
|
@@ -87,6 +91,7 @@ function projectChecks(ctx: CliContext): CheckResult[] {
|
|
|
87
91
|
);
|
|
88
92
|
|
|
89
93
|
results.push(...versionChecks(ctx, pkg));
|
|
94
|
+
results.push(...legacyChecks(ctx));
|
|
90
95
|
|
|
91
96
|
const appJson = readJson<{ expo?: { plugins?: unknown[] } }>(ctx, path.join(ctx.cwd, 'app.json'));
|
|
92
97
|
const plugins = appJson?.expo?.plugins ?? [];
|
|
@@ -157,7 +162,7 @@ function versionChecks(ctx: CliContext, pkg: PackageJson): CheckResult[] {
|
|
|
157
162
|
name: 'Quiesco versions',
|
|
158
163
|
status: 'fail',
|
|
159
164
|
detail: `different versions: ${list}`,
|
|
160
|
-
fix: `Quiesco's packages are released together and only work with the same version. Install one version of all of them, e.g. ${names.map((n) => `${n}@${newest}`).join(' ')}.`,
|
|
165
|
+
fix: `Quiesco's packages are released together and only work with the same version. Install one version of all of them, e.g. ${names.map((n) => `${n}@${newest}`).join(' ')}, or upgrade them all with npx quiesco@latest init --upgrade.`,
|
|
161
166
|
});
|
|
162
167
|
} else {
|
|
163
168
|
project = versions[0] as string;
|
|
@@ -168,7 +173,7 @@ function versionChecks(ctx: CliContext, pkg: PackageJson): CheckResult[] {
|
|
|
168
173
|
name: 'Quiesco versions',
|
|
169
174
|
status: 'warn',
|
|
170
175
|
detail: `the project has ${project}; this doctor is ${ctx.version}`,
|
|
171
|
-
fix: "Run the project's own CLI (npx quiesco doctor in the project directory), or upgrade the project
|
|
176
|
+
fix: "Run the project's own CLI (npx quiesco doctor in the project directory), or upgrade the project with npx quiesco@latest init --upgrade.",
|
|
172
177
|
},
|
|
173
178
|
);
|
|
174
179
|
}
|
|
@@ -184,6 +189,140 @@ function versionChecks(ctx: CliContext, pkg: PackageJson): CheckResult[] {
|
|
|
184
189
|
return results;
|
|
185
190
|
}
|
|
186
191
|
|
|
192
|
+
const CUCUMBER_FILES = ['cucumber.mjs', 'cucumber.js', 'cucumber.cjs', 'cucumber.json', 'cucumber.yaml', 'cucumber.yml'];
|
|
193
|
+
const CONFIG_FILES = ['quiesco.config.mts', 'quiesco.config.ts', 'quiesco.config.mjs', 'quiesco.config.js'];
|
|
194
|
+
const DYNAMIC_APP_CONFIGS = ['app.config.ts', 'app.config.js', 'app.config.mjs', 'app.config.cjs'];
|
|
195
|
+
|
|
196
|
+
/** The first step / support file under features/ that imports a relative .ts file, or null. */
|
|
197
|
+
function tsImport(ctx: CliContext): string | null {
|
|
198
|
+
const dir = path.join(ctx.cwd, 'features');
|
|
199
|
+
let files: string[];
|
|
200
|
+
try {
|
|
201
|
+
files = (fs.readdirSync(dir, { recursive: true }) as string[]).filter((f) => /\.[cm]?tsx?$/.test(f) && !f.split(path.sep).includes('node_modules'));
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const relTs = /(?:from\s+|import\s*\(?\s*)['"]\.{1,2}\/[^'"]+\.[cm]?tsx?['"]/;
|
|
206
|
+
return files.find((f) => relTs.test(ctx.readFile(path.join(dir, f)) ?? '')) ?? null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Issue #35: files written by older inits that the current one writes differently. Reported only when
|
|
211
|
+
* something is wrong.
|
|
212
|
+
*/
|
|
213
|
+
function legacyChecks(ctx: CliContext): CheckResult[] {
|
|
214
|
+
const results: CheckResult[] = [];
|
|
215
|
+
const cucumber = CUCUMBER_FILES.find((f) => ctx.exists(path.join(ctx.cwd, f)));
|
|
216
|
+
if (cucumber !== undefined && /\bpaths\b["']?\s*:/.test(ctx.readFile(path.join(ctx.cwd, cucumber)) ?? '')) {
|
|
217
|
+
results.push({
|
|
218
|
+
name: 'cucumber paths',
|
|
219
|
+
status: 'warn',
|
|
220
|
+
detail: `${cucumber} sets paths`,
|
|
221
|
+
fix: `cucumber-js adds them to the files given on the command line, so quiesco test features/x.feature runs every feature. Remove the line (features/**/*.feature is the default); ${UPGRADE_HINT}.`,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const tsconfig = ctx.readFile(path.join(ctx.cwd, 'tsconfig.json'));
|
|
225
|
+
if (tsconfig !== null && !/"allowImportingTsExtensions"\s*:\s*true/.test(tsconfig)) {
|
|
226
|
+
const importer = tsImport(ctx);
|
|
227
|
+
if (importer !== null) {
|
|
228
|
+
results.push({
|
|
229
|
+
name: 'tsconfig',
|
|
230
|
+
status: 'fail',
|
|
231
|
+
detail: `features/${importer} imports a .ts file, and tsconfig.json does not set allowImportingTsExtensions`,
|
|
232
|
+
fix: `Add "allowImportingTsExtensions": true to compilerOptions: tsc fails with TS5097 without it (step files must name the .ts file for Node's type stripping); ${UPGRADE_HINT}.`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return results;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** e2e builds have a script for each native platform in the config (older inits did not write them). */
|
|
240
|
+
function buildScriptChecks(pkg: PackageJson | null, config: QuiescoConfig): CheckResult[] {
|
|
241
|
+
const scripts = Object.values(pkg?.scripts ?? {});
|
|
242
|
+
return (['ios', 'android'] as const)
|
|
243
|
+
.filter((p) => config.apps[p] !== undefined && !scripts.some((s) => new RegExp(`\\bquiesco build ${p}\\b`).test(s)))
|
|
244
|
+
.map((p) => ({
|
|
245
|
+
name: 'build scripts',
|
|
246
|
+
status: 'info' as const,
|
|
247
|
+
detail: `no script runs quiesco build ${p}`,
|
|
248
|
+
fix: `Add "e2e:build:${p}": "quiesco build ${p}" to package.json (or run npx quiesco build ${p}); ${UPGRADE_HINT}.`,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface AppJsonIds {
|
|
253
|
+
expo?: { scheme?: string | string[]; ios?: { bundleIdentifier?: string }; android?: { package?: string } };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Issue #34: quiesco.config names the app that the build makes. Compared with app.json (what expo prebuild
|
|
258
|
+
* uses) and, when they exist, with the prebuilt Android project and the iOS build. Placeholders left by
|
|
259
|
+
* init fail.
|
|
260
|
+
*/
|
|
261
|
+
async function appIdChecks(ctx: CliContext, config: QuiescoConfig): Promise<CheckResult[]> {
|
|
262
|
+
const { ios, android } = config.apps;
|
|
263
|
+
if (ios === undefined && android === undefined) return [];
|
|
264
|
+
const configFile = CONFIG_FILES.find((f) => ctx.exists(path.join(ctx.cwd, f)));
|
|
265
|
+
const todos = [...((configFile !== undefined ? ctx.readFile(path.join(ctx.cwd, configFile)) : null) ?? '').matchAll(/\/\/ TODO: (expo\.[\w.]+)/g)].map((m) => m[1] as string);
|
|
266
|
+
if (todos.length > 0) {
|
|
267
|
+
return [
|
|
268
|
+
{
|
|
269
|
+
name: 'app IDs',
|
|
270
|
+
status: 'fail',
|
|
271
|
+
detail: `${configFile as string} still has init's placeholders (TODO: ${todos.join(', ')})`,
|
|
272
|
+
fix: `Set the IDs in app.json (expo.ios.bundleIdentifier, expo.android.package, expo.scheme) and the same values in quiesco.config; ${UPGRADE_HINT}.`,
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
const dynamic = DYNAMIC_APP_CONFIGS.find((f) => ctx.exists(path.join(ctx.cwd, f)));
|
|
277
|
+
const results: CheckResult[] = [];
|
|
278
|
+
if (dynamic !== undefined) {
|
|
279
|
+
results.push({ name: 'app IDs', status: 'warn', detail: `${dynamic} found; cannot compare the app IDs with it`, fix: 'Make sure apps.ios.bundleId, apps.android.package and devClient.scheme are the values your app config sets.' });
|
|
280
|
+
} else {
|
|
281
|
+
const expo = readJson<AppJsonIds>(ctx, path.join(ctx.cwd, 'app.json'))?.expo ?? {};
|
|
282
|
+
const schemes = expo.scheme === undefined ? [] : Array.isArray(expo.scheme) ? expo.scheme : [expo.scheme];
|
|
283
|
+
const problems: string[] = [];
|
|
284
|
+
const compare = (what: string, want: string, have: string | undefined): void => {
|
|
285
|
+
if (have === undefined) problems.push(`app.json has no expo.${what} (the build gets Expo's default, not ${want})`);
|
|
286
|
+
else if (have !== want) problems.push(`quiesco.config has ${want}, app.json expo.${what} is ${have}`);
|
|
287
|
+
};
|
|
288
|
+
if (ios !== undefined) compare('ios.bundleIdentifier', ios.bundleId, expo.ios?.bundleIdentifier);
|
|
289
|
+
if (android !== undefined) compare('android.package', android.package, expo.android?.package);
|
|
290
|
+
const scheme = android?.devClient?.scheme;
|
|
291
|
+
if (scheme !== undefined && !schemes.includes(scheme)) {
|
|
292
|
+
problems.push(schemes.length === 0 ? `app.json has no expo.scheme (the dev client cannot be opened with ${scheme}://)` : `devClient.scheme is ${scheme}, app.json expo.scheme is ${schemes.join(', ')}`);
|
|
293
|
+
}
|
|
294
|
+
results.push(
|
|
295
|
+
problems.length === 0
|
|
296
|
+
? { name: 'app IDs', status: 'ok', detail: 'quiesco.config matches app.json' }
|
|
297
|
+
: { name: 'app IDs', status: 'fail', detail: problems.join('; '), fix: 'Use the same IDs in app.json and quiesco.config, then build again (npx quiesco build ios / android).' },
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
// The builds: an app built before the IDs changed is another app.
|
|
301
|
+
if (android !== undefined) {
|
|
302
|
+
const gradle = ctx.readFile(path.join(ctx.cwd, 'android/app/build.gradle'));
|
|
303
|
+
const built = gradle === null ? undefined : /applicationId\s*(?:=\s*)?['"]([^'"]+)['"]/.exec(gradle)?.[1];
|
|
304
|
+
const manifest = ctx.readFile(path.join(ctx.cwd, 'android/app/src/main/AndroidManifest.xml'));
|
|
305
|
+
const scheme = android.devClient?.scheme;
|
|
306
|
+
const wrong: string[] = [];
|
|
307
|
+
if (built !== undefined && built !== android.package) wrong.push(`android/app/build.gradle has applicationId ${built}`);
|
|
308
|
+
if (scheme !== undefined && manifest !== null && !manifest.includes(`android:scheme="${scheme}"`)) wrong.push(`AndroidManifest.xml registers no ${scheme}:// scheme`);
|
|
309
|
+
if (wrong.length > 0) {
|
|
310
|
+
results.push({ name: 'Android: app ID', status: 'fail', detail: `${wrong.join('; ')} (quiesco.config: ${android.package}${scheme !== undefined ? `, ${scheme}://` : ''})`, fix: 'Build again once app.json has the IDs quiesco.config names: npx quiesco build android (it runs expo prebuild with app.json).' });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (ios?.binaryPath !== undefined && ctx.platform === 'darwin') {
|
|
314
|
+
const plist = path.join(path.resolve(ctx.cwd, ios.binaryPath), 'Info.plist');
|
|
315
|
+
if (ctx.exists(plist)) {
|
|
316
|
+
const r = await ctx.exec('plutil', ['-extract', 'CFBundleIdentifier', 'raw', plist]);
|
|
317
|
+
const built = r.code === 0 ? r.stdout.trim() : '';
|
|
318
|
+
if (built !== '' && built !== ios.bundleId) {
|
|
319
|
+
results.push({ name: 'iOS: app ID', status: 'fail', detail: `${ios.binaryPath} is ${built} (quiesco.config: ${ios.bundleId})`, fix: 'Build again once app.json has the ID quiesco.config names: npx quiesco build ios.' });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return results;
|
|
324
|
+
}
|
|
325
|
+
|
|
187
326
|
/** Numeric semver order (prerelease tags compare as text). */
|
|
188
327
|
function compareVersions(a: string, b: string): number {
|
|
189
328
|
const pa = a.split(/[.-]/);
|
|
@@ -340,6 +479,8 @@ export async function runChecks(ctx: CliContext, only: CliPlatform | undefined,
|
|
|
340
479
|
try {
|
|
341
480
|
config = await deps.loadConfig(ctx.cwd);
|
|
342
481
|
results.push({ name: 'quiesco.config', status: 'ok', detail: `apps: ${Object.keys(config.apps).join(', ') || 'none'}` });
|
|
482
|
+
results.push(...(await appIdChecks(ctx, config)));
|
|
483
|
+
results.push(...buildScriptChecks(readJson<PackageJson>(ctx, path.join(ctx.cwd, 'package.json')), config));
|
|
343
484
|
} catch (e) {
|
|
344
485
|
results.push({ name: 'quiesco.config', status: 'fail', detail: (e as Error).message.split('\n')[0] ?? '', fix: 'Create quiesco.config.mts (npx quiesco init writes one).' });
|
|
345
486
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -6,94 +6,17 @@
|
|
|
6
6
|
* `--packages <dir>`: install Quiesco from the tarballs in <dir> (`pnpm pack` output) instead of the
|
|
7
7
|
* npm registry, and point the packages' own @quiesco/* dependencies at those tarballs too.
|
|
8
8
|
*/
|
|
9
|
-
import fs from 'node:fs';
|
|
10
9
|
import path from 'node:path';
|
|
11
10
|
|
|
12
11
|
import type { CliContext, CliPlatform } from '../context.js';
|
|
13
12
|
import { PLATFORMS, takeFlag, takeOption } from '../context.js';
|
|
14
|
-
import { installedVersion, isQuiescoPackage } from '../packages.js';
|
|
15
13
|
import { entryFile, registeredRoot, rootSourceFiles, wrapRegisteredRoot } from '../project.js';
|
|
14
|
+
import type { AppJson, InitStep, PackageJson, StepLog } from '../setup-steps.js';
|
|
15
|
+
import { DEV, RUNTIME, WEB_DEV, detectPackageManager, ensureAppIds, ensureScripts, ensureTsconfig, firstScheme, installPackages, printSteps, readJson, writeJson } from '../setup-steps.js';
|
|
16
|
+
import { upgradeCommand } from './upgrade.js';
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface PackageJson {
|
|
20
|
-
name?: string;
|
|
21
|
-
main?: string;
|
|
22
|
-
scripts?: Record<string, string>;
|
|
23
|
-
dependencies?: Record<string, string>;
|
|
24
|
-
devDependencies?: Record<string, string>;
|
|
25
|
-
overrides?: Record<string, string>;
|
|
26
|
-
resolutions?: Record<string, string>;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface AppJson {
|
|
31
|
-
expo?: {
|
|
32
|
-
name?: string;
|
|
33
|
-
scheme?: string | string[];
|
|
34
|
-
plugins?: unknown[];
|
|
35
|
-
ios?: { bundleIdentifier?: string };
|
|
36
|
-
android?: { package?: string };
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Installed into `dependencies`: the app bundles them (stubbed / excluded in production builds). */
|
|
42
|
-
const RUNTIME = ['@quiesco/agent', '@quiesco/native'];
|
|
43
|
-
/** Installed into `devDependencies`. */
|
|
44
|
-
const DEV = ['quiesco', '@quiesco/core', '@quiesco/cucumber', '@quiesco/expo-plugin', '@cucumber/cucumber'];
|
|
45
|
-
const WEB_DEV = ['@quiesco/web', 'playwright'];
|
|
46
|
-
/** Internal packages pulled in by the ones above; only pinned when installing from tarballs. */
|
|
47
|
-
const TRANSITIVE = ['@quiesco/protocol'];
|
|
48
|
-
|
|
49
|
-
export function detectPackageManager(ctx: CliContext): PackageManager {
|
|
50
|
-
if (ctx.exists(path.join(ctx.cwd, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
51
|
-
if (ctx.exists(path.join(ctx.cwd, 'yarn.lock'))) return 'yarn';
|
|
52
|
-
if (ctx.exists(path.join(ctx.cwd, 'bun.lock')) || ctx.exists(path.join(ctx.cwd, 'bun.lockb'))) return 'bun';
|
|
53
|
-
return 'npm';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** `@quiesco/agent` → `quiesco-agent-<version>.tgz` (the file name `pnpm pack` / `npm pack` writes). */
|
|
57
|
-
export function findTarballs(dir: string, names: readonly string[], list: (d: string) => string[] = (d) => fs.readdirSync(d)): Map<string, string> {
|
|
58
|
-
const files = list(dir).filter((f) => f.endsWith('.tgz'));
|
|
59
|
-
const found = new Map<string, string>();
|
|
60
|
-
for (const name of names) {
|
|
61
|
-
const base = name.replace(/^@/, '').replace('/', '-');
|
|
62
|
-
const match = files.find((f) => new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}-\\d[^/]*\\.tgz$`).test(f));
|
|
63
|
-
if (match !== undefined) found.set(name, path.join(dir, match));
|
|
64
|
-
}
|
|
65
|
-
return found;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** An `overrides:` block for pnpm-workspace.yaml (names and paths quoted: `@` starts no plain YAML scalar). */
|
|
69
|
-
function pnpmOverrides(pins: Record<string, string>): string {
|
|
70
|
-
return `overrides:\n${Object.entries(pins).map(([n, f]) => ` ${JSON.stringify(n)}: ${JSON.stringify(f)}\n`).join('')}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function addCommand(pm: PackageManager, dev: boolean, specs: string[]): { command: string; args: string[] } {
|
|
74
|
-
switch (pm) {
|
|
75
|
-
case 'pnpm':
|
|
76
|
-
return { command: 'pnpm', args: ['add', ...(dev ? ['-D'] : []), ...specs] };
|
|
77
|
-
case 'yarn':
|
|
78
|
-
return { command: 'yarn', args: ['add', ...(dev ? ['-D'] : []), ...specs] };
|
|
79
|
-
case 'bun':
|
|
80
|
-
return { command: 'bun', args: ['add', ...(dev ? ['-d'] : []), ...specs] };
|
|
81
|
-
case 'npm':
|
|
82
|
-
return { command: 'npm', args: ['install', ...(dev ? ['--save-dev'] : []), ...specs] };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function readJson<T>(ctx: CliContext, file: string): T | null {
|
|
87
|
-
const text = ctx.readFile(file);
|
|
88
|
-
if (text === null) return null;
|
|
89
|
-
try {
|
|
90
|
-
return JSON.parse(text) as T;
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const writeJson = (ctx: CliContext, file: string, value: unknown): void => ctx.writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
18
|
+
export { detectPackageManager, findTarballs } from '../setup-steps.js';
|
|
19
|
+
export type { InitStep } from '../setup-steps.js';
|
|
97
20
|
|
|
98
21
|
const METRO_CONFIG = `// Learn more https://docs.expo.dev/guides/customizing-metro
|
|
99
22
|
const { getDefaultConfig } = require('expo/metro-config');
|
|
@@ -120,7 +43,7 @@ export function iosAppName(name: string | undefined): { name: string; exact: boo
|
|
|
120
43
|
}
|
|
121
44
|
|
|
122
45
|
function quiescoConfig(app: AppJson, platforms: readonly CliPlatform[]): string {
|
|
123
|
-
const scheme =
|
|
46
|
+
const scheme = firstScheme(app);
|
|
124
47
|
const ios = iosAppName(app.expo?.name);
|
|
125
48
|
const lines = [`import { defineConfig } from '@quiesco/core';`, '', 'export default defineConfig({', ' apps: {'];
|
|
126
49
|
if (platforms.includes('ios')) {
|
|
@@ -201,13 +124,8 @@ Then('the home screen is visible', async function (this: QuiescoWorld) {
|
|
|
201
124
|
});
|
|
202
125
|
`;
|
|
203
126
|
|
|
204
|
-
export interface InitStep {
|
|
205
|
-
status: 'created' | 'updated' | 'skipped' | 'ran' | 'todo';
|
|
206
|
-
what: string;
|
|
207
|
-
note?: string;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
127
|
export async function initCommand(args: readonly string[], ctx: CliContext): Promise<number> {
|
|
128
|
+
if (args.includes('--upgrade')) return upgradeCommand(args.filter((a) => a !== '--upgrade'), ctx);
|
|
211
129
|
let rest = [...args];
|
|
212
130
|
const platformsOpt = takeOption(rest, '--platforms');
|
|
213
131
|
rest = platformsOpt.rest;
|
|
@@ -236,83 +154,20 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
236
154
|
: ['ios', 'android', ...(hasWebDeps ? (['web'] as const) : [])];
|
|
237
155
|
|
|
238
156
|
const steps: InitStep[] = [];
|
|
157
|
+
const log: StepLog = { ctx, steps, dryRun: false };
|
|
239
158
|
const pm = detectPackageManager(ctx);
|
|
240
159
|
|
|
241
160
|
// 1. Dependencies.
|
|
242
161
|
const runtime = [...RUNTIME];
|
|
243
162
|
const dev = [...DEV, ...(platforms.includes('web') ? WEB_DEV : [])];
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const tarballs = findTarballs(dir, ours);
|
|
253
|
-
const missing = ours.filter((n) => !tarballs.has(n));
|
|
254
|
-
if (missing.length > 0) {
|
|
255
|
-
ctx.err(`quiesco init: no tarball for ${missing.join(', ')} in ${dir}`);
|
|
256
|
-
return 1;
|
|
257
|
-
}
|
|
258
|
-
spec = (name) => (tarballs.has(name) ? `file:${tarballs.get(name) as string}` : name);
|
|
259
|
-
expected = (name) => /-(\d[^/]*)\.tgz$/.exec(tarballs.get(name) ?? '')?.[1] ?? ctx.version;
|
|
260
|
-
// Their own dependencies on each other ("@quiesco/protocol": "0.0.0") must resolve to the tarballs too.
|
|
261
|
-
// npm refuses an override for a package that is also a direct dependency (EOVERRIDE) and reuses the
|
|
262
|
-
// directly installed tarballs for those ranges anyway: pin only the indirect ones there. pnpm and
|
|
263
|
-
// yarn resolve every dependency on its own, so they need all of them pinned.
|
|
264
|
-
const direct = new Set([...runtime, ...dev]);
|
|
265
|
-
const pins = Object.fromEntries([...tarballs].filter(([n]) => pm !== 'npm' || !direct.has(n)).map(([n, f]) => [n, `file:${f}`]));
|
|
266
|
-
const pinned = `installing from the tarballs in ${packagesOpt.value} (${Object.keys(pins).length} indirect ${Object.keys(pins).length === 1 ? 'dependency' : 'dependencies'} pinned)`;
|
|
267
|
-
if (pm === 'pnpm') {
|
|
268
|
-
// pnpm 10+ reads overrides from pnpm-workspace.yaml only; the "pnpm" field of package.json is ignored.
|
|
269
|
-
const yamlFile = path.join(ctx.cwd, 'pnpm-workspace.yaml');
|
|
270
|
-
const yaml = ctx.readFile(yamlFile) ?? '';
|
|
271
|
-
if (/^overrides:/m.test(yaml)) {
|
|
272
|
-
ctx.err(`quiesco init: pnpm-workspace.yaml already has overrides; add these and run quiesco init again:\n${pnpmOverrides(pins)}`);
|
|
273
|
-
return 1;
|
|
274
|
-
}
|
|
275
|
-
ctx.writeFile(yamlFile, `${yaml}${yaml === '' || yaml.endsWith('\n') ? '' : '\n'}${pnpmOverrides(pins)}`);
|
|
276
|
-
steps.push({ status: 'updated', what: 'pnpm-workspace.yaml', note: pinned });
|
|
277
|
-
} else {
|
|
278
|
-
const current = readJson<PackageJson>(ctx, pkgFile) as PackageJson;
|
|
279
|
-
if (pm === 'yarn') current.resolutions = { ...current.resolutions, ...pins };
|
|
280
|
-
else current.overrides = { ...current.overrides, ...pins };
|
|
281
|
-
writeJson(ctx, pkgFile, current);
|
|
282
|
-
steps.push({ status: 'updated', what: 'package.json', note: pinned });
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const installs = [addCommand(pm, false, runtime.map(spec)), addCommand(pm, true, dev.map(spec))];
|
|
286
|
-
for (const cmd of installs) {
|
|
287
|
-
const line = `${cmd.command} ${cmd.args.join(' ')}`;
|
|
288
|
-
if (skipInstall.present) {
|
|
289
|
-
steps.push({ status: 'todo', what: 'install', note: line });
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
ctx.out(`$ ${line}`);
|
|
293
|
-
const r = await ctx.exec(cmd.command, cmd.args, { cwd: ctx.cwd });
|
|
294
|
-
if (r.code !== 0) {
|
|
295
|
-
ctx.err(r.stderr.trim() || r.stdout.trim());
|
|
296
|
-
ctx.err(`quiesco init: \`${line}\` failed (exit ${r.code}).`);
|
|
297
|
-
return 1;
|
|
298
|
-
}
|
|
299
|
-
steps.push({ status: 'ran', what: 'install', note: line });
|
|
300
|
-
}
|
|
301
|
-
if (!skipInstall.present) {
|
|
302
|
-
const ours = [...runtime, ...dev].filter(isQuiescoPackage);
|
|
303
|
-
const wrong = ours.map((name) => ({ name, want: expected(name), got: installedVersion(ctx, name) })).filter((p) => p.got !== p.want);
|
|
304
|
-
if (wrong.length > 0) {
|
|
305
|
-
ctx.err(`quiesco init: the installed Quiesco packages are not the version that was asked for:`);
|
|
306
|
-
for (const p of wrong) ctx.err(` ${p.name}: ${p.got ?? 'not found in node_modules'} (wanted ${p.want})`);
|
|
307
|
-
ctx.err('All Quiesco packages must have the same version as the CLI that writes the project files. The');
|
|
308
|
-
ctx.err("package manager may have used stale registry metadata from its cache, or held a new release back");
|
|
309
|
-
ctx.err('(pnpm minimumReleaseAge). Install them again with the version given:');
|
|
310
|
-
for (const cmd of [addCommand(pm, false, runtime.map(spec)), addCommand(pm, true, dev.filter(isQuiescoPackage).map(spec))]) ctx.err(` ${cmd.command} ${cmd.args.join(' ')}`);
|
|
311
|
-
ctx.err('then run quiesco init again.');
|
|
312
|
-
return 1;
|
|
313
|
-
}
|
|
314
|
-
steps.push({ status: 'ran', what: 'versions', note: `${ours.length} Quiesco packages at ${[...new Set(ours.map(expected))].join(', ')}` });
|
|
315
|
-
}
|
|
163
|
+
const installed = await installPackages(log, {
|
|
164
|
+
pm,
|
|
165
|
+
runtime,
|
|
166
|
+
dev,
|
|
167
|
+
...(packagesOpt.value !== undefined ? { packagesDir: packagesOpt.value } : {}),
|
|
168
|
+
skipInstall: skipInstall.present,
|
|
169
|
+
});
|
|
170
|
+
if (!installed) return 1;
|
|
316
171
|
|
|
317
172
|
// 2. Config plugin in app.json.
|
|
318
173
|
const appFile = path.join(ctx.cwd, 'app.json');
|
|
@@ -330,6 +185,9 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
330
185
|
steps.push({ status: 'todo', what: 'app config', note: 'add "@quiesco/expo-plugin" to the plugins of your app config' });
|
|
331
186
|
}
|
|
332
187
|
|
|
188
|
+
// 2b. App IDs (issue #34): app.json without them builds an app with Expo's defaults, not the config's.
|
|
189
|
+
const appWithIds = ensureAppIds(log, platforms);
|
|
190
|
+
|
|
333
191
|
// 3. Metro.
|
|
334
192
|
const metro = ['metro.config.js', 'metro.config.cjs', 'metro.config.mjs', 'metro.config.ts'].map((f) => path.join(ctx.cwd, f)).find((f) => ctx.exists(f));
|
|
335
193
|
if (metro === undefined) {
|
|
@@ -399,7 +257,7 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
399
257
|
ctx.writeFile(path.join(ctx.cwd, rel), content);
|
|
400
258
|
steps.push({ status: 'created', what: rel, note });
|
|
401
259
|
};
|
|
402
|
-
write('quiesco.config.mts', quiescoConfig(
|
|
260
|
+
write('quiesco.config.mts', quiescoConfig(appWithIds, platforms), `apps: ${platforms.join(', ')}`, ['quiesco.config.ts', 'quiesco.config.mts', 'quiesco.config.js', 'quiesco.config.mjs']);
|
|
403
261
|
write('cucumber.mjs', CUCUMBER_CONFIG, 'step files and format (features/**/*.feature by default)', ['cucumber.mjs', 'cucumber.js', 'cucumber.cjs', 'cucumber.json', 'cucumber.yaml', 'cucumber.yml']);
|
|
404
262
|
write('features/package.json', '{ "type": "module" }\n', 'step files are ES modules');
|
|
405
263
|
write('features/support/quiesco.ts', SUPPORT, 'this.app and the lifecycle hooks');
|
|
@@ -407,46 +265,12 @@ export async function initCommand(args: readonly string[], ctx: CliContext): Pro
|
|
|
407
265
|
write('features/step_definitions/app.steps.ts', STEPS, 'its step');
|
|
408
266
|
|
|
409
267
|
// 5b. tsconfig.json (issue #21): step files import each other with .ts (Node's type stripping needs it).
|
|
410
|
-
|
|
411
|
-
const tsconfigText = ctx.readFile(tsconfigFile);
|
|
412
|
-
if (tsconfigText !== null) {
|
|
413
|
-
let tsconfig: { compilerOptions?: Record<string, unknown> } | null;
|
|
414
|
-
try {
|
|
415
|
-
tsconfig = JSON.parse(tsconfigText) as { compilerOptions?: Record<string, unknown> };
|
|
416
|
-
} catch {
|
|
417
|
-
tsconfig = null; // comments or trailing commas: leave the file to the user
|
|
418
|
-
}
|
|
419
|
-
if (tsconfig?.compilerOptions?.['allowImportingTsExtensions'] === true) {
|
|
420
|
-
steps.push({ status: 'skipped', what: 'tsconfig.json', note: 'already allows .ts imports' });
|
|
421
|
-
} else if (tsconfig === null || typeof tsconfig !== 'object' || Array.isArray(tsconfig)) {
|
|
422
|
-
steps.push({ status: 'todo', what: 'tsconfig.json', note: 'add "allowImportingTsExtensions": true to compilerOptions (step files import each other with .ts)' });
|
|
423
|
-
} else {
|
|
424
|
-
tsconfig.compilerOptions = { ...tsconfig.compilerOptions, allowImportingTsExtensions: true };
|
|
425
|
-
writeJson(ctx, tsconfigFile, tsconfig);
|
|
426
|
-
steps.push({ status: 'updated', what: 'tsconfig.json', note: 'allowImportingTsExtensions: step files import each other with .ts' });
|
|
427
|
-
}
|
|
428
|
-
}
|
|
268
|
+
ensureTsconfig(log);
|
|
429
269
|
|
|
430
270
|
// 6. Scripts.
|
|
431
|
-
|
|
432
|
-
const wanted: Record<string, string> = {
|
|
433
|
-
'e2e:start': 'EXPO_PUBLIC_QUIESCO=1 expo start',
|
|
434
|
-
...(platforms.includes('web') ? { 'e2e:web': 'EXPO_PUBLIC_QUIESCO=1 expo export --platform web && quiesco test --platform web' } : {}),
|
|
435
|
-
...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android': 'quiesco test --platform android' } : {}),
|
|
436
|
-
...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios': 'quiesco test --platform ios' } : {}),
|
|
437
|
-
};
|
|
438
|
-
const added = Object.keys(wanted).filter((k) => scripts[k] === undefined);
|
|
439
|
-
if (added.length > 0) {
|
|
440
|
-
for (const k of added) scripts[k] = wanted[k] as string;
|
|
441
|
-
const now = readJson<PackageJson>(ctx, pkgFile) as PackageJson;
|
|
442
|
-
now.scripts = scripts;
|
|
443
|
-
writeJson(ctx, pkgFile, now);
|
|
444
|
-
steps.push({ status: 'updated', what: 'package.json', note: `scripts: ${added.join(', ')}` });
|
|
445
|
-
}
|
|
271
|
+
ensureScripts(log, platforms);
|
|
446
272
|
|
|
447
|
-
|
|
448
|
-
ctx.out('');
|
|
449
|
-
for (const s of steps) ctx.out(`${icon[s.status]} ${s.what}${s.note !== undefined ? ` — ${s.note}` : ''}`);
|
|
273
|
+
printSteps(ctx, steps);
|
|
450
274
|
ctx.out('');
|
|
451
275
|
ctx.out('Next:');
|
|
452
276
|
const next: string[] = [];
|