agentic-mobile-kit 0.5.4 → 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/README.md +1 -0
- package/lib/doctor.js +26 -5
- package/lib/init.js +166 -11
- package/package.json +1 -1
- package/stacks/react-native/template/.agents/skills/m-release/SKILL.md +2 -1
- package/stacks/react-native/template/.githooks/pre-commit +7 -2
- package/stacks/react-native/template/.github/workflows/ios.yml +1 -2
- package/stacks/react-native/template/AGENTS.md +3 -3
- package/stacks/react-native/template/codemagic.yaml +1 -1
- package/stacks/react-native/template/docs/ai/known-issues.md +12 -2
- package/stacks/react-native/template/docs/ai/react-native.md +5 -4
- package/stacks/react-native/template/scripts/ai/android-flavors.js +41 -0
- package/stacks/react-native/template/scripts/ai/case-check.js +35 -0
- package/stacks/react-native/template/scripts/ai/install-deps.sh +4 -1
- package/stacks/react-native/template/scripts/ai/ios-build.sh +10 -3
- package/stacks/react-native/template/scripts/ai/pod-install.sh +12 -0
- package/stacks/react-native/template/scripts/ai/release-build.sh +28 -8
- package/stacks/react-native/template/scripts/ai/release-check.js +30 -4
- package/stacks/react-native/template/scripts/ai/verify.sh +55 -15
- package/stacks/react-native/template/specs/_templates/flow.yaml +2 -0
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Both need a clean working tree and leave the result for you to review with `git
|
|
|
58
58
|
## Requirements
|
|
59
59
|
|
|
60
60
|
- Git and Node.js 20 or later, on macOS, Windows or Linux. The kit's tests run on all three for every change.
|
|
61
|
+
- The app at the root of its git repository.
|
|
61
62
|
- Android work needs the Android SDK and Java. iOS work needs a Mac with Xcode and CocoaPods. `doctor` checks the rest.
|
|
62
63
|
- On Windows, turn on Developer Mode (Settings > System > For developers) and run `git config --global core.symlinks true`. Then `init` can link the Claude Code skills folder, and clones keep the link.
|
|
63
64
|
|
package/lib/doctor.js
CHANGED
|
@@ -4,7 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const { spawnSync } = require('child_process');
|
|
7
|
-
const { tool } = require('./init');
|
|
7
|
+
const { tool, hookManager, hooksWired } = require('./init');
|
|
8
8
|
|
|
9
9
|
const RULESYNC = 'rulesync@27.0.0';
|
|
10
10
|
|
|
@@ -40,10 +40,31 @@ function projectChecks(cwd, opts) {
|
|
|
40
40
|
? ok('AGENTS.md size', `${lines} lines`)
|
|
41
41
|
: warn(`AGENTS.md is ${lines} lines / ${bytes} bytes`, 'keep it under 150 lines and 8 KB; tools truncate or ignore long files. Move details to docs/ai/'));
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
let pkg = {};
|
|
44
|
+
try { pkg = JSON.parse(read(cwd, 'package.json') || '{}'); } catch {}
|
|
45
|
+
const manager = hookManager(cwd, pkg);
|
|
46
|
+
if (!manager) {
|
|
47
|
+
const hooksPath = run('git', ['config', 'core.hooksPath'], { cwd });
|
|
48
|
+
out.push(hooksPath === '.githooks'
|
|
49
|
+
? ok('Git hooks active')
|
|
50
|
+
: fail('Git hooks not active on this clone', 'run: git config core.hooksPath .githooks (your package manager\'s install does this too)'));
|
|
51
|
+
} else if (manager.manual) {
|
|
52
|
+
out.push(warn(`Git hooks run from ${manager.name}, without the kit's checks`, 'add "sh .githooks/pre-commit" and "sh .githooks/pre-push" to those hooks'));
|
|
53
|
+
} else if (!hooksWired(cwd, manager)) {
|
|
54
|
+
out.push(fail(`The kit's checks aren't in your ${manager.name} hooks`, 'run: npx agentic-mobile-kit sync'));
|
|
55
|
+
} else {
|
|
56
|
+
// what git runs: core.hooksPath, or .git/hooks
|
|
57
|
+
const dir = run('git', ['rev-parse', '--git-path', 'hooks'], { cwd });
|
|
58
|
+
out.push(dir && fs.existsSync(path.join(cwd, dir, 'pre-commit'))
|
|
59
|
+
? ok('Git hooks active', `the kit's checks run from ${manager.name}`)
|
|
60
|
+
: fail(`${manager.name} isn't set up on this clone, so no git hooks run`, 'run your package manager\'s install'));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (fs.existsSync(path.join(cwd, 'scripts/ai/case-check.js'))) {
|
|
64
|
+
const r = spawnSync(process.execPath, ['scripts/ai/case-check.js'], { cwd, encoding: 'utf8' });
|
|
65
|
+
const lines = (r.stderr || '').trim().split('\n');
|
|
66
|
+
out.push(r.status === 0 ? ok('File names match git') : fail(`Renamed only in letter case, and git missed it:${lines.slice(1, -1).join(',')}`, lines.pop()));
|
|
67
|
+
}
|
|
47
68
|
|
|
48
69
|
const tracked = (run('git', ['ls-files'], { cwd }) || '').split('\n').filter(f => /(^|\/)\.env(\.(?!example$)[\w.-]+)?$/.test(f));
|
|
49
70
|
out.push(tracked.length ? fail(`Secret files tracked by git: ${tracked.join(', ')}`, 'git rm --cached them, rotate the secrets, keep them out of the repo') : ok('No .env files in git'));
|
package/lib/init.js
CHANGED
|
@@ -119,12 +119,23 @@ function fillPlaceholders(text, values) {
|
|
|
119
119
|
return text.replace(/\{\{(\w+)\}\}/g, (m, k) => (k in values ? values[k] : m));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// React Native 0.82 and later run only the New Architecture. Before that, android/gradle.properties chooses:
|
|
123
|
+
// the New Architecture was opt-in before 0.76 and the default from 0.76.
|
|
124
|
+
function architecture(cwd, rnVersion) {
|
|
125
|
+
const [major, minor] = String(rnVersion).split('.').map(Number);
|
|
126
|
+
if (!(major === 0 && minor < 82)) return 'New Architecture';
|
|
127
|
+
const flag = ((readIf(path.join(cwd, 'android', 'gradle.properties')) || '').match(/^\s*newArchEnabled\s*=\s*(true|false)/m) || [])[1];
|
|
128
|
+
return (flag ? flag === 'true' : minor >= 76) ? 'New Architecture' : 'Old Architecture: newArchEnabled=false';
|
|
129
|
+
}
|
|
130
|
+
|
|
122
131
|
function projectValues(cwd, pkg, deps, pm, ci) {
|
|
132
|
+
const rn = installedVersion(cwd, 'react-native', deps['react-native']);
|
|
123
133
|
return {
|
|
124
134
|
KIT_VERSION,
|
|
125
135
|
KIT_CI: ci.join(',') || 'none',
|
|
126
136
|
APP_NAME: pkg.name || path.basename(cwd),
|
|
127
|
-
RN_VERSION:
|
|
137
|
+
RN_VERSION: rn,
|
|
138
|
+
RN_ARCH: architecture(cwd, rn),
|
|
128
139
|
REACT_VERSION: installedVersion(cwd, 'react', deps.react),
|
|
129
140
|
TS_VERSION: installedVersion(cwd, 'typescript', deps.typescript),
|
|
130
141
|
NODE_VERSION: (pkg.engines && pkg.engines.node) || `${process.versions.node.split('.')[0]}`,
|
|
@@ -222,6 +233,136 @@ function merge3(current, base, kitNew, from) {
|
|
|
222
233
|
return { text: r.stdout, conflicts: r.status };
|
|
223
234
|
}
|
|
224
235
|
|
|
236
|
+
// Git hook managers a project may already use. The kit's hooks then run from theirs and core.hooksPath stays theirs:
|
|
237
|
+
// two tools setting it undo each other on every install (husky's prepare script runs after the kit's postinstall).
|
|
238
|
+
const KIT_HOOKS = ['pre-commit', 'pre-push'];
|
|
239
|
+
const MARK = 'agentic-mobile-kit';
|
|
240
|
+
const hookCall = h => `sh .githooks/${h}${h === 'pre-push' ? ' "$@"' : ''} || exit 1 # ${MARK}`;
|
|
241
|
+
const localHooksPath = cwd => {
|
|
242
|
+
let v = '';
|
|
243
|
+
try { v = git(cwd, 'config', '--local', 'core.hooksPath'); } catch {}
|
|
244
|
+
return v && path.posix.normalize(v.replace(/\\/g, '/')).replace(/\/+$/, '');
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function hookManager(cwd, pkg) {
|
|
248
|
+
const local = localHooksPath(cwd);
|
|
249
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
250
|
+
if ((deps.husky && fs.existsSync(path.join(cwd, '.husky'))) || local.startsWith('.husky')) return { name: 'husky', dir: '.husky' };
|
|
251
|
+
if (pkg.husky && pkg.husky.hooks) return { name: 'husky', json: pkg.husky.hooks }; // husky 4
|
|
252
|
+
if (pkg['simple-git-hooks']) return { name: 'simple-git-hooks', json: pkg['simple-git-hooks'] };
|
|
253
|
+
const yaml = ['lefthook.yml', '.lefthook.yml', 'lefthook.yaml', '.lefthook.yaml'].find(f => fs.existsSync(path.join(cwd, f)));
|
|
254
|
+
if (yaml) return { name: 'lefthook', yaml };
|
|
255
|
+
// the team's own hooks folder; one outside the repo isn't the kit's to edit
|
|
256
|
+
if (local && local !== '.githooks') return path.isAbsolute(local) || local.startsWith('..') ? { name: local, manual: true } : { name: local, dir: local };
|
|
257
|
+
// hooks another tool installed into .git/hooks, which core.hooksPath would switch off
|
|
258
|
+
let gitHooks = '';
|
|
259
|
+
try { gitHooks = git(cwd, 'rev-parse', '--git-path', 'hooks'); } catch {}
|
|
260
|
+
if (!local && gitHooks && KIT_HOOKS.some(h => fs.existsSync(path.join(cwd, gitHooks, h)))) return { name: '.git/hooks', manual: true };
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const hookFile = (m, h) => (m.dir ? `${m.dir}/${h}` : m.yaml);
|
|
265
|
+
const hooksWired = (cwd, m) => KIT_HOOKS.every(h => (m.json ? m.json[h] || '' : readIf(path.join(cwd, hookFile(m, h))) || '').includes(`.githooks/${h}`));
|
|
266
|
+
|
|
267
|
+
// after the shebang, comments and husky's own setup line: a command after the team's `exit` would never run
|
|
268
|
+
function insertCall(text, line) {
|
|
269
|
+
const lines = text.replace(/\n+$/, '').split('\n');
|
|
270
|
+
let i = 0;
|
|
271
|
+
while (i < lines.length && /^(#|\s*$|\.\s|source\s)/.test(lines[i])) i++;
|
|
272
|
+
lines.splice(i, 0, line);
|
|
273
|
+
return `${lines.join('\n')}\n`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// adds the kit's command to a lefthook hook (under its commands: or jobs:), or the hook itself; null if it can't tell where
|
|
277
|
+
function lefthookAdd(text, h) {
|
|
278
|
+
const run = `sh .githooks/${h}`;
|
|
279
|
+
const lines = text.replace(/\n+$/, '').split('\n');
|
|
280
|
+
const start = lines.findIndex(l => new RegExp(`^["']?${h}["']?\\s*:`).test(l));
|
|
281
|
+
if (start < 0) return `${lines.join('\n')}\n${h}: # ${MARK}\n commands: # ${MARK}\n ${MARK}:\n run: ${run}\n`;
|
|
282
|
+
if (!/:\s*(#.*)?$/.test(lines[start])) return null; // written inline ({ … }) or with an anchor
|
|
283
|
+
let end = lines.findIndex((l, i) => i > start && /^[^\s#]/.test(l));
|
|
284
|
+
if (end < 0) end = lines.length;
|
|
285
|
+
const at = lines.findIndex((l, i) => i > start && i < end && /^\s+(commands|jobs):\s*(#.*)?$/.test(l));
|
|
286
|
+
if (at < 0) return null;
|
|
287
|
+
const indent = lines[at].match(/^\s*/)[0];
|
|
288
|
+
const next = lines.slice(at + 1, end).find(l => l.trim() && !l.trim().startsWith('#'));
|
|
289
|
+
const nextIndent = next ? next.match(/^\s*/)[0] : '';
|
|
290
|
+
if (/jobs:/.test(lines[at])) {
|
|
291
|
+
// a list: its items may sit at the same indent as "jobs:"
|
|
292
|
+
const item = next && next.trim().startsWith('-') ? nextIndent : `${indent} `;
|
|
293
|
+
lines.splice(at + 1, 0, `${item}- name: ${MARK}`, `${item} run: ${run}`);
|
|
294
|
+
} else {
|
|
295
|
+
const key = nextIndent.length > indent.length ? nextIndent : `${indent} `;
|
|
296
|
+
lines.splice(at + 1, 0, `${key}${MARK}:`, `${key}${key.slice(indent.length)}run: ${run}`);
|
|
297
|
+
}
|
|
298
|
+
return `${lines.join('\n')}\n`;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// runs the kit's hooks from the project's hook manager; true if package.json changed
|
|
302
|
+
function wireHooks(cwd, m, done) {
|
|
303
|
+
if (m.manual) {
|
|
304
|
+
done.warnings.push(`git hooks already run from ${m.name}, so the kit left core.hooksPath alone. To run the kit's checks too, add "sh .githooks/pre-commit" and "sh .githooks/pre-push" to those hooks.`);
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
let pkgChanged = false;
|
|
308
|
+
for (const h of KIT_HOOKS) {
|
|
309
|
+
if (m.json) {
|
|
310
|
+
if ((m.json[h] || '').includes(`.githooks/${h}`)) continue;
|
|
311
|
+
m.json[h] = m.json[h] ? `sh .githooks/${h} && ${m.json[h]}` : `sh .githooks/${h}`;
|
|
312
|
+
pkgChanged = true;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const rel = hookFile(m, h);
|
|
316
|
+
const file = path.join(cwd, rel);
|
|
317
|
+
const text = readIf(file);
|
|
318
|
+
if ((text || '').includes(`.githooks/${h}`)) continue;
|
|
319
|
+
if (m.yaml) {
|
|
320
|
+
const next = lefthookAdd(text, h);
|
|
321
|
+
if (next === null) { done.warnings.push(`couldn't add the kit's ${h} check to ${rel}: add a command there that runs "sh .githooks/${h}"`); continue; }
|
|
322
|
+
fs.writeFileSync(file, next);
|
|
323
|
+
if (!done.merged.includes(rel)) done.merged.push(rel);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
327
|
+
fs.writeFileSync(file, text === null ? `#!/usr/bin/env sh\n${hookCall(h)}\n` : insertCall(text, hookCall(h)));
|
|
328
|
+
// husky 5 to 8 and plain hook folders run the file itself
|
|
329
|
+
fs.chmodSync(file, 0o755);
|
|
330
|
+
if (WIN) git(cwd, 'add', '--chmod=+x', '--', rel);
|
|
331
|
+
(text === null ? done.created : done.merged).push(rel);
|
|
332
|
+
}
|
|
333
|
+
if (pkgChanged && m.name === 'simple-git-hooks') done.warnings.push('run "npx simple-git-hooks" once, so it installs the hooks with the kit\'s checks in them');
|
|
334
|
+
return pkgChanged;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// takes the kit's lines back out of the project's hook manager
|
|
338
|
+
function unwireHooks(cwd, m, report) {
|
|
339
|
+
let pkgChanged = false;
|
|
340
|
+
for (const h of KIT_HOOKS) {
|
|
341
|
+
if (m.json) {
|
|
342
|
+
const before = m.json[h];
|
|
343
|
+
if (before === `sh .githooks/${h}`) delete m.json[h];
|
|
344
|
+
else if (before) m.json[h] = before.replace(`sh .githooks/${h} && `, '');
|
|
345
|
+
if (m.json[h] !== before) { pkgChanged = true; report.removed.push(`package.json ${m.name} ${h} (the kit's command)`); }
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const rel = hookFile(m, h);
|
|
349
|
+
const text = readIf(path.join(cwd, rel));
|
|
350
|
+
if (text === null || !text.includes(MARK) && !text.includes('.githooks/')) continue;
|
|
351
|
+
const rest = text.split('\n').filter(l => !l.includes(MARK) && !l.includes('.githooks/')).join('\n');
|
|
352
|
+
if (/^(#![^\n]*)?\s*$/.test(rest)) fs.unlinkSync(path.join(cwd, rel)); else fs.writeFileSync(path.join(cwd, rel), rest);
|
|
353
|
+
if (!report.removed.some(r => r.startsWith(rel))) report.removed.push(`${rel} (the kit's lines)`);
|
|
354
|
+
}
|
|
355
|
+
return pkgChanged;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// takes the kit's command out of postinstall; true if it was there
|
|
359
|
+
function dropHooksCmd(scripts) {
|
|
360
|
+
const next = scripts.postinstall === HOOKS_CMD ? undefined : (scripts.postinstall || '').replace(` && (${HOOKS_CMD})`, '') || undefined;
|
|
361
|
+
if (next === scripts.postinstall) return false;
|
|
362
|
+
if (next) scripts.postinstall = next; else delete scripts.postinstall;
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
|
|
225
366
|
const SKILL_LINKS = [['.claude/skills', 'claude'], ['.kiro/skills', 'kiro']];
|
|
226
367
|
const kitSkills = template => fs.readdirSync(path.join(template, '.agents', 'skills'), { withFileTypes: true }).filter(e => e.isDirectory()).map(e => e.name);
|
|
227
368
|
|
|
@@ -282,7 +423,12 @@ function finish(cwd, { pkg, deps, tools, template, skipGenerate }) {
|
|
|
282
423
|
// only TypeScript projects get typecheck: tsc fails ("no inputs") in JavaScript apps that merely have typescript installed
|
|
283
424
|
const hasTs = git(cwd, 'ls-files', '*.ts', '*.tsx').split('\n').some(f => f && !f.endsWith('.d.ts'));
|
|
284
425
|
if (!scripts.typecheck && deps.typescript && hasTs) { scripts.typecheck = 'tsc --noEmit'; pkgChanged = true; }
|
|
285
|
-
|
|
426
|
+
const manager = hookManager(cwd, pkg);
|
|
427
|
+
if (manager) {
|
|
428
|
+
// the project's hook manager runs the kit's hooks; drop the postinstall earlier kit versions added, which fought it
|
|
429
|
+
if (dropHooksCmd(scripts)) pkgChanged = true;
|
|
430
|
+
if (wireHooks(cwd, manager, done)) pkgChanged = true;
|
|
431
|
+
} else if (!(scripts.postinstall || '').includes('core.hooksPath')) {
|
|
286
432
|
// parentheses keep the existing script's failure behavior: `a && b || true` would hide a failing `a`
|
|
287
433
|
scripts.postinstall = scripts.postinstall ? `${scripts.postinstall} && (${HOOKS_CMD})` : HOOKS_CMD;
|
|
288
434
|
pkgChanged = true;
|
|
@@ -290,7 +436,13 @@ function finish(cwd, { pkg, deps, tools, template, skipGenerate }) {
|
|
|
290
436
|
if (pkgChanged) { fs.writeFileSync(path.join(cwd, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`); done.merged.push('package.json (scripts)'); }
|
|
291
437
|
|
|
292
438
|
// 5. activate the git hooks now
|
|
293
|
-
git(cwd, 'config', 'core.hooksPath', '.githooks');
|
|
439
|
+
if (!manager) git(cwd, 'config', 'core.hooksPath', '.githooks');
|
|
440
|
+
else if (localHooksPath(cwd) === '.githooks') {
|
|
441
|
+
// an earlier kit version took core.hooksPath over: give it back (husky 9 uses .husky/_, husky 5 to 8 .husky)
|
|
442
|
+
const husky = manager.dir === '.husky' && ['.husky/_/h', '.husky/_/husky.sh'].find(f => fs.existsSync(path.join(cwd, f)));
|
|
443
|
+
if (husky) git(cwd, 'config', 'core.hooksPath', husky.endsWith('/h') ? '.husky/_' : '.husky');
|
|
444
|
+
else git(cwd, 'config', '--unset', 'core.hooksPath');
|
|
445
|
+
}
|
|
294
446
|
// Windows files have no executable bit, and git skips non-executable hooks on Mac and Linux clones:
|
|
295
447
|
// stage the hooks as executable so the commit carries it
|
|
296
448
|
const hooks = ['.githooks/pre-commit', '.githooks/pre-push'].filter(h => fs.existsSync(path.join(cwd, h)));
|
|
@@ -310,6 +462,10 @@ function finish(cwd, { pkg, deps, tools, template, skipGenerate }) {
|
|
|
310
462
|
}
|
|
311
463
|
|
|
312
464
|
function init(cwd, opts = {}) {
|
|
465
|
+
// monorepos: git runs hooks from the repository root, and GitHub reads workflows only there
|
|
466
|
+
let prefix = '';
|
|
467
|
+
try { prefix = git(cwd, 'rev-parse', '--show-prefix').replace(/\/$/, ''); } catch {}
|
|
468
|
+
if (prefix) throw new InitError(`This app is in a subfolder of its git repository (${prefix}), as in a monorepo. The kit doesn't support that yet: git runs hooks from the repository root, and GitHub reads workflows only there.`);
|
|
313
469
|
const { pkg, deps } = checkProject(cwd);
|
|
314
470
|
const pm = detectPm(cwd, opts.pm);
|
|
315
471
|
const tools = opts.tools || TESTED;
|
|
@@ -453,14 +609,13 @@ function uninstall(cwd, opts = {}) {
|
|
|
453
609
|
for (; d && d !== '.'; d = path.dirname(d)) { try { fs.rmdirSync(path.join(cwd, d)); } catch { break; } }
|
|
454
610
|
}
|
|
455
611
|
|
|
456
|
-
// git hooks
|
|
612
|
+
// git hooks: the kit's postinstall, or its lines in the project's hook manager (which would fail once .githooks is gone)
|
|
457
613
|
const scripts = pkg.scripts || {};
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
614
|
+
let pkgChanged = false;
|
|
615
|
+
if (dropHooksCmd(scripts)) { pkgChanged = true; report.removed.push('package.json postinstall (git hooks)'); }
|
|
616
|
+
const manager = hookManager(cwd, pkg);
|
|
617
|
+
if (manager && !manager.manual && unwireHooks(cwd, manager, report)) pkgChanged = true;
|
|
618
|
+
if (pkgChanged) fs.writeFileSync(path.join(cwd, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`);
|
|
464
619
|
try { if (git(cwd, 'config', 'core.hooksPath') === '.githooks') git(cwd, 'config', '--unset', 'core.hooksPath'); } catch {}
|
|
465
620
|
|
|
466
621
|
report.left.push('.gitignore lines for .env files and .ai/ (they keep secrets and local evidence out of git)');
|
|
@@ -508,4 +663,4 @@ function printUninstall({ report }, log = console.log) {
|
|
|
508
663
|
log('\nReview it with "git status" and "git diff", then commit. Undo it with git if you change your mind.');
|
|
509
664
|
}
|
|
510
665
|
|
|
511
|
-
module.exports = { init, sync, uninstall, printSummary, printSync, printUninstall, InitError, TOOLS, CI, KIT_VERSION, tool };
|
|
666
|
+
module.exports = { init, sync, uninstall, printSummary, printSync, printUninstall, InitError, TOOLS, CI, KIT_VERSION, tool, hookManager, hooksWired };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-mobile-kit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "One setup for AI-assisted development of bare React Native apps: shared rules and workflows for Claude Code, Codex and Antigravity, git hooks, device checks with screenshots, and release tooling for the App Store and Google Play.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "prakashpro1",
|
|
@@ -22,10 +22,11 @@ Input: $ARGUMENTS (the new version such as 1.4.0, or patch, minor or major; whic
|
|
|
22
22
|
|
|
23
23
|
Show all three files to the user and wait for their approval.
|
|
24
24
|
5. **Version and build numbers:** `sh scripts/ai/set-version.sh <version>` sets the iOS and Android version names. If the script stops because the project ships several apps, ask the user which version each app gets, and set them after they confirm.
|
|
25
|
-
- When `
|
|
25
|
+
- When CI or fastlane sets the build numbers at build time (`release-check.js` in step 6 says so), leave them alone.
|
|
26
26
|
- Otherwise every store upload needs a higher build number. Ask before changing native files. Then raise Android's `versionCode` in `android/app/build.gradle`, and set iOS with `cd ios && agvtool new-version -all <number>`. Never edit `project.pbxproj` by hand. iOS may keep its build number when the version name changes, if that's how the team works.
|
|
27
27
|
6. **Release check:** `node scripts/ai/release-check.js`. Show the output. Fix each ✗, asking first when the fix touches native config. List each ! for the user to decide.
|
|
28
28
|
7. **Release PR:** commit as `chore(release): <version>` (so the next changelog leaves it out), with `Assisted-by: <tool>/<model>`. Ask before pushing. Open a PR titled `Release <version>` with the changelog and the release-check output.
|
|
29
29
|
8. **Tag and build, after the merge.** Once the PR is merged, ask the user before tagging. Then run `git switch main && git pull && git tag v<version> && git push origin v<version>`.
|
|
30
30
|
- With Codemagic (`codemagic.yaml`; see `docs/ai/codemagic.md`), the tag starts the signed builds.
|
|
31
|
+
- With the team's own release tooling (fastlane lanes in `fastlane/`, `ios/fastlane/` or `android/fastlane/`, or release scripts in `package.json`), the user runs the lane or script that builds and uploads the release, instead of `release-build.sh`. Tell them which one; if it isn't clear, ask.
|
|
31
32
|
- Without CI, the user builds signed apps on their Mac, because signing keys stay with people. Tell them to run `sh scripts/ai/release-build.sh android [flavor]` and `sh scripts/ai/release-build.sh ios [scheme]`, and to upload the results from `.ai/release/` (Play Console, and Xcode's Organizer or Transporter). Never run these yourself or ask for the keys.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# agentic-mobile-kit pre-commit: runs for every commit, whichever person or AI tool makes it.
|
|
3
|
-
# Blocks secrets
|
|
3
|
+
# Blocks secrets, broken Xcode project files and case-only renames git missed, and lints the staged JS/TS files.
|
|
4
4
|
set -eu
|
|
5
5
|
|
|
6
6
|
staged=$(git diff --cached --name-only --diff-filter=ACMR)
|
|
@@ -47,7 +47,12 @@ if [ -n "$specs" ] && [ -f scripts/ai/spec.js ]; then
|
|
|
47
47
|
node scripts/ai/spec.js check --skip-drafts $specs || fail "fix the spec format above (format: specs/current/README.md)"
|
|
48
48
|
fi
|
|
49
49
|
|
|
50
|
-
# 6.
|
|
50
|
+
# 6. files renamed only in letter case on macOS or Windows: git still has the old name, so other machines can't find them
|
|
51
|
+
if [ -f scripts/ai/case-check.js ]; then
|
|
52
|
+
node scripts/ai/case-check.js || fail "rename them through git as shown above"
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# 7. warn about large commits (the PR size check in CI is the hard limit)
|
|
51
56
|
lines=$(git diff --cached --numstat -- . ':(exclude)*.lock' ':(exclude)package-lock.json' ':(exclude)pnpm-lock.yaml' ':(exclude)*.snap' |
|
|
52
57
|
awk '{ s += $1 + $2 } END { print s + 0 }')
|
|
53
58
|
[ "$lines" -le 400 ] || echo "pre-commit: warning: $lines changed lines; consider smaller commits" >&2
|
|
@@ -37,7 +37,6 @@ jobs:
|
|
|
37
37
|
if: hashFiles('ios/Podfile') == ''
|
|
38
38
|
run: npx expo prebuild --platform ios --no-install
|
|
39
39
|
- name: Install pods
|
|
40
|
-
|
|
41
|
-
run: pod install
|
|
40
|
+
run: sh scripts/ai/pod-install.sh
|
|
42
41
|
- name: Build for the simulator (no signing)
|
|
43
42
|
run: sh scripts/ai/ios-build.sh
|
|
@@ -7,7 +7,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
|
|
|
7
7
|
|
|
8
8
|
## Project
|
|
9
9
|
|
|
10
|
-
- Bare React Native {{RN_VERSION}} (
|
|
10
|
+
- Bare React Native {{RN_VERSION}} ({{RN_ARCH}}), React {{REACT_VERSION}}, TypeScript {{TS_VERSION}}, Node {{NODE_VERSION}}. Package manager: {{PM}}.
|
|
11
11
|
- What the app does: `docs/ai/product.md`, and requirement by requirement, as it works now: `specs/current/`. Stack and services: `docs/ai/tech.md`. Folders and layers: `docs/ai/structure.md`. Code style: `docs/ai/conventions.md`.
|
|
12
12
|
|
|
13
13
|
## Commands
|
|
@@ -16,10 +16,10 @@ This project may also use other AI workflow frameworks (for example Superpowers,
|
|
|
16
16
|
|---|---|
|
|
17
17
|
| Install dependencies | `sh scripts/ai/install-deps.sh` |
|
|
18
18
|
| Lint, typecheck, test | `{{PM_RUN}} lint`, `{{PM_RUN}} typecheck`, `{{PM_RUN}} test` |
|
|
19
|
-
| iOS pods (after native dependency changes) | `
|
|
19
|
+
| iOS pods (after native dependency changes) | `sh scripts/ai/pod-install.sh` |
|
|
20
20
|
| iOS build (simulator, no signing) | `sh scripts/ai/ios-build.sh` |
|
|
21
21
|
| Android build | `cd android && ./gradlew assembleDebug` |
|
|
22
|
-
| Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/ai/verify.sh all --spec <id>` |
|
|
22
|
+
| Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/ai/verify.sh all --spec <id>`; with product flavors it checks the first unless `--flavor <name>`; another iOS scheme: `--scheme <name>` |
|
|
23
23
|
| Specs: progress, format check, fold a finished feature into the living spec | `node scripts/ai/spec.js status`, `node scripts/ai/spec.js check`, `node scripts/ai/spec.js merge <id>` |
|
|
24
24
|
| Check a release before tagging it (versions, permission texts, debug leftovers) | `node scripts/ai/release-check.js` |
|
|
25
25
|
| Signed release builds (a person runs them: they use the signing keys) | `sh scripts/ai/release-build.sh android [flavor]`, `sh scripts/ai/release-build.sh ios [scheme]` |
|
|
@@ -66,7 +66,7 @@ workflows:
|
|
|
66
66
|
- name: Release check
|
|
67
67
|
script: node scripts/ai/release-check.js
|
|
68
68
|
- name: Install dependencies
|
|
69
|
-
script: sh scripts/ai/install-deps.sh &&
|
|
69
|
+
script: sh scripts/ai/install-deps.sh && sh scripts/ai/pod-install.sh
|
|
70
70
|
- name: Store release notes
|
|
71
71
|
script: |
|
|
72
72
|
notes="release-notes/${CM_TAG#v}/app-store.txt"
|
|
@@ -13,5 +13,15 @@ Recurring errors and their fixes. Check here before debugging a build error. Rem
|
|
|
13
13
|
|
|
14
14
|
### iOS build fails right after a native dependency was added or removed
|
|
15
15
|
- **Cause:** `ios/Pods` is out of date.
|
|
16
|
-
- **Fix:** `
|
|
17
|
-
- **Prevention:** run `pod
|
|
16
|
+
- **Fix:** `sh scripts/ai/pod-install.sh`, then rebuild.
|
|
17
|
+
- **Prevention:** run `sh scripts/ai/pod-install.sh` in the same change that edits `package.json`.
|
|
18
|
+
|
|
19
|
+
### `./gradlew` fails with "no main manifest attribute, in …/gradle-wrapper.jar"
|
|
20
|
+
- **Cause:** a React Native upgrade updated `android/gradlew` (which now runs `java -jar gradle-wrapper.jar`) but not `android/gradle/wrapper/gradle-wrapper.jar`. The upgrade diff doesn't carry binary files.
|
|
21
|
+
- **Fix:** copy `android/gradle/wrapper/gradle-wrapper.jar` from the React Native template of your new version (or run `gradle wrapper` with the version in `gradle-wrapper.properties`).
|
|
22
|
+
- **Prevention:** when upgrading, also copy the binary files the upgrade helper lists.
|
|
23
|
+
|
|
24
|
+
### "Unable to resolve module ./Name" in CI or a fresh clone, while it builds on your machine
|
|
25
|
+
- **Cause:** a file was renamed only in letter case (for example `storage.ts` to `Storage.ts`). macOS and Windows treat both names as the same file, so git kept the old name; Metro and Linux CI machines don't.
|
|
26
|
+
- **Fix:** rename it through git in two steps, then commit: `git mv src/utils/storage.ts src/utils/tmp.ts && git mv src/utils/tmp.ts src/utils/Storage.ts`.
|
|
27
|
+
- **Prevention:** rename files with `git mv`, not only in Finder or the editor.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
# React Native rules (bare
|
|
1
|
+
# React Native rules (bare)
|
|
2
2
|
|
|
3
3
|
Rules for things AI agents commonly get wrong in current React Native. Each one comes from a documented platform change.
|
|
4
4
|
|
|
5
5
|
## Architecture
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- `AGENTS.md` says which architecture this app runs.
|
|
8
|
+
- New Architecture (the only one since React Native 0.82): write native modules as Turbo Modules and native views as Fabric components, with TypeScript codegen specs. Don't use the old bridge APIs (`NativeModules`, `requireNativeComponent`) in new code. From 0.82, `newArchEnabled=false` is ignored.
|
|
9
|
+
- Old Architecture (`newArchEnabled=false`): before adding a library, check that it still supports the Old Architecture; Reanimated 4 and FlashList 2, for example, don't. Moving to the New Architecture is a task of its own, needed before React Native 0.82; don't mix it into other work.
|
|
9
10
|
|
|
10
11
|
## Screens and layout
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ Rules for things AI agents commonly get wrong in current React Native. Each one
|
|
|
17
18
|
|
|
18
19
|
## Native changes
|
|
19
20
|
|
|
20
|
-
- After adding or removing a native dependency: `
|
|
21
|
+
- After adding or removing a native dependency: `sh scripts/ai/pod-install.sh`, then rebuild both apps. Restart Metro with `--reset-cache` if the bundle looks stale.
|
|
21
22
|
- Don't hand-edit `project.pbxproj`. Let CocoaPods or Xcode change it.
|
|
22
23
|
- Don't bump the Android Gradle Plugin, Gradle, Kotlin or the iOS deployment target one by one. Upgrade React Native as a whole with the `upgrading-react-native` skill and the React Native Upgrade Helper.
|
|
23
24
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Lists the Android app's product flavors, one per line, from android/app/build.gradle (or .kts).
|
|
3
|
+
// No output: the app has no flavors. Exit 2: it has several flavor dimensions, so a build variant
|
|
4
|
+
// has to be named in full (for example devFree).
|
|
5
|
+
'use strict';
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
|
|
8
|
+
const file = ['android/app/build.gradle', 'android/app/build.gradle.kts'].find(f => fs.existsSync(f));
|
|
9
|
+
const text = (file ? fs.readFileSync(file, 'utf8') : '').replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
|
|
10
|
+
|
|
11
|
+
// the body of `name { … }`, found by matching braces (Gradle blocks nest)
|
|
12
|
+
function block(t, name) {
|
|
13
|
+
const m = new RegExp(`(^|\\W)${name}\\s*\\{`).exec(t);
|
|
14
|
+
if (!m) return null;
|
|
15
|
+
let depth = 0;
|
|
16
|
+
for (let i = m.index + m[0].length - 1; i < t.length; i++) {
|
|
17
|
+
if (t[i] === '{') depth++;
|
|
18
|
+
else if (t[i] === '}' && --depth === 0) return t.slice(m.index + m[0].length, i);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const body = block(text, 'productFlavors');
|
|
24
|
+
if (body === null) process.exit(0);
|
|
25
|
+
|
|
26
|
+
const dimensions = (text.match(/flavorDimensions[^\n]*/g) || []).join(' ').match(/["'][^"']+["']/g) || [];
|
|
27
|
+
if (dimensions.length > 1) {
|
|
28
|
+
console.error(`several flavor dimensions (${dimensions.join(', ')}): name the build variant in full, for example devFree`);
|
|
29
|
+
process.exit(2);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// the blocks directly inside: `dev {` (Groovy) or `create("dev") {` (Kotlin)
|
|
33
|
+
const names = [];
|
|
34
|
+
let depth = 0;
|
|
35
|
+
const token = /(?:create|register|maybeCreate)\(\s*["']([\w-]+)["']\s*\)\s*\{|([A-Za-z_]\w*)\s*\{|\{|\}/g;
|
|
36
|
+
for (let m; (m = token.exec(body));) {
|
|
37
|
+
if (m[0] === '}') { depth--; continue; }
|
|
38
|
+
if (depth === 0 && (m[1] || m[2])) names.push(m[1] || m[2]);
|
|
39
|
+
depth++;
|
|
40
|
+
}
|
|
41
|
+
if (names.length) console.log(names.join('\n'));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Finds files and folders that git tracks under a name differing from the disk only in letter case.
|
|
3
|
+
// macOS and Windows treat both names as one file, so a rename such as storage.ts to Storage.ts never reaches git:
|
|
4
|
+
// the app builds on that machine and fails in CI and on every fresh clone. Exits 1 when it finds any.
|
|
5
|
+
'use strict';
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { execFileSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const tracked = execFileSync('git', ['ls-files', '-z'], { encoding: 'utf8', maxBuffer: 1 << 30 }).split('\0').filter(Boolean);
|
|
10
|
+
const listings = new Map();
|
|
11
|
+
const names = dir => {
|
|
12
|
+
if (!listings.has(dir)) { try { listings.set(dir, new Set(fs.readdirSync(dir || '.'))); } catch { listings.set(dir, null); } }
|
|
13
|
+
return listings.get(dir);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const wrong = new Map(); // git's path -> the path on disk
|
|
17
|
+
for (const file of tracked) {
|
|
18
|
+
const parts = file.split('/');
|
|
19
|
+
for (let i = 0; i < parts.length; i++) {
|
|
20
|
+
const dir = parts.slice(0, i).join('/');
|
|
21
|
+
const here = names(dir);
|
|
22
|
+
if (here && here.has(parts[i])) continue;
|
|
23
|
+
const disk = here && [...here].find(n => n.toLowerCase() === parts[i].toLowerCase());
|
|
24
|
+
if (disk) wrong.set(parts.slice(0, i + 1).join('/'), [dir, disk].filter(Boolean).join('/'));
|
|
25
|
+
break; // deleted, or reported: nothing to check below it
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (wrong.size) {
|
|
30
|
+
console.error('Git has these under a different letter case than the disk:');
|
|
31
|
+
for (const [inGit, onDisk] of wrong) console.error(` ${inGit} (on disk: ${onDisk})`);
|
|
32
|
+
const [inGit, onDisk] = wrong.entries().next().value;
|
|
33
|
+
console.error(`Rename each through git in two steps, for example: git mv "${inGit}" "${inGit}.tmp" && git mv "${inGit}.tmp" "${onDisk}"`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
@@ -10,5 +10,8 @@ elif [ -f pnpm-lock.yaml ]; then
|
|
|
10
10
|
elif [ -f bun.lock ] || [ -f bun.lockb ]; then
|
|
11
11
|
bun install --frozen-lockfile # ponytail: CI needs a setup-bun step for this branch
|
|
12
12
|
else
|
|
13
|
-
npm ci
|
|
13
|
+
npm ci || {
|
|
14
|
+
echo "install-deps: npm ci failed. If it's a peer-dependency conflict (ERESOLVE) and your team installs with --legacy-peer-deps, commit legacy-peer-deps=true in .npmrc so every install, and CI, does the same." >&2
|
|
15
|
+
exit 1
|
|
16
|
+
}
|
|
14
17
|
fi
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# Builds the iOS app for the simulator without code signing (CI and local checks).
|
|
3
|
-
# CONFIGURATION=Release builds a self-contained app (JS bundled; no Metro needed)
|
|
3
|
+
# CONFIGURATION=Release builds a self-contained app (JS bundled; no Metro needed), with the configuration the scheme
|
|
4
|
+
# archives with: apps with one per environment (for example "Release Staging") get theirs.
|
|
5
|
+
# AMK_IOS_SCHEME picks the scheme (default: the one named like the workspace).
|
|
4
6
|
# Output goes to ios/DerivedData: ios/build holds React Native codegen files from pod install.
|
|
5
7
|
set -eu
|
|
6
8
|
config=${CONFIGURATION:-Debug}
|
|
7
9
|
workspace=$(ls -d ios/*.xcworkspace 2>/dev/null | head -n 1)
|
|
8
|
-
[ -n "$workspace" ] || { echo "No ios/*.xcworkspace found. Run pod
|
|
9
|
-
scheme=$(basename "$workspace" .xcworkspace)
|
|
10
|
+
[ -n "$workspace" ] || { echo "No ios/*.xcworkspace found. Run sh scripts/ai/pod-install.sh first."; exit 1; }
|
|
11
|
+
scheme=${AMK_IOS_SCHEME:-$(basename "$workspace" .xcworkspace)}
|
|
12
|
+
if [ "$config" = Release ]; then
|
|
13
|
+
file=$(ls ios/*.xcodeproj/xcshareddata/xcschemes/"$scheme".xcscheme ios/*.xcworkspace/xcshareddata/xcschemes/"$scheme".xcscheme 2> /dev/null | head -n 1)
|
|
14
|
+
[ -z "$file" ] || config=$(awk '/<ArchiveAction/ { a = 1 } a && /buildConfiguration/ { split($0, q, "\""); print q[2]; exit }' "$file")
|
|
15
|
+
[ -n "$config" ] || config=Release
|
|
16
|
+
fi
|
|
10
17
|
|
|
11
18
|
xcodebuild -workspace "$workspace" -scheme "$scheme" -configuration "$config" \
|
|
12
19
|
-sdk iphonesimulator -destination 'generic/platform=iOS Simulator' \
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Installs the iOS pods. With a Gemfile (React Native's template has one), it uses the CocoaPods version pinned there,
|
|
3
|
+
# so Podfile.lock doesn't change just because machines have different CocoaPods versions.
|
|
4
|
+
# Usage: sh scripts/ai/pod-install.sh [pod install options]
|
|
5
|
+
set -eu
|
|
6
|
+
cd ios
|
|
7
|
+
if [ -f ../Gemfile ] && command -v bundle > /dev/null && bundle check > /dev/null 2>&1; then
|
|
8
|
+
bundle exec pod install "$@"
|
|
9
|
+
else
|
|
10
|
+
[ ! -f ../Gemfile ] || echo "pod-install: the Gemfile's gems aren't installed (run: bundle install), so this uses the CocoaPods on PATH" >&2
|
|
11
|
+
pod install "$@"
|
|
12
|
+
fi
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
# A person runs it, because it uses the signing keys, which agents must never handle.
|
|
4
4
|
#
|
|
5
5
|
# sh scripts/ai/release-build.sh android [flavor] signed app bundle (.aab) for Google Play
|
|
6
|
-
# sh scripts/ai/release-build.sh ios [scheme] signed .ipa for App Store Connect
|
|
6
|
+
# sh scripts/ai/release-build.sh ios [scheme] signed .ipa for App Store Connect, or as ios/ExportOptions.plist says
|
|
7
|
+
# Defaults: AMK_ANDROID_FLAVOR and AMK_IOS_SCHEME. An app with product flavors must name the one to build.
|
|
7
8
|
#
|
|
8
9
|
# Android signs with your upload key. Set its path in your shell, never in the repo:
|
|
9
10
|
# export AMK_UPLOAD_KEYSTORE=~/keys/myapp-upload.jks AMK_UPLOAD_KEY_ALIAS=upload
|
|
10
11
|
# The passwords are asked for, unless AMK_UPLOAD_STORE_PASSWORD and AMK_UPLOAD_KEY_PASSWORD are set.
|
|
11
12
|
# Without AMK_UPLOAD_KEYSTORE it uses the app's own signing setup, and stops if that's the debug key.
|
|
12
|
-
# iOS
|
|
13
|
+
# iOS archives with the scheme's archive configuration and exports with the project's ios/ExportOptions.plist
|
|
14
|
+
# (or the one AMK_IOS_EXPORT_OPTIONS names): manual signing, ad hoc or enterprise. Without one, it exports for
|
|
15
|
+
# App Store Connect with automatic signing, using the Apple account in Xcode (Settings > Accounts); Xcode may
|
|
13
16
|
# create a distribution certificate or profile in that team if one is missing.
|
|
14
17
|
# Version and build numbers come from the repo, so set them first (the m-release skill does).
|
|
15
18
|
# Output: .ai/release/
|
|
@@ -29,6 +32,17 @@ secret() {
|
|
|
29
32
|
|
|
30
33
|
case "$platform" in
|
|
31
34
|
android)
|
|
35
|
+
target=${target:-${AMK_ANDROID_FLAVOR:-}}
|
|
36
|
+
if [ -z "$target" ]; then
|
|
37
|
+
code=0
|
|
38
|
+
flavors=$(node scripts/ai/android-flavors.js) || code=$?
|
|
39
|
+
case $code in
|
|
40
|
+
0) ;;
|
|
41
|
+
2) echo "This app has several flavor dimensions: name the variant, for example: sh scripts/ai/release-build.sh android devFree" >&2; exit 1 ;;
|
|
42
|
+
*) echo "Couldn't read the product flavors from build.gradle (see the error above)." >&2; exit 1 ;;
|
|
43
|
+
esac
|
|
44
|
+
[ -z "$flavors" ] || { echo "This app has product flavors ($(echo $flavors)). Name the one to build, for example: sh scripts/ai/release-build.sh android $(echo "$flavors" | head -n 1)" >&2; exit 1; }
|
|
45
|
+
fi
|
|
32
46
|
flavor=$(printf %s "$target" | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }')
|
|
33
47
|
if [ -n "${AMK_UPLOAD_KEYSTORE:-}" ]; then
|
|
34
48
|
secret AMK_UPLOAD_STORE_PASSWORD 'Keystore password'
|
|
@@ -55,14 +69,18 @@ android)
|
|
|
55
69
|
;;
|
|
56
70
|
ios)
|
|
57
71
|
workspace=$(ls -d ios/*.xcworkspace | head -n 1)
|
|
58
|
-
scheme=${target:-$(basename "$workspace" .xcworkspace)}
|
|
59
|
-
[ -d ios/Pods ] ||
|
|
72
|
+
scheme=${target:-${AMK_IOS_SCHEME:-$(basename "$workspace" .xcworkspace)}}
|
|
73
|
+
[ -d ios/Pods ] || sh scripts/ai/pod-install.sh
|
|
60
74
|
log="$out/$scheme-ios.log"
|
|
61
75
|
echo "Archiving $scheme (several minutes; log: $log)"
|
|
62
|
-
xcodebuild -workspace "$workspace" -scheme "$scheme" -
|
|
76
|
+
xcodebuild -workspace "$workspace" -scheme "$scheme" -destination 'generic/platform=iOS' \
|
|
63
77
|
-archivePath "$out/$scheme.xcarchive" -allowProvisioningUpdates archive > "$log" 2>&1 \
|
|
64
78
|
|| { grep -E 'error:|BUILD FAILED|ARCHIVE FAILED' "$log" | head -n 20; exit 1; }
|
|
65
|
-
|
|
79
|
+
options=${AMK_IOS_EXPORT_OPTIONS:-ios/ExportOptions.plist}
|
|
80
|
+
if [ ! -f "$options" ]; then
|
|
81
|
+
[ -z "${AMK_IOS_EXPORT_OPTIONS:-}" ] || { echo "AMK_IOS_EXPORT_OPTIONS: no file at $options" >&2; exit 1; }
|
|
82
|
+
options="$out/ExportOptions.plist"
|
|
83
|
+
cat > "$options" <<'PLIST'
|
|
66
84
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
67
85
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
68
86
|
<plist version="1.0"><dict>
|
|
@@ -71,8 +89,10 @@ ios)
|
|
|
71
89
|
<key>signingStyle</key><string>automatic</string>
|
|
72
90
|
</dict></plist>
|
|
73
91
|
PLIST
|
|
92
|
+
fi
|
|
93
|
+
echo "Exporting with $options"
|
|
74
94
|
xcodebuild -exportArchive -archivePath "$out/$scheme.xcarchive" -exportPath "$out/$scheme" \
|
|
75
|
-
-exportOptionsPlist "$
|
|
95
|
+
-exportOptionsPlist "$options" -allowProvisioningUpdates >> "$log" 2>&1 \
|
|
76
96
|
|| { grep -E 'error:|EXPORT FAILED' "$log" | head -n 20; exit 1; }
|
|
77
97
|
ipa=$(ls "$out/$scheme"/*.ipa | head -n 1)
|
|
78
98
|
# the export re-signs for distribution, so check the app inside the .ipa, not the archive
|
|
@@ -81,7 +101,7 @@ PLIST
|
|
|
81
101
|
echo "$ipa"
|
|
82
102
|
;;
|
|
83
103
|
*)
|
|
84
|
-
sed -n '2,
|
|
104
|
+
sed -n '2,18p' "$0"
|
|
85
105
|
exit 1
|
|
86
106
|
;;
|
|
87
107
|
esac
|
|
@@ -40,7 +40,15 @@ const manifestPath = 'android/app/src/main/AndroidManifest.xml';
|
|
|
40
40
|
const pkg = JSON.parse(readNow('package.json') || '{}');
|
|
41
41
|
// this kit's codemagic.yaml sets build numbers and the Android upload key on the build machine
|
|
42
42
|
const codemagic = readNow('codemagic.yaml') || '';
|
|
43
|
-
|
|
43
|
+
// build numbers set at build time (by CI or fastlane, as this kit's codemagic.yaml does) never change in the repo
|
|
44
|
+
const workflows = fs.existsSync('.github/workflows') ? fs.readdirSync('.github/workflows').map(f => `.github/workflows/${f}`) : [];
|
|
45
|
+
const buildFiles = ['codemagic.yaml', 'bitrise.yml', '.gitlab-ci.yml', '.circleci/config.yml', 'azure-pipelines.yml', ...workflows,
|
|
46
|
+
...['fastlane', 'ios/fastlane', 'android/fastlane'].map(d => `${d}/Fastfile`)];
|
|
47
|
+
const setsBuild = {
|
|
48
|
+
iOS: /agvtool new-version|increment_build_number|set-xcode-build-number|Set :CFBundleVersion/,
|
|
49
|
+
Android: /versionCode[^\n]*\$|increment_version_code|android_set_version_code|change-android-versioncode/,
|
|
50
|
+
};
|
|
51
|
+
const ciBuildNumber = Object.fromEntries(Object.entries(setsBuild).map(([p, re]) => [p, buildFiles.find(f => re.test(readNow(f) || ''))]));
|
|
44
52
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
45
53
|
|
|
46
54
|
// ---------- 1. versions ----------
|
|
@@ -50,7 +58,7 @@ const androidVersions = t => all(/versionName\s*=?\s*"([^"]+)"/g, stripComments(
|
|
|
50
58
|
const androidBuilds = t => all(/versionCode\s*=?\s*(\d+)/g, stripComments(t));
|
|
51
59
|
|
|
52
60
|
function compare(platform, now, before, kind, versionChanged) {
|
|
53
|
-
if (kind === 'build number' && ciBuildNumber[platform]) { info(`${platform} build number: set
|
|
61
|
+
if (kind === 'build number' && ciBuildNumber[platform]) { info(`${platform} build number: set at build time (${ciBuildNumber[platform]})`); return; }
|
|
54
62
|
if (!now.length) { warn(`${platform} ${kind}: couldn't read it`, 'check it by hand before you ship'); return; }
|
|
55
63
|
if (!before) { info(`${platform} ${kind}: ${now.join(', ')}`); return; }
|
|
56
64
|
if (!before.length || now.join() !== before.join()) {
|
|
@@ -61,7 +69,7 @@ function compare(platform, now, before, kind, versionChanged) {
|
|
|
61
69
|
// the App Store needs a new build number only within a version, so 1 again for a new version is fine
|
|
62
70
|
ok(`${platform} build number (${now.join(', ')} again, for a new version)`);
|
|
63
71
|
} else if (kind === 'build number') {
|
|
64
|
-
warn(`${platform} build number unchanged since ${since} (${now.join(', ')})`, 'bump it, unless
|
|
72
|
+
warn(`${platform} build number unchanged since ${since} (${now.join(', ')})`, 'bump it, unless CI or fastlane sets it at build time; stores reject a repeated build number');
|
|
65
73
|
} else {
|
|
66
74
|
warn(`${platform} version unchanged since ${since} (${now.join(', ')})`, 'fine for a re-upload of the same version; otherwise bump it');
|
|
67
75
|
}
|
|
@@ -182,7 +190,25 @@ const debuggers = (git('grep', '-n', '-E', '^[[:space:]]*debugger;?[[:space:]]*$
|
|
|
182
190
|
if (debuggers.length) fail(`"debugger" statements left in code: ${debuggers.slice(0, 3).join(', ')}${debuggers.length > 3 ? ' …' : ''}`, 'remove them');
|
|
183
191
|
else ok('No "debugger" statements');
|
|
184
192
|
|
|
185
|
-
// ---------- 6.
|
|
193
|
+
// ---------- 6. signing keys in git ----------
|
|
194
|
+
// the standard debug.keystore (password "android") is public and fine; real keys and passwords aren't
|
|
195
|
+
const tracked = (git('ls-files') || '').split('\n').filter(Boolean);
|
|
196
|
+
const gradleCode = stripComments(readNow(gradlePath));
|
|
197
|
+
const storeFiles = [
|
|
198
|
+
...all(/storeFile\s*=?\s*file\(\s*["']([^"']+)["']\s*\)/g, gradleCode).map(f => path.posix.join('android/app', f)),
|
|
199
|
+
...all(/storeFile\s*=?\s*rootProject\.file\(\s*["']([^"']+)["']\s*\)/g, gradleCode).map(f => path.posix.join('android', f)),
|
|
200
|
+
];
|
|
201
|
+
const keys = tracked.filter(f => (/\.(jks|keystore|p12|p8|mobileprovision)$/.test(f) || storeFiles.includes(f)) && path.basename(f) !== 'debug.keystore');
|
|
202
|
+
// React Native's docs suggest android/gradle.properties for these passwords, and that file is usually committed
|
|
203
|
+
const propsPasswords = tracked.includes('android/gradle.properties')
|
|
204
|
+
? (readNow('android/gradle.properties') || '').split('\n').filter(l => /^[^#]*password[^=]*=\s*\S/i.test(l)).length : 0;
|
|
205
|
+
const passwords = [...gradleCode.matchAll(/(?:store|key)Password\s*=?\s*["']([^"']*)["']/g)].filter(m => m[1] !== 'android').length + propsPasswords;
|
|
206
|
+
if (keys.length || passwords) {
|
|
207
|
+
const what = [keys.length && `signing keys are in git: ${keys.join(', ')}`, passwords && `${passwords} signing password(s) are written in ${propsPasswords ? 'android/gradle.properties or ' : ''}${gradlePath}`].filter(Boolean).join('; ');
|
|
208
|
+
warn(what.charAt(0).toUpperCase() + what.slice(1), 'anyone who can read the repo can sign builds as you: keep keys in a password manager, read passwords from the environment or ~/.gradle/gradle.properties, and reset the upload key in Play Console if Play App Signing is on');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ---------- 7. store notes ----------
|
|
186
212
|
const LIMITS = { 'play-store': 500, 'app-store': 4000 };
|
|
187
213
|
const noteFiles = fs.existsSync('release-notes') ? (git('ls-files', '--others', '--cached', '--exclude-standard', 'release-notes') || '').split('\n').filter(Boolean) : [];
|
|
188
214
|
for (const f of noteFiles) {
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
# and Android emulator, running Maestro flows and saving screenshots as evidence.
|
|
4
4
|
#
|
|
5
5
|
# Usage: sh scripts/ai/verify.sh [quick|ios|android|all] [--spec <id>] [--flow <file>] [--label <name>]
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# --
|
|
6
|
+
# [--flavor <name>] [--scheme <name>]
|
|
7
|
+
# quick lint, typecheck, tests
|
|
8
|
+
# ios|android release build, install, run flows, screenshots
|
|
9
|
+
# all everything (default)
|
|
10
|
+
# --spec <id> run .maestro/<id>*.yaml and save evidence in .ai/evidence/<id>/
|
|
11
|
+
# --label <n> evidence folder name (default: the spec id, or a timestamp)
|
|
12
|
+
# --flavor <name> Android product flavor to check (default: the first one in build.gradle)
|
|
13
|
+
# --scheme <name> iOS scheme to check (default: the one named like the workspace)
|
|
11
14
|
# (no flows found: a smoke check that launches the app and takes a screenshot)
|
|
12
|
-
# Env:
|
|
15
|
+
# Env: AMK_ANDROID_FLAVOR, AMK_IOS_SCHEME (defaults for the two options), AMK_IOS_DEVICE (simulator name
|
|
16
|
+
# or UDID), AMK_ANDROID_DEVICE (adb serial, when several are connected), AMK_ANDROID_AVD (emulator to start)
|
|
13
17
|
set -eu
|
|
14
18
|
|
|
15
19
|
mode=${1:-all}
|
|
@@ -17,11 +21,14 @@ mode=${1:-all}
|
|
|
17
21
|
spec=""
|
|
18
22
|
flow=""
|
|
19
23
|
label=""
|
|
24
|
+
flavor=${AMK_ANDROID_FLAVOR:-}
|
|
20
25
|
while [ $# -gt 0 ]; do
|
|
21
26
|
case $1 in
|
|
22
27
|
--spec) spec=$2; shift 2 ;;
|
|
23
28
|
--flow) flow=$2; shift 2 ;;
|
|
24
29
|
--label) label=$2; shift 2 ;;
|
|
30
|
+
--flavor) flavor=$2; shift 2 ;;
|
|
31
|
+
--scheme) AMK_IOS_SCHEME=$2; export AMK_IOS_SCHEME; shift 2 ;;
|
|
25
32
|
*) echo "verify: unknown option $1"; exit 2 ;;
|
|
26
33
|
esac
|
|
27
34
|
done
|
|
@@ -43,7 +50,8 @@ run_flows() { # platform device app_id
|
|
|
43
50
|
mkdir -p "$out"
|
|
44
51
|
files=$(flow_files)
|
|
45
52
|
if [ -z "$files" ]; then
|
|
46
|
-
|
|
53
|
+
# launchApp returns before the app has drawn: without the wait, the screenshot can show the home screen
|
|
54
|
+
printf 'appId: %s\n---\n- launchApp\n- waitForAnimationToEnd\n- takeScreenshot: smoke-launch\n' "$3" > "$out/smoke.yaml"
|
|
47
55
|
files="$out/smoke.yaml"
|
|
48
56
|
fi
|
|
49
57
|
passed=0
|
|
@@ -87,11 +95,12 @@ ios() {
|
|
|
87
95
|
fi
|
|
88
96
|
command -v maestro > /dev/null || { echo "ios: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
|
|
89
97
|
# pod install also generates React Native codegen files into ios/build/generated
|
|
90
|
-
if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ]; then
|
|
98
|
+
if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ]; then sh scripts/ai/pod-install.sh > "$evidence/pod-install.log" 2>&1; fi
|
|
91
99
|
if ! CONFIGURATION=Release sh scripts/ai/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
|
|
92
100
|
echo "ios: release build FAILED, see ${evidence#"$root"/}/ios-build.log"; status=1; return
|
|
93
101
|
fi
|
|
94
|
-
app
|
|
102
|
+
# the newest app: the scheme just built (another scheme's app may still be there from an earlier build)
|
|
103
|
+
app=$(ls -dt ios/DerivedData/Build/Products/*-iphonesimulator/*.app | head -n 1)
|
|
95
104
|
app_id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app/Info.plist")
|
|
96
105
|
device=$(xcrun simctl list devices available -j | node -e '
|
|
97
106
|
const all = Object.entries(JSON.parse(require("fs").readFileSync(0, "utf8")).devices)
|
|
@@ -117,20 +126,51 @@ android() {
|
|
|
117
126
|
esac
|
|
118
127
|
sdk=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$default_sdk}}
|
|
119
128
|
adb="$sdk/platform-tools/adb"
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
# apps with product flavors: check one, the first in build.gradle unless --flavor names another
|
|
130
|
+
if [ -z "$flavor" ]; then
|
|
131
|
+
code=0
|
|
132
|
+
flavors=$(node scripts/ai/android-flavors.js) || code=$?
|
|
133
|
+
case $code in
|
|
134
|
+
0) ;;
|
|
135
|
+
2) echo "android: the app has several flavor dimensions; name the variant with --flavor (for example devFree)"; status=1; return ;;
|
|
136
|
+
*) echo "android: couldn't read the product flavors from build.gradle (see the error above)"; status=1; return ;;
|
|
137
|
+
esac
|
|
138
|
+
flavor=$(echo "$flavors" | head -n 1)
|
|
139
|
+
[ -z "$flavor" ] || echo "android: checking the \"$flavor\" flavor (the app has: $(echo $flavors)); --flavor <name> checks another"
|
|
122
140
|
fi
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
device=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
|
|
141
|
+
variant=$(printf %s "$flavor" | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }')
|
|
142
|
+
# the device first: the build only needs its CPU type, and an emulator boots while Gradle builds
|
|
143
|
+
device=${AMK_ANDROID_DEVICE:-$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')}
|
|
126
144
|
if [ -z "$device" ]; then
|
|
127
145
|
avd=${AMK_ANDROID_AVD:-$("$sdk/emulator/emulator" -list-avds | head -n 1)}
|
|
128
146
|
[ -n "$avd" ] || { echo "android: no emulator found (create one in Android Studio)"; status=1; return; }
|
|
129
147
|
nohup "$sdk/emulator/emulator" -avd "$avd" -no-snapshot-save -no-boot-anim > /dev/null 2>&1 &
|
|
130
148
|
"$adb" wait-for-device
|
|
131
|
-
until [ "$("$adb" shell getprop sys.boot_completed 2> /dev/null | tr -d '\r')" = 1 ]; do sleep 3; done
|
|
132
149
|
device=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
|
|
133
150
|
fi
|
|
151
|
+
abi=$("$adb" -s "$device" shell getprop ro.product.cpu.abi 2> /dev/null | tr -d '\r')
|
|
152
|
+
[ -n "$abi" ] || { echo "android: device $device isn't connected (see: adb devices)"; status=1; return; }
|
|
153
|
+
# native code for that CPU type only, as run-android --active-arch-only does: much faster than all four
|
|
154
|
+
set -- -PreactNativeArchitectures="$abi"
|
|
155
|
+
# signed with the project's debug key, so the check build installs whatever key its real release needs
|
|
156
|
+
if [ -f android/app/debug.keystore ]; then
|
|
157
|
+
keystore=$(cd android/app && { pwd -W 2> /dev/null || pwd; })/debug.keystore # pwd -W: a Windows path in Git Bash
|
|
158
|
+
set -- "$@" -Pandroid.injected.signing.store.file="$keystore" -Pandroid.injected.signing.store.password=android \
|
|
159
|
+
-Pandroid.injected.signing.key.alias=androiddebugkey -Pandroid.injected.signing.key.password=android
|
|
160
|
+
fi
|
|
161
|
+
if ! (cd android && ./gradlew "assemble${variant}Release" --no-daemon -q "$@") > "$evidence/android-build.log" 2>&1; then
|
|
162
|
+
echo "android: release build FAILED, see ${evidence#"$root"/}/android-build.log"; status=1; return
|
|
163
|
+
fi
|
|
164
|
+
# apps that split APKs by CPU type get one per type: take this device's, else the universal one
|
|
165
|
+
apks=$(ls android/app/build/outputs/apk/${flavor:+$flavor/}release/*.apk)
|
|
166
|
+
apk=$(echo "$apks" | grep -e "-$abi-" | head -n 1)
|
|
167
|
+
[ -n "$apk" ] || apk=$(echo "$apks" | grep universal | head -n 1)
|
|
168
|
+
[ -n "$apk" ] || apk=$(echo "$apks" | head -n 1)
|
|
169
|
+
# the app ID from the built APK, which includes flavor suffixes such as .dev
|
|
170
|
+
aapt2="$(ls -d "$sdk"/build-tools/*/ 2> /dev/null | sort -V | tail -n 1)aapt2"
|
|
171
|
+
app_id=$("$aapt2" dump badging "$apk" 2> /dev/null | sed -n "s/^package: name='\([^']*\)'.*/\1/p")
|
|
172
|
+
[ -n "$app_id" ] || app_id=$(sed -n 's/.*applicationId *=\{0,1\} *"\([^"]*\)".*/\1/p' android/app/build.gradle* | head -n 1)
|
|
173
|
+
until [ "$("$adb" -s "$device" shell getprop sys.boot_completed 2> /dev/null | tr -d '\r')" = 1 ]; do sleep 3; done
|
|
134
174
|
"$adb" -s "$device" install -r "$apk" > /dev/null
|
|
135
175
|
# system "isn't responding" pop-ups (common on busy emulators) cover the app and fail flows; app crashes still fail them
|
|
136
176
|
"$adb" -s "$device" shell settings put global hide_error_dialogs 1
|