@sprid/release 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +14 -0
- package/README.md +152 -0
- package/SECURITY.md +17 -0
- package/bin/release.mjs +20 -0
- package/package.json +65 -0
- package/src/annotate.ts +67 -0
- package/src/asc/client.ts +84 -0
- package/src/asc/index.ts +8 -0
- package/src/asc/metadata.ts +120 -0
- package/src/asc/screenshots.ts +256 -0
- package/src/asc/submissions.ts +85 -0
- package/src/asc/submit.ts +227 -0
- package/src/asc/upload.ts +34 -0
- package/src/asc/version.ts +367 -0
- package/src/build/android.ts +122 -0
- package/src/build/credentials.ts +57 -0
- package/src/build/env-files.ts +60 -0
- package/src/build/env-sources.ts +41 -0
- package/src/build/exec.ts +141 -0
- package/src/build/git.ts +64 -0
- package/src/build/ios.ts +200 -0
- package/src/build/prebuild.ts +26 -0
- package/src/build/preflight.ts +58 -0
- package/src/build/sentry.ts +31 -0
- package/src/bump.ts +101 -0
- package/src/cli.ts +207 -0
- package/src/config.ts +454 -0
- package/src/copy.ts +105 -0
- package/src/env-guard.ts +48 -0
- package/src/index.ts +13 -0
- package/src/play/client.ts +54 -0
- package/src/play/graphics.ts +161 -0
- package/src/play/index.ts +8 -0
- package/src/play/metadata.ts +29 -0
- package/src/play/screenshots.ts +97 -0
- package/src/play/upload.ts +116 -0
- package/src/progress.ts +220 -0
- package/src/ship.ts +194 -0
package/src/copy.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store-listing copy: the shared TYPE + the fail-loud length validator. The
|
|
3
|
+
* actual strings live in each app (its own `store-copy.ts`), since copy is
|
|
4
|
+
* inherently per-app; only the shape and the store-imposed limits are shared.
|
|
5
|
+
*
|
|
6
|
+
* `validateStoreCopy()` is the guard that was missing when one app's keyword
|
|
7
|
+
* field silently shipped 102/100 chars — run it at the top of every push,
|
|
8
|
+
* including dry runs, so over-limit copy is caught with no credentials.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface StoreCopy {
|
|
12
|
+
/** App name — Apple `name` + Play `title`. ≤30 chars. (both stores) */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Full description — Apple `description` + Play `fullDescription`. ≤4000 chars. (both stores) */
|
|
15
|
+
description: string;
|
|
16
|
+
/** Play short description. ≤80 chars. (Play only) */
|
|
17
|
+
shortDescription?: string;
|
|
18
|
+
/** Apple subtitle. ≤30 chars. (Apple only) */
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
/** Apple keywords field — comma-separated; spaces within keyword phrases are allowed. ≤100 chars. (Apple only) */
|
|
21
|
+
keywords?: string;
|
|
22
|
+
/** Apple promotional text. ≤170 chars. (Apple only) */
|
|
23
|
+
promotionalText?: string;
|
|
24
|
+
/** Privacy-policy URL (Apple appInfo; localized). */
|
|
25
|
+
privacyPolicyUrl?: string;
|
|
26
|
+
/** Support URL (Apple). */
|
|
27
|
+
supportUrl?: string;
|
|
28
|
+
/** Marketing URL (Apple). */
|
|
29
|
+
marketingUrl?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Contact / default-language details for a Play listing. */
|
|
33
|
+
export interface StoreContact {
|
|
34
|
+
contactEmail: string;
|
|
35
|
+
contactWebsite: string;
|
|
36
|
+
defaultLanguage: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Store-imposed character ceilings (shared where the two stores agree). */
|
|
40
|
+
export const LIMITS = {
|
|
41
|
+
name: 30,
|
|
42
|
+
subtitle: 30,
|
|
43
|
+
shortDescription: 80,
|
|
44
|
+
keywords: 100,
|
|
45
|
+
promotionalText: 170,
|
|
46
|
+
description: 4000,
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Fail loudly on anything a store would reject: over-limit fields, keyword
|
|
51
|
+
* or empty required strings. Only selected store fields are validated when a store is provided.
|
|
52
|
+
* Validates every locale at once and throws with the full list of violations.
|
|
53
|
+
*/
|
|
54
|
+
export function validateStoreCopy(copy: Record<string, StoreCopy>, store?: 'apple' | 'play'): void {
|
|
55
|
+
const errors: string[] = [];
|
|
56
|
+
for (const [locale, c] of Object.entries(copy)) {
|
|
57
|
+
// name + description are needed by both stores; the rest are store-specific
|
|
58
|
+
// and optional (e.g. an app that ships Play-only has no subtitle/keywords).
|
|
59
|
+
if (!c.name?.trim()) errors.push(`[${locale}] name is empty`);
|
|
60
|
+
if (!c.description?.trim()) errors.push(`[${locale}] description is empty`);
|
|
61
|
+
// Length-check every field that IS present.
|
|
62
|
+
const present: [keyof typeof LIMITS, string | undefined][] = [
|
|
63
|
+
['name', c.name],
|
|
64
|
+
['subtitle', c.subtitle],
|
|
65
|
+
['shortDescription', c.shortDescription],
|
|
66
|
+
['keywords', c.keywords],
|
|
67
|
+
['promotionalText', c.promotionalText],
|
|
68
|
+
['description', c.description],
|
|
69
|
+
];
|
|
70
|
+
for (const [field, value] of present) {
|
|
71
|
+
if (store === 'apple' && field === 'shortDescription') continue;
|
|
72
|
+
if (store === 'play' && ['subtitle', 'keywords', 'promotionalText'].includes(field)) continue;
|
|
73
|
+
if (value && value.length > LIMITS[field]) {
|
|
74
|
+
errors.push(`[${locale}] ${field} is ${value.length}/${LIMITS[field]} chars (over by ${value.length - LIMITS[field]})`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
if (errors.length) {
|
|
80
|
+
throw new Error(`Store copy validation failed:\n - ${errors.join('\n - ')}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Pretty length report for a `bun store-copy.ts` self-lint (skips absent fields). */
|
|
85
|
+
export function copyLengthReport(copy: Record<string, StoreCopy>): string {
|
|
86
|
+
const len = (v: string | undefined, limit: number) => (v === undefined ? '—' : `${v.length}/${limit}`);
|
|
87
|
+
return Object.entries(copy)
|
|
88
|
+
.map(
|
|
89
|
+
([locale, c]) =>
|
|
90
|
+
` [${locale}] name ${len(c.name, LIMITS.name)}, subtitle ${len(c.subtitle, LIMITS.subtitle)}, ` +
|
|
91
|
+
`short ${len(c.shortDescription, LIMITS.shortDescription)}, keywords ${len(c.keywords, LIMITS.keywords)}, ` +
|
|
92
|
+
`promo ${len(c.promotionalText, LIMITS.promotionalText)}, desc ${len(c.description, LIMITS.description)}`,
|
|
93
|
+
)
|
|
94
|
+
.join('\n');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Validate exactly the selected locales; missing copy must never silently disappear. */
|
|
98
|
+
export function selectedCopy(copy: Record<string, StoreCopy>, map: Record<string, string>, store: 'apple' | 'play'): [string, StoreCopy][] {
|
|
99
|
+
const entries = Object.entries(map).map(([locale, key]): [string, StoreCopy] => {
|
|
100
|
+
if (!copy[key]) throw new Error(`Missing storeCopy.${key} for ${store} locale ${locale}.`);
|
|
101
|
+
return [locale, copy[key]];
|
|
102
|
+
});
|
|
103
|
+
validateStoreCopy(Object.fromEntries(entries), store);
|
|
104
|
+
return entries;
|
|
105
|
+
}
|
package/src/env-guard.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Local build and store release support. All app settings come from the consuming configuration. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { releasePath } from './config.ts';
|
|
5
|
+
import type { AppReleaseConfig, RequiredEnvVar } from './config.ts';
|
|
6
|
+
|
|
7
|
+
function parseEnvFile(path: string): Record<string, string> {
|
|
8
|
+
const out: Record<string, string> = {};
|
|
9
|
+
let text: string;
|
|
10
|
+
try {
|
|
11
|
+
text = readFileSync(path, 'utf8');
|
|
12
|
+
} catch {
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
for (const line of text.split('\n')) {
|
|
16
|
+
const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/i);
|
|
17
|
+
if (m) out[m[1]] = m[2].trim().replace(/^["']|["']$/g, '');
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export function assertRequiredProdEnv(config: AppReleaseConfig, envFilePath?: string): void {
|
|
24
|
+
const required = config.requiredProdEnv ?? [];
|
|
25
|
+
if (!required.length) return;
|
|
26
|
+
|
|
27
|
+
const path = envFilePath
|
|
28
|
+
? releasePath(config, envFilePath)
|
|
29
|
+
: resolve(releasePath(config, config.build?.appDir ?? '.'), '.env');
|
|
30
|
+
const env = parseEnvFile(path);
|
|
31
|
+
|
|
32
|
+
const norm: RequiredEnvVar[] = required.map((r) => (typeof r === 'string' ? { name: r } : r));
|
|
33
|
+
const errors: string[] = [];
|
|
34
|
+
for (const { name, allowLocalhost } of norm) {
|
|
35
|
+
const value = process.env[name] ?? env[name] ?? '';
|
|
36
|
+
if (!value) {
|
|
37
|
+
errors.push(`${name} is blank in ${path} (a production build would ship it unset).`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!allowLocalhost && /(localhost|127\.0\.0\.1)/.test(value)) {
|
|
41
|
+
errors.push(`${name} points to localhost, unreachable from a shipped app.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (errors.length) {
|
|
45
|
+
throw new Error(`Production env check failed:\n - ${errors.join('\n - ')}`);
|
|
46
|
+
}
|
|
47
|
+
console.log(`✓ Required production env present: ${norm.map((r) => r.name).join(', ')}`);
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @sprid/release — the listing half of a store release: metadata, screenshots
|
|
2
|
+
// and Play graphics, pushed from one `release.config.ts`. Building, signing,
|
|
3
|
+
// uploading binaries and submitting for review are deliberately not here.
|
|
4
|
+
export * from './config.ts';
|
|
5
|
+
export * from './copy.ts';
|
|
6
|
+
export * from './asc/index.ts';
|
|
7
|
+
export * from './play/index.ts';
|
|
8
|
+
|
|
9
|
+
export { ship, type ShipOptions } from './ship.ts';
|
|
10
|
+
export { bumpVersion, readAppVersion, type AppVersion, type BumpKind } from './bump.ts';
|
|
11
|
+
export { uploadIpa } from './asc/upload.ts';
|
|
12
|
+
export { submitForReview, type SubmitOptions } from './asc/submit.ts';
|
|
13
|
+
export { uploadAab, finalizePlayRelease, PlayConsoleRequiredError, type UploadAabOptions } from './play/upload.ts';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Play Android Publisher client + the shared edit-session helpers.
|
|
3
|
+
* `withEdit` runs work inside an edit and commits
|
|
4
|
+
* or abandons on failure. Release tracks are never changed. Config-driven.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { google } from 'googleapis';
|
|
8
|
+
import type { AppReleaseConfig } from '../config.ts';
|
|
9
|
+
import { resolvePlayKeyPath } from '../config.ts';
|
|
10
|
+
|
|
11
|
+
export type PlayApi = ReturnType<typeof google.androidpublisher>;
|
|
12
|
+
|
|
13
|
+
export interface PlayClient {
|
|
14
|
+
readonly packageName: string;
|
|
15
|
+
readonly play: PlayApi;
|
|
16
|
+
/** Commit an edit without modifying release tracks. Name kept for compatibility. */
|
|
17
|
+
commitWithDraftStaging(editId: string, reapply?: (editId: string) => Promise<void>): Promise<void>;
|
|
18
|
+
withEdit<T>(fn: (editId: string) => Promise<T>): Promise<T>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createPlayClient(config: AppReleaseConfig): PlayClient {
|
|
22
|
+
const packageName = config.play?.packageName;
|
|
23
|
+
if (!packageName) throw new Error('Set play.packageName for Google Play commands.');
|
|
24
|
+
const auth = new google.auth.GoogleAuth({
|
|
25
|
+
keyFile: resolvePlayKeyPath(config),
|
|
26
|
+
scopes: ['https://www.googleapis.com/auth/androidpublisher'],
|
|
27
|
+
});
|
|
28
|
+
const play = google.androidpublisher({ version: 'v3', auth });
|
|
29
|
+
|
|
30
|
+
// Retain the exported method name for existing callers. Listing updates never
|
|
31
|
+
// modify release tracks, even when Play refuses a commit for a draft app.
|
|
32
|
+
async function commitWithDraftStaging(editId: string, _reapply?: (editId: string) => Promise<void>): Promise<void> {
|
|
33
|
+
await play.edits.commit({ packageName, editId });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function withEdit<T>(fn: (editId: string) => Promise<T>): Promise<T> {
|
|
37
|
+
const editRes = await play.edits.insert({ packageName });
|
|
38
|
+
const editId = editRes.data.id!;
|
|
39
|
+
console.log(` Edit ID: ${editId}`);
|
|
40
|
+
try {
|
|
41
|
+
const result = await fn(editId);
|
|
42
|
+
await commitWithDraftStaging(editId);
|
|
43
|
+
console.log(' ✓ committed');
|
|
44
|
+
return result;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
try {
|
|
47
|
+
await play.edits.delete({ packageName, editId });
|
|
48
|
+
} catch {}
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { packageName, play, commitWithDraftStaging, withEdit };
|
|
54
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push Google Play feature graphic + icon per locale. Delete the existing
|
|
3
|
+
* `featureGraphic` (1024×500 PNG) + `icon` (512×512 PNG) then re-upload, so
|
|
4
|
+
* re-runs replace rather than append. Commits with `changesNotSentForReview`
|
|
5
|
+
* (+ the draft-app retry), matching `play/screenshots.ts`.
|
|
6
|
+
*
|
|
7
|
+
* Source paths come from `config.playGraphics {featureGraphic?, icon?, dir?}`
|
|
8
|
+
* (each may contain `{lang}` for per-locale assets). When only `dir` is set,
|
|
9
|
+
* the defaults are `<dir>/play-store-feature.png` and `<dir>/play-store-icon.png`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createReadStream, existsSync, statSync } from 'node:fs';
|
|
13
|
+
import { resolve } from 'node:path';
|
|
14
|
+
import { listingLocaleMap, releasePath, type AppReleaseConfig } from '../config.ts';
|
|
15
|
+
import { createPlayClient } from './client.ts';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Play feature-graphic + icon source (for the `play-graphics` command). Add this
|
|
19
|
+
* as an optional `playGraphics?: PlayGraphicsConfig` field on `AppReleaseConfig`
|
|
20
|
+
* in config.ts. Each path may contain `{lang}` for per-locale assets; relative to
|
|
21
|
+
* cwd. When only `dir` is set, the per-type defaults are `<dir>/play-store-feature.png`
|
|
22
|
+
* and `<dir>/play-store-icon.png`.
|
|
23
|
+
*/
|
|
24
|
+
export interface PlayGraphicsConfig {
|
|
25
|
+
/** Explicit 1024×500 feature graphic PNG path (may contain `{lang}`). */
|
|
26
|
+
featureGraphic?: string;
|
|
27
|
+
/** Explicit 512×512 icon PNG path (may contain `{lang}`). */
|
|
28
|
+
icon?: string;
|
|
29
|
+
/** Base dir to derive the default feature/icon paths from when not explicit. */
|
|
30
|
+
dir?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Config carrying the (optional) playGraphics field — see config.ts. */
|
|
34
|
+
type ConfigWithPlayGraphics = AppReleaseConfig & { playGraphics?: PlayGraphicsConfig };
|
|
35
|
+
|
|
36
|
+
export interface PushPlayGraphicsOptions {
|
|
37
|
+
config: AppReleaseConfig;
|
|
38
|
+
/** Listing locale → copy-locale key (defaults to listingLocales.play / locales.play). */
|
|
39
|
+
localeMap?: Record<string, string>;
|
|
40
|
+
execute?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type GraphicType = 'featureGraphic' | 'icon';
|
|
44
|
+
|
|
45
|
+
// Resolve a configured path for a given language, substituting `{lang}` and
|
|
46
|
+
// resolving relative to cwd. Returns undefined when no path is configured.
|
|
47
|
+
function resolvePath(config: AppReleaseConfig, path: string | undefined, lang: string): string | undefined {
|
|
48
|
+
if (!path) return undefined;
|
|
49
|
+
return releasePath(config, path.replaceAll('{lang}', lang));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function describe(path: string): string {
|
|
53
|
+
if (!existsSync(path)) return `${path} (MISSING)`;
|
|
54
|
+
const size = statSync(path).size;
|
|
55
|
+
return `${path} (${(size / 1024).toFixed(0)} KB)`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function pushPlayGraphics({ config, localeMap, execute = false }: PushPlayGraphicsOptions): Promise<void> {
|
|
59
|
+
const gc = (config as ConfigWithPlayGraphics).playGraphics;
|
|
60
|
+
if (!gc) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
'release.config.ts needs `playGraphics {featureGraphic?, icon?, dir?}` for play-graphics.',
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
console.log(`Google Play graphics push ${execute ? '(EXECUTE)' : '(DRY RUN)'}`);
|
|
66
|
+
|
|
67
|
+
// Default the per-type source from `dir` when an explicit path isn't given.
|
|
68
|
+
const featureSrc =
|
|
69
|
+
gc.featureGraphic ?? (gc.dir ? `${gc.dir.replace(/\/$/, '')}/play-store-feature.png` : undefined);
|
|
70
|
+
const iconSrc = gc.icon ?? (gc.dir ? `${gc.dir.replace(/\/$/, '')}/play-store-icon.png` : undefined);
|
|
71
|
+
|
|
72
|
+
const graphics: { type: GraphicType; src: string | undefined; expect: string }[] = [
|
|
73
|
+
{ type: 'featureGraphic', src: featureSrc, expect: '1024×500 PNG' },
|
|
74
|
+
{ type: 'icon', src: iconSrc, expect: '512×512 PNG' },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const map = listingLocaleMap(config, 'play', localeMap);
|
|
78
|
+
const plan = Object.entries(map).flatMap(([locale, lang]) => graphics.flatMap(({ type, src }) => {
|
|
79
|
+
const path = resolvePath(config, src, lang);
|
|
80
|
+
if (!path) return [];
|
|
81
|
+
if (!existsSync(path) || !statSync(path).isFile() || !statSync(path).size) throw new Error(`Missing or empty ${type} source: ${path}`);
|
|
82
|
+
return [{ locale, type, path }];
|
|
83
|
+
}));
|
|
84
|
+
if (!plan.length) throw new Error('Configure at least one Play graphic source.');
|
|
85
|
+
console.log(JSON.stringify(plan, null, 2));
|
|
86
|
+
if (!iconSrc) console.log(' Icon omitted: execution must verify an existing Play listing icon for every selected locale.');
|
|
87
|
+
if (!execute) return;
|
|
88
|
+
const { play, packageName } = createPlayClient(config);
|
|
89
|
+
|
|
90
|
+
const editRes = execute ? await play.edits.insert({ packageName }) : { data: { id: 'dry-run' } };
|
|
91
|
+
const editId = editRes.data.id!;
|
|
92
|
+
if (execute) console.log(` Edit ID: ${editId}`);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
// The launcher icon inside an AAB does not populate the store listing.
|
|
96
|
+
// Check all locales before replacing any graphics. Partial updates remain
|
|
97
|
+
// valid when the listing already has an icon.
|
|
98
|
+
if (!iconSrc) {
|
|
99
|
+
const icons = new Map<string, boolean>();
|
|
100
|
+
let defaultLocale: string | undefined;
|
|
101
|
+
const hasIcon = async (locale: string) => {
|
|
102
|
+
if (!icons.has(locale)) {
|
|
103
|
+
const existing = await play.edits.images.list({ packageName, editId, language: locale, imageType: 'icon' });
|
|
104
|
+
icons.set(locale, Boolean(existing.data.images?.length));
|
|
105
|
+
}
|
|
106
|
+
return icons.get(locale)!;
|
|
107
|
+
};
|
|
108
|
+
for (const locale of Object.keys(map)) {
|
|
109
|
+
if (await hasIcon(locale)) continue;
|
|
110
|
+
defaultLocale ??= (await play.edits.details.get({ packageName, editId })).data.defaultLanguage ?? undefined;
|
|
111
|
+
if (defaultLocale && defaultLocale !== locale && await hasIcon(defaultLocale)) continue;
|
|
112
|
+
throw new Error(`No Play listing icon for ${locale}. Configure playGraphics.icon with a 512×512 PNG before uploading graphics; the AAB launcher icon is separate.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const [locale, lang] of Object.entries(map)) {
|
|
116
|
+
console.log(`\n[${locale}]`);
|
|
117
|
+
for (const { type, src, expect } of graphics) {
|
|
118
|
+
const path = resolvePath(config, src, lang);
|
|
119
|
+
if (!path) {
|
|
120
|
+
console.log(type === 'icon' ? ' icon: preserving verified existing Play icon' : ` ${type}: no source configured, skipping`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!existsSync(path)) {
|
|
124
|
+
throw new Error(`Missing ${type} source: ${path}`);
|
|
125
|
+
}
|
|
126
|
+
console.log(` ${type}: ${describe(path)} (expect ${expect})`);
|
|
127
|
+
if (!execute) continue;
|
|
128
|
+
|
|
129
|
+
await play.edits.images
|
|
130
|
+
.deleteall({ packageName, editId, language: locale, imageType: type })
|
|
131
|
+
.catch((e: any) => {
|
|
132
|
+
if (e.code !== 404) throw e;
|
|
133
|
+
});
|
|
134
|
+
await play.edits.images.upload({
|
|
135
|
+
packageName,
|
|
136
|
+
editId,
|
|
137
|
+
language: locale,
|
|
138
|
+
imageType: type,
|
|
139
|
+
media: { mimeType: 'image/png', body: createReadStream(path) },
|
|
140
|
+
});
|
|
141
|
+
console.log(` ✓ ${type}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (execute) {
|
|
146
|
+
try {
|
|
147
|
+
await play.edits.commit({ packageName, editId, changesNotSentForReview: true });
|
|
148
|
+
} catch (e: any) {
|
|
149
|
+
if (String(e?.message ?? '').includes('changesNotSentForReview')) {
|
|
150
|
+
await play.edits.commit({ packageName, editId });
|
|
151
|
+
} else throw e;
|
|
152
|
+
}
|
|
153
|
+
console.log(' ✓ committed');
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (execute) await play.edits.delete({ packageName, editId }).catch(() => {});
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.log(`\n${execute ? '✓ Done' : '(dry run — pass execute:true to push)'}`);
|
|
161
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createPlayClient } from './client.ts';
|
|
2
|
+
export type { PlayClient, PlayApi } from './client.ts';
|
|
3
|
+
export { pushPlayMetadata } from './metadata.ts';
|
|
4
|
+
export type { PushPlayMetadataOptions } from './metadata.ts';
|
|
5
|
+
export { pushPlayScreenshots } from './screenshots.ts';
|
|
6
|
+
export type { PushPlayScreenshotsOptions } from './screenshots.ts';
|
|
7
|
+
export { pushPlayGraphics } from './graphics.ts';
|
|
8
|
+
export type { PushPlayGraphicsOptions } from './graphics.ts';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Update selected Google Play listings without touching releases or build configuration. */
|
|
2
|
+
import { listingLocaleMap, type AppReleaseConfig } from '../config.ts';
|
|
3
|
+
import { selectedCopy, type StoreContact, type StoreCopy } from '../copy.ts';
|
|
4
|
+
import { createPlayClient } from './client.ts';
|
|
5
|
+
|
|
6
|
+
export interface PushPlayMetadataOptions {
|
|
7
|
+
config: AppReleaseConfig;
|
|
8
|
+
copy: Record<string, StoreCopy>;
|
|
9
|
+
contact?: StoreContact;
|
|
10
|
+
localeMap?: Record<string, string>;
|
|
11
|
+
execute?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function pushPlayMetadata({ config, copy, contact, localeMap, execute = false }: PushPlayMetadataOptions): Promise<void> {
|
|
15
|
+
const listings = selectedCopy(copy, listingLocaleMap(config, 'play', localeMap), 'play');
|
|
16
|
+
const plan = listings.map(([language, c]) => ({ language, title: c.name,
|
|
17
|
+
shortDescription: c.shortDescription, fullDescription: c.description }));
|
|
18
|
+
console.log(JSON.stringify({ store: 'play', packageName: config.play?.packageName, listings: plan, contact }, null, 2));
|
|
19
|
+
if (!execute) return;
|
|
20
|
+
const client = createPlayClient(config);
|
|
21
|
+
const { play, packageName } = client;
|
|
22
|
+
await client.withEdit(async editId => {
|
|
23
|
+
for (const listing of plan) {
|
|
24
|
+
await play.edits.listings.patch({ packageName, editId, language: listing.language, requestBody: listing });
|
|
25
|
+
}
|
|
26
|
+
if (contact) await play.edits.details.patch({ packageName, editId, requestBody: contact });
|
|
27
|
+
});
|
|
28
|
+
console.log('Google Play metadata updated.');
|
|
29
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload Play Store phone screenshots: per listing locale, delete the existing `phoneScreenshots`
|
|
3
|
+
* then upload the ordered JPEGs matched by `playScreenshots.{dir,glob}`. Commits
|
|
4
|
+
* with `changesNotSentForReview` (+ the draft-app retry).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createReadStream, readdirSync } from 'node:fs';
|
|
8
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
9
|
+
import { listingLocaleMap, releasePath, type AppReleaseConfig } from '../config.ts';
|
|
10
|
+
import { createPlayClient } from './client.ts';
|
|
11
|
+
|
|
12
|
+
export interface PushPlayScreenshotsOptions {
|
|
13
|
+
config: AppReleaseConfig;
|
|
14
|
+
/** Listing locale → copy-locale key (defaults to listingLocales.play / locales.play). */
|
|
15
|
+
localeMap?: Record<string, string>;
|
|
16
|
+
execute?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Resolve `<dir>/<glob with {lang}>` where the glob's last segment has a single
|
|
20
|
+
// `*` wildcard (e.g. `en/aso/app_en_play-phone_*.jpg`). Node fs, no bun dep.
|
|
21
|
+
function filesFor(dir: string, glob: string, lang: string): string[] {
|
|
22
|
+
const full = resolve(dir, glob.replaceAll('{lang}', lang));
|
|
23
|
+
const folder = dirname(full);
|
|
24
|
+
const namePattern = basename(full);
|
|
25
|
+
const rx = new RegExp('^' + namePattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$');
|
|
26
|
+
let names: string[];
|
|
27
|
+
try {
|
|
28
|
+
names = readdirSync(folder);
|
|
29
|
+
} catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
return names
|
|
33
|
+
.filter((n) => rx.test(n))
|
|
34
|
+
.sort()
|
|
35
|
+
.map((n) => resolve(folder, n));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function pushPlayScreenshots({ config, localeMap, execute = false }: PushPlayScreenshotsOptions): Promise<void> {
|
|
39
|
+
const sc = config.playScreenshots;
|
|
40
|
+
if (!sc) throw new Error('release.config.ts needs `playScreenshots {dir, glob}` for play-screenshots.');
|
|
41
|
+
console.log(`Google Play screenshots push ${execute ? '(EXECUTE)' : '(DRY RUN)'}`);
|
|
42
|
+
|
|
43
|
+
const map = listingLocaleMap(config, 'play', localeMap);
|
|
44
|
+
const dir = releasePath(config, sc.dir);
|
|
45
|
+
const sources = new Map(Object.entries(map).map(([locale, lang]) => {
|
|
46
|
+
const files = filesFor(dir, sc.glob, lang);
|
|
47
|
+
if (!files.length) throw new Error(`No replacement screenshots for ${locale}: ${sc.glob}`);
|
|
48
|
+
return [locale, files];
|
|
49
|
+
}));
|
|
50
|
+
console.log(JSON.stringify(Object.fromEntries(sources), null, 2));
|
|
51
|
+
if (!execute) return;
|
|
52
|
+
const { play, packageName } = createPlayClient(config);
|
|
53
|
+
|
|
54
|
+
const editRes = execute ? await play.edits.insert({ packageName }) : { data: { id: 'dry-run' } };
|
|
55
|
+
const editId = editRes.data.id!;
|
|
56
|
+
if (execute) console.log(` Edit ID: ${editId}`);
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
for (const [locale, lang] of Object.entries(map)) {
|
|
60
|
+
const files = sources.get(locale)!;
|
|
61
|
+
console.log(` [${locale}] ${files.length} screenshot(s)${files.length ? '' : ' — skipping'}`);
|
|
62
|
+
for (const f of files) console.log(` ${f.split('/').pop()}`);
|
|
63
|
+
if (!execute || !files.length) continue;
|
|
64
|
+
|
|
65
|
+
await play.edits.images
|
|
66
|
+
.deleteall({ packageName, editId, language: locale, imageType: 'phoneScreenshots' })
|
|
67
|
+
.catch((e: any) => {
|
|
68
|
+
if (e.code !== 404) throw e;
|
|
69
|
+
});
|
|
70
|
+
for (const f of files) {
|
|
71
|
+
await play.edits.images.upload({
|
|
72
|
+
packageName,
|
|
73
|
+
editId,
|
|
74
|
+
language: locale,
|
|
75
|
+
imageType: 'phoneScreenshots',
|
|
76
|
+
media: { mimeType: f.toLowerCase().endsWith('.png') ? 'image/png' : 'image/jpeg', body: createReadStream(f) },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (execute) {
|
|
82
|
+
try {
|
|
83
|
+
await play.edits.commit({ packageName, editId, changesNotSentForReview: true });
|
|
84
|
+
} catch (e: any) {
|
|
85
|
+
if (String(e?.message ?? '').includes('changesNotSentForReview')) {
|
|
86
|
+
await play.edits.commit({ packageName, editId });
|
|
87
|
+
} else throw e;
|
|
88
|
+
}
|
|
89
|
+
console.log(' ✓ committed');
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (execute) await play.edits.delete({ packageName, editId }).catch(() => {});
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(`\n${execute ? '✓ Done' : '(dry run — pass execute:true to push)'}`);
|
|
97
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** Local build and store release support. All app settings come from the consuming configuration. */
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { listingLocaleMap } from '../config.ts';
|
|
4
|
+
import type { AppReleaseConfig } from '../config.ts';
|
|
5
|
+
import { createPlayClient } from './client.ts';
|
|
6
|
+
import { stage } from '../progress.ts';
|
|
7
|
+
|
|
8
|
+
export type PlayTrack = 'internal' | 'beta' | 'production';
|
|
9
|
+
|
|
10
|
+
export interface UploadAabOptions {
|
|
11
|
+
|
|
12
|
+
aabPath: string;
|
|
13
|
+
|
|
14
|
+
version: string;
|
|
15
|
+
track?: PlayTrack;
|
|
16
|
+
|
|
17
|
+
sendForReview?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The binary is saved on the requested track, but Google requires Console setup. */
|
|
21
|
+
export class PlayConsoleRequiredError extends Error {
|
|
22
|
+
constructor(readonly versionCode: number, readonly track: PlayTrack) {
|
|
23
|
+
super(`Version code ${versionCode} is saved as a ${track} draft. Google rejected publishing this draft app. Complete its first release in Google Play Console; it has not been sent for review.`);
|
|
24
|
+
this.name = 'PlayConsoleRequiredError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DEFAULT_NOTES: Record<string, string> = {
|
|
29
|
+
en: 'Bug fixes and improvements.',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function releaseNotesFor(config: AppReleaseConfig): { language: string; text: string }[] {
|
|
33
|
+
const notes = config.releaseNotes ?? {};
|
|
34
|
+
return Object.entries(config.locales?.play ?? listingLocaleMap(config, 'play'))
|
|
35
|
+
.map(([playLocale, copyKey]) => {
|
|
36
|
+
const text = notes[copyKey] ?? DEFAULT_NOTES[copyKey];
|
|
37
|
+
return text ? { language: playLocale, text } : null;
|
|
38
|
+
})
|
|
39
|
+
.filter((n): n is { language: string; text: string } => n !== null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function uploadAab(config: AppReleaseConfig, opts: UploadAabOptions): Promise<number> {
|
|
43
|
+
const track: PlayTrack = opts.track ?? 'production';
|
|
44
|
+
const sendForReview = opts.sendForReview ?? track === 'production';
|
|
45
|
+
const { play, packageName } = createPlayClient(config);
|
|
46
|
+
|
|
47
|
+
console.log(`── Uploading AAB to Google Play (track=${track}, sendForReview=${sendForReview})`);
|
|
48
|
+
const editRes = await play.edits.insert({ packageName });
|
|
49
|
+
const editId = editRes.data.id!;
|
|
50
|
+
console.log(` Edit ID: ${editId}`);
|
|
51
|
+
try {
|
|
52
|
+
const bundle = await stage('android-upload', 'Uploading bundle to Google Play', () =>
|
|
53
|
+
play.edits.bundles.upload({
|
|
54
|
+
packageName,
|
|
55
|
+
editId,
|
|
56
|
+
media: { mimeType: 'application/octet-stream', body: createReadStream(opts.aabPath) },
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
const versionCode = bundle.data.versionCode!;
|
|
60
|
+
console.log(` Uploaded versionCode ${versionCode}`);
|
|
61
|
+
|
|
62
|
+
await finalizePlayRelease(config, { ...opts, track, sendForReview, editId, versionCode });
|
|
63
|
+
return versionCode;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!(error instanceof PlayConsoleRequiredError)) {
|
|
66
|
+
try { await play.edits.delete({ packageName, editId }); } catch {}
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Finish an existing upload edit without uploading the same bundle again. */
|
|
73
|
+
export async function finalizePlayRelease(config: AppReleaseConfig, opts: {
|
|
74
|
+
editId: string; versionCode: number; version: string; track?: PlayTrack; sendForReview?: boolean;
|
|
75
|
+
}): Promise<void> {
|
|
76
|
+
const { editId, versionCode } = opts;
|
|
77
|
+
const track = opts.track ?? 'production';
|
|
78
|
+
const sendForReview = opts.sendForReview ?? track === 'production';
|
|
79
|
+
const { play, packageName } = createPlayClient(config);
|
|
80
|
+
|
|
81
|
+
// beta/production require release notes + status 'completed'; internal accepts draft.
|
|
82
|
+
const completed = track === 'beta' || track === 'production';
|
|
83
|
+
const release = completed
|
|
84
|
+
? {
|
|
85
|
+
name: `${opts.version} (${versionCode})`,
|
|
86
|
+
versionCodes: [String(versionCode)],
|
|
87
|
+
status: 'completed' as const,
|
|
88
|
+
releaseNotes: releaseNotesFor(config),
|
|
89
|
+
}
|
|
90
|
+
: { versionCodes: [String(versionCode)], status: 'draft' as const };
|
|
91
|
+
|
|
92
|
+
console.log(` Assigning to ${track} track…`);
|
|
93
|
+
try {
|
|
94
|
+
await play.edits.tracks.update({ packageName, editId, track, requestBody: { track, releases: [release] } });
|
|
95
|
+
try {
|
|
96
|
+
await play.edits.commit({ packageName, editId, changesNotSentForReview: !sendForReview });
|
|
97
|
+
console.log(` ✓ Android upload complete${sendForReview ? ' (sent for review).' : ' (not sent for review).'}`);
|
|
98
|
+
} catch (err: any) {
|
|
99
|
+
const body = err?.message ?? '';
|
|
100
|
+
if (sendForReview && String(body).includes('changesNotSentForReview must not be set')) {
|
|
101
|
+
console.log(' Play auto-sends edits for review; retrying without the flag.');
|
|
102
|
+
await play.edits.commit({ packageName, editId });
|
|
103
|
+
console.log(' ✓ Android upload complete (sent for review by Google auto-send mode).');
|
|
104
|
+
} else {
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (!completed || !(error instanceof Error) || !error.message.includes('Only releases with status draft may be created on draft app')) throw error;
|
|
110
|
+
// Google can reject the track update or the final commit. Preserve the
|
|
111
|
+
// requested track and report the saved draft as an incomplete release.
|
|
112
|
+
await play.edits.tracks.update({ packageName, editId, track, requestBody: { track, releases: [{ ...release, status: 'draft' }] } });
|
|
113
|
+
await play.edits.commit({ packageName, editId });
|
|
114
|
+
throw new PlayConsoleRequiredError(versionCode, track);
|
|
115
|
+
}
|
|
116
|
+
}
|