react-native-update-cli 2.24.1 → 2.25.0

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.
Files changed (95) hide show
  1. package/README.md +11 -4
  2. package/README.zh-CN.md +11 -4
  3. package/cli.json +7 -1
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.js +63 -18
  6. package/lib/app.js +25 -3
  7. package/lib/bin.js +39 -45
  8. package/lib/bundle-runner.d.ts +27 -0
  9. package/lib/bundle-runner.js +240 -21
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +19 -6
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +5 -14
  15. package/lib/locales/en.js +5 -14
  16. package/lib/locales/zh.d.ts +5 -13
  17. package/lib/locales/zh.js +5 -13
  18. package/lib/package.js +4 -0
  19. package/lib/provider.d.ts +1 -1
  20. package/lib/provider.js +3 -1
  21. package/lib/symbolicate.js +11 -3
  22. package/lib/types.d.ts +1 -0
  23. package/lib/user.js +6 -0
  24. package/lib/utils/add-gitignore.js +7 -1
  25. package/lib/utils/dep-versions.d.ts +7 -0
  26. package/lib/utils/dep-versions.js +78 -26
  27. package/lib/utils/git.js +9 -6
  28. package/lib/utils/hermes-base.js +2 -1
  29. package/lib/utils/i18n.d.ts +5 -0
  30. package/lib/utils/i18n.js +14 -1
  31. package/lib/utils/index.d.ts +2 -1
  32. package/lib/utils/index.js +9 -4
  33. package/lib/utils/latest-version/index.js +8 -0
  34. package/lib/utils/runtime.d.ts +21 -0
  35. package/lib/utils/runtime.js +138 -5
  36. package/lib/utils/slim-sourcemap.d.ts +11 -0
  37. package/lib/utils/slim-sourcemap.js +22 -0
  38. package/lib/utils/zip-range.js +3 -2
  39. package/lib/versions.js +16 -15
  40. package/package.json +4 -2
  41. package/lib/index.d.ts +0 -1
  42. package/lib/index.js +0 -17
  43. package/src/api.ts +0 -470
  44. package/src/app.ts +0 -241
  45. package/src/auto-update.ts +0 -647
  46. package/src/bin-cresc.ts +0 -8
  47. package/src/bin.ts +0 -115
  48. package/src/bundle-pack.ts +0 -61
  49. package/src/bundle-runner.ts +0 -1430
  50. package/src/bundle.ts +0 -371
  51. package/src/cache.ts +0 -20
  52. package/src/diff.ts +0 -1010
  53. package/src/exports.ts +0 -17
  54. package/src/index.ts +0 -1
  55. package/src/install.ts +0 -50
  56. package/src/locales/en.ts +0 -257
  57. package/src/locales/zh.ts +0 -234
  58. package/src/native-package.ts +0 -338
  59. package/src/package.ts +0 -482
  60. package/src/provider.ts +0 -294
  61. package/src/symbolicate.ts +0 -159
  62. package/src/types.ts +0 -150
  63. package/src/user.ts +0 -39
  64. package/src/utils/add-gitignore.ts +0 -35
  65. package/src/utils/app-info-parser/aab.ts +0 -241
  66. package/src/utils/app-info-parser/apk.ts +0 -92
  67. package/src/utils/app-info-parser/app.ts +0 -7
  68. package/src/utils/app-info-parser/index.ts +0 -54
  69. package/src/utils/app-info-parser/ipa.ts +0 -109
  70. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  71. package/src/utils/app-info-parser/utils.ts +0 -161
  72. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  73. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  74. package/src/utils/app-info-parser/zip.ts +0 -108
  75. package/src/utils/check-lockfile.ts +0 -93
  76. package/src/utils/check-plugin.ts +0 -38
  77. package/src/utils/command-result.ts +0 -24
  78. package/src/utils/constants.ts +0 -25
  79. package/src/utils/dep-versions.ts +0 -83
  80. package/src/utils/git.ts +0 -71
  81. package/src/utils/hbcTransform.ts +0 -649
  82. package/src/utils/hermes-base.ts +0 -1137
  83. package/src/utils/http-helper.ts +0 -152
  84. package/src/utils/i18n.ts +0 -39
  85. package/src/utils/index.ts +0 -698
  86. package/src/utils/latest-version/index.ts +0 -573
  87. package/src/utils/options.ts +0 -78
  88. package/src/utils/plugin-config.ts +0 -32
  89. package/src/utils/runtime.ts +0 -187
  90. package/src/utils/slim-sourcemap.ts +0 -83
  91. package/src/utils/zip-entries.ts +0 -209
  92. package/src/utils/zip-options.ts +0 -178
  93. package/src/utils/zip-range.ts +0 -727
  94. package/src/utils/zip-raw-writer.ts +0 -247
  95. package/src/versions.ts +0 -894
package/src/provider.ts DELETED
@@ -1,294 +0,0 @@
1
- import { getSession, loadSession } from './api';
2
- import { getPlatform, getSelectedApp } from './app';
3
- import type {
4
- BundleOptions,
5
- CLIProvider,
6
- CommandContext,
7
- CommandResult,
8
- Platform,
9
- PublishOptions,
10
- Session,
11
- SymbolicateOptions,
12
- UpdateVersionOptions,
13
- UploadOptions,
14
- } from './types';
15
- import { runAsCommandResult } from './utils/command-result';
16
- import { t } from './utils/i18n';
17
-
18
- const DEFAULT_BUNDLE_OUTPUT =
19
- '$' + '{tempDir}/output/$' + '{platform}.$' + '{time}.ppk';
20
-
21
- export class CLIProviderImpl implements CLIProvider {
22
- private session?: Session;
23
- private sessionInitPromise?: Promise<void>;
24
-
25
- private createContext(
26
- options: Record<string, unknown>,
27
- args: string[] = [],
28
- ): CommandContext {
29
- return { args, options };
30
- }
31
-
32
- private async ensureInitialized(): Promise<void> {
33
- if (this.session) {
34
- return;
35
- }
36
-
37
- if (!this.sessionInitPromise) {
38
- this.sessionInitPromise = (async () => {
39
- await loadSession();
40
- this.session = getSession();
41
- })().finally(() => {
42
- this.sessionInitPromise = undefined;
43
- });
44
- }
45
-
46
- await this.sessionInitPromise;
47
- }
48
-
49
- private runMessageCommand(
50
- task: () => Promise<void>,
51
- fallbackError: string,
52
- successMessage: string,
53
- requireSession = true,
54
- ): Promise<CommandResult> {
55
- return runAsCommandResult(
56
- async () => {
57
- if (requireSession) {
58
- await this.ensureInitialized();
59
- }
60
- await task();
61
- },
62
- fallbackError,
63
- () => ({ message: successMessage }),
64
- );
65
- }
66
-
67
- private runDataCommand<T>(
68
- task: () => Promise<T>,
69
- fallbackError: string,
70
- requireSession = true,
71
- ): Promise<CommandResult> {
72
- return runAsCommandResult(async () => {
73
- if (requireSession) {
74
- await this.ensureInitialized();
75
- }
76
- return task();
77
- }, fallbackError);
78
- }
79
-
80
- async bundle(options: BundleOptions): Promise<CommandResult> {
81
- return this.runMessageCommand(
82
- async () => {
83
- const context = this.createContext({
84
- dev: options.dev || false,
85
- platform: options.platform,
86
- bundleName: options.bundleName || 'index.bundlejs',
87
- entryFile: options.entryFile || 'index.js',
88
- output: options.output || DEFAULT_BUNDLE_OUTPUT,
89
- 'no-interactive': true,
90
- sourcemap: options.sourcemap || false,
91
- taro: options.taro || false,
92
- expo: options.expo || false,
93
- rncli: options.rncli || false,
94
- hermes: options.hermes || false,
95
- hermesBase: options.hermesBase || 'auto',
96
- verifyHermesBase: options.verifyHermesBase ?? true,
97
- sentryRelease: options.sentryRelease,
98
- sentryDist: options.sentryDist,
99
- appId: options.appId,
100
- config: options.config,
101
- });
102
-
103
- const { bundleCommands } = await import('./bundle');
104
- await bundleCommands.bundle(context);
105
- },
106
- 'Unknown error during bundling',
107
- 'Bundle created successfully',
108
- false,
109
- );
110
- }
111
-
112
- async publish(options: PublishOptions): Promise<CommandResult> {
113
- return this.runMessageCommand(
114
- async () => {
115
- const context = this.createContext(
116
- {
117
- name: options.name,
118
- description: options.description,
119
- metaInfo: options.metaInfo,
120
- packageId: options.packageId,
121
- packageVersion: options.packageVersion,
122
- minPackageVersion: options.minPackageVersion,
123
- maxPackageVersion: options.maxPackageVersion,
124
- packageVersionRange: options.packageVersionRange,
125
- platform: options.platform,
126
- appId: options.appId,
127
- config: options.config,
128
- 'no-interactive': true,
129
- rollout:
130
- options.rollout === undefined
131
- ? undefined
132
- : String(options.rollout),
133
- dryRun: options.dryRun || false,
134
- sourcemap: options.sourcemap,
135
- },
136
- options.filePath ? [options.filePath] : [],
137
- );
138
-
139
- const { versionCommands } = await import('./versions');
140
- await versionCommands.publish(context);
141
- },
142
- 'Unknown error during publishing',
143
- 'Version published successfully',
144
- );
145
- }
146
-
147
- async symbolicate(options: SymbolicateOptions): Promise<CommandResult> {
148
- return this.runMessageCommand(
149
- async () => {
150
- const context = this.createContext(
151
- {
152
- hash: options.hash,
153
- versionId: options.versionId,
154
- platform: options.platform,
155
- appId: options.appId,
156
- config: options.config,
157
- output: options.output,
158
- },
159
- options.stackFile ? [options.stackFile] : [],
160
- );
161
- const { symbolicateCommands } = await import('./symbolicate');
162
- await symbolicateCommands.symbolicate(context);
163
- },
164
- 'Unknown error during symbolication',
165
- 'Stack symbolicated',
166
- );
167
- }
168
-
169
- async upload(options: UploadOptions): Promise<CommandResult> {
170
- return this.runMessageCommand(
171
- async () => {
172
- const filePath = options.filePath;
173
- const fileType = filePath.split('.').pop()?.toLowerCase();
174
-
175
- const context = this.createContext(
176
- {
177
- platform: options.platform,
178
- appId: options.appId,
179
- appKey: options.appKey,
180
- version: options.version,
181
- config: options.config,
182
- },
183
- [filePath],
184
- );
185
-
186
- const { packageCommands } = await import('./package');
187
- const uploadHandlerMap = {
188
- ipa: packageCommands.uploadIpa,
189
- apk: packageCommands.uploadApk,
190
- aab: packageCommands.uploadAab,
191
- app: packageCommands.uploadApp,
192
- } as const;
193
- const uploadHandler =
194
- fileType && fileType in uploadHandlerMap
195
- ? uploadHandlerMap[fileType as keyof typeof uploadHandlerMap]
196
- : undefined;
197
-
198
- if (!uploadHandler) {
199
- throw new Error(t('unsupportedFileType', { fileType }));
200
- }
201
- await uploadHandler(context);
202
- },
203
- 'Unknown error during upload',
204
- 'File uploaded successfully',
205
- );
206
- }
207
-
208
- async getSelectedApp(
209
- platform?: Platform,
210
- config?: string,
211
- ): Promise<{ appId: string; platform: Platform }> {
212
- const resolvedPlatform = await this.getPlatform(platform);
213
- return getSelectedApp(resolvedPlatform, config);
214
- }
215
-
216
- async listApps(platform?: Platform): Promise<CommandResult> {
217
- return this.runDataCommand(async () => {
218
- const { getAppCommands } = await import('./app');
219
- return getAppCommands().apps({
220
- options: { platform: platform ?? '' },
221
- });
222
- }, 'Unknown error listing apps');
223
- }
224
-
225
- async createApp(name: string, platform: Platform): Promise<CommandResult> {
226
- return this.runMessageCommand(
227
- async () => {
228
- const { getAppCommands } = await import('./app');
229
- await getAppCommands().createApp({
230
- options: {
231
- name,
232
- platform,
233
- downloadUrl: '',
234
- },
235
- });
236
- },
237
- 'Unknown error creating app',
238
- 'App created successfully',
239
- );
240
- }
241
-
242
- async listVersions(appId: string): Promise<CommandResult> {
243
- return this.runDataCommand(async () => {
244
- const { fetchVersions } = await import('./versions');
245
- return fetchVersions(appId);
246
- }, 'Unknown error listing versions');
247
- }
248
-
249
- async updateVersion(
250
- appId: string,
251
- versionId: string,
252
- updates: UpdateVersionOptions,
253
- ): Promise<CommandResult> {
254
- return this.runMessageCommand(
255
- async () => {
256
- const context = this.createContext({
257
- appId,
258
- versionId,
259
- ...updates,
260
- 'no-interactive': true,
261
- rollout:
262
- updates.rollout === undefined ? undefined : String(updates.rollout),
263
- });
264
-
265
- const { versionCommands } = await import('./versions');
266
- await versionCommands.update(context);
267
- },
268
- 'Unknown error updating version',
269
- 'Version updated successfully',
270
- );
271
- }
272
-
273
- async getPlatform(platform?: Platform): Promise<Platform> {
274
- return getPlatform(platform);
275
- }
276
-
277
- async loadSession(): Promise<Session> {
278
- await this.ensureInitialized();
279
- if (!this.session) {
280
- throw new Error(t('failedToLoadSession'));
281
- }
282
- return this.session;
283
- }
284
-
285
- async listPackages(appId?: string): Promise<CommandResult> {
286
- return this.runDataCommand(async () => {
287
- if (!appId) {
288
- throw new Error(t('appIdRequired'));
289
- }
290
- const { listPackage } = await import('./package');
291
- return listPackage(appId);
292
- }, 'Unknown error listing packages');
293
- }
294
- }
@@ -1,159 +0,0 @@
1
- import fs from 'fs';
2
- import fetch from 'node-fetch';
3
- import { SourceMapConsumer } from 'source-map';
4
- import { get } from './api';
5
- import { getPlatform, getSelectedApp } from './app';
6
- import type { Platform, Version } from './types';
7
- import { t } from './utils/i18n';
8
- import { fetchVersions } from './versions';
9
-
10
- // A frame location inside a shipped bundle: `<bundle>:<line>:<column>`. Covers
11
- // `index.bundlejs`, `index.android.bundle`, `main.jsbundle`, `bundle.harmony.js`
12
- // and plain `.js`/`.hbc` names; an optional `address at ` prefix marks a
13
- // Hermes bytecode frame (column = bytecode offset, already 0-based).
14
- const FRAME_PATTERN =
15
- /(address at )?((?:[\w.-]+\/)*[\w.-]+\.(?:bundlejs|jsbundle|bundle|hbc|js))(?:\?[^\s:)]*)?:(\d+):(\d+)/g;
16
-
17
- export interface FrameConsumer {
18
- originalPositionFor(position: { line: number; column: number }): {
19
- source?: string | null;
20
- line?: number | null;
21
- column?: number | null;
22
- name?: string | null;
23
- };
24
- }
25
-
26
- /**
27
- * Rewrites every bundle frame of `stack` to its original source position.
28
- * JS engines report 1-based columns, so they are shifted to the 0-based
29
- * columns source maps use; Hermes bytecode frames (`address at`) carry the
30
- * bytecode offset, which the composed hermes map keys directly.
31
- */
32
- export function symbolicateStack(
33
- stack: string,
34
- consumer: FrameConsumer,
35
- ): { text: string; mapped: number } {
36
- let mapped = 0;
37
- const text = stack.replace(
38
- FRAME_PATTERN,
39
- (
40
- frame,
41
- hermes: string | undefined,
42
- _bundle,
43
- line: string,
44
- column: string,
45
- ) => {
46
- const position = consumer.originalPositionFor({
47
- line: Number(line),
48
- column: hermes ? Number(column) : Math.max(0, Number(column) - 1),
49
- });
50
- if (
51
- !position.source ||
52
- position.line === null ||
53
- position.line === undefined
54
- ) {
55
- return frame;
56
- }
57
- mapped++;
58
- const original = `${position.source}:${position.line}:${(position.column ?? 0) + 1}`;
59
- return position.name ? `${original} (${position.name})` : original;
60
- },
61
- );
62
- return { text, mapped };
63
- }
64
-
65
- async function findVersionByHash(
66
- appId: string,
67
- hash: string,
68
- ): Promise<Version | undefined> {
69
- const limit = 100;
70
- // The list is newest-first; crashes are usually about recent versions.
71
- for (let offset = 0; offset < 100 * limit; offset += limit) {
72
- const page = await fetchVersions(appId, offset, limit);
73
- const found = page.find((version) => version.hash === hash);
74
- if (found) {
75
- return found;
76
- }
77
- if (page.length < limit) {
78
- return undefined;
79
- }
80
- }
81
- return undefined;
82
- }
83
-
84
- async function readStack(source: string | undefined): Promise<string> {
85
- if (!source || source === '-') {
86
- return new Promise((resolve, reject) => {
87
- const chunks: Buffer[] = [];
88
- process.stdin.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
89
- process.stdin.on('end', () =>
90
- resolve(Buffer.concat(chunks).toString('utf8')),
91
- );
92
- process.stdin.on('error', reject);
93
- });
94
- }
95
- return fs.readFileSync(source, 'utf8');
96
- }
97
-
98
- export const symbolicateCommands = {
99
- symbolicate: async ({
100
- args,
101
- options,
102
- }: {
103
- args: string[];
104
- options: Record<string, unknown>;
105
- }) => {
106
- const hash = typeof options.hash === 'string' ? options.hash : '';
107
- const versionIdOption =
108
- typeof options.versionId === 'string' ? options.versionId : '';
109
- if (!hash && !versionIdOption) {
110
- throw new Error(t('symbolicateUsage'));
111
- }
112
- const platform = await getPlatform(
113
- typeof options.platform === 'string'
114
- ? (options.platform as Platform)
115
- : undefined,
116
- );
117
- const appId =
118
- typeof options.appId === 'string' && options.appId
119
- ? options.appId
120
- : (await getSelectedApp(platform, options.config as string | undefined))
121
- .appId;
122
-
123
- let versionId = versionIdOption;
124
- if (!versionId) {
125
- const version = await findVersionByHash(appId, hash);
126
- if (!version) {
127
- throw new Error(t('symbolicateVersionNotFound', { hash }));
128
- }
129
- versionId = String(version.id);
130
- }
131
-
132
- const located = await get(`/app/${appId}/version/${versionId}/sourceMap`);
133
- if (!located?.url) {
134
- throw new Error(t('symbolicateNoSourceMap', { id: versionId }));
135
- }
136
- const response = await fetch(located.url);
137
- if (!response.ok) {
138
- throw new Error(`Failed to download source map: HTTP ${response.status}`);
139
- }
140
- const rawMap = JSON.parse(await response.text());
141
- const consumer = new SourceMapConsumer(rawMap);
142
-
143
- const stack = await readStack(args[0]);
144
- const { text, mapped } = symbolicateStack(stack, consumer);
145
- if (typeof options.output === 'string' && options.output) {
146
- fs.writeFileSync(options.output, text);
147
- } else {
148
- process.stdout.write(text.endsWith('\n') ? text : `${text}\n`);
149
- }
150
- console.error(
151
- t('symbolicateDone', {
152
- count: mapped,
153
- id: versionId,
154
- hash: located.hash ?? hash,
155
- }),
156
- );
157
- return { versionId, mapped };
158
- },
159
- };
package/src/types.ts DELETED
@@ -1,150 +0,0 @@
1
- declare global {
2
- var NO_INTERACTIVE: boolean | undefined;
3
- var USE_ACC_OSS: boolean | undefined;
4
- }
5
-
6
- export interface Session {
7
- token: string;
8
- }
9
-
10
- export type Platform = 'ios' | 'android' | 'harmony';
11
-
12
- export interface Package {
13
- // server-side ids are numeric (auto-increment primary keys)
14
- id: number;
15
- name: string;
16
- version?: string;
17
- status?: string;
18
- appId?: string;
19
- appKey?: string;
20
- versionName?: string | number | null;
21
- buildTime?: string | number | null;
22
- deps?: Record<string, string> | string | null;
23
- }
24
-
25
- export interface Version {
26
- id: number;
27
- hash: string;
28
- name: string;
29
- packages?: Package[];
30
- deps?: Record<string, string> | string | null;
31
- /** storage key of the archived source map (absent when published without one) */
32
- sourceMapKey?: string;
33
- }
34
-
35
- export interface CommandContext<
36
- TOptions extends Record<string, unknown> = Record<string, unknown>,
37
- > {
38
- args: string[];
39
- options: TOptions;
40
- platform?: Platform;
41
- appId?: string;
42
- session?: Session;
43
- }
44
-
45
- export interface CommandResult {
46
- success: boolean;
47
- data?: unknown;
48
- error?: string;
49
- }
50
-
51
- export interface BundleOptions {
52
- dev?: boolean;
53
- platform?: Platform;
54
- bundleName?: string;
55
- entryFile?: string;
56
- output?: string;
57
- sourcemap?: boolean;
58
- taro?: boolean;
59
- expo?: boolean;
60
- rncli?: boolean;
61
- hermes?: boolean;
62
- /** 'auto' (default) | 'none' | path to a .hbc/.ppk/.apk/.ipa used as hermesc -base-bytecode */
63
- hermesBase?: string;
64
- /** run the disassembly equivalence check after a base compile (default true) */
65
- verifyHermesBase?: boolean;
66
- /** pass --reset-cache to Metro (default true); false reuses its transform cache */
67
- resetCache?: boolean;
68
- sentryRelease?: string;
69
- sentryDist?: string;
70
- /** publish to this app instead of the one selected in the config file */
71
- appId?: string;
72
- /** selected-app config file (default: update.json) */
73
- config?: string;
74
- }
75
-
76
- export interface PublishOptions {
77
- filePath?: string;
78
- /** path of the final source map to archive with the version */
79
- sourcemap?: string;
80
- platform?: Platform;
81
- name?: string;
82
- description?: string;
83
- metaInfo?: string;
84
- packageId?: string;
85
- packageVersion?: string;
86
- minPackageVersion?: string;
87
- maxPackageVersion?: string;
88
- packageVersionRange?: string;
89
- rollout?: number | string;
90
- dryRun?: boolean;
91
- appId?: string;
92
- config?: string;
93
- }
94
-
95
- export interface UploadOptions {
96
- platform?: Platform;
97
- filePath: string;
98
- appId?: string;
99
- appKey?: string;
100
- version?: string;
101
- config?: string;
102
- }
103
-
104
- export interface UpdateVersionOptions {
105
- platform?: Platform;
106
- packageId?: string;
107
- packageVersion?: string;
108
- minPackageVersion?: string;
109
- maxPackageVersion?: string;
110
- packageVersionRange?: string;
111
- rollout?: number | string;
112
- dryRun?: boolean;
113
- }
114
-
115
- export interface SymbolicateOptions {
116
- /** stack trace file ('-' for stdin) */
117
- stackFile?: string;
118
- /** update hash of the running version (from getUpdateMetadata().currentVersion) */
119
- hash?: string;
120
- versionId?: string;
121
- platform?: Platform;
122
- appId?: string;
123
- config?: string;
124
- /** write the symbolicated stack here instead of stdout */
125
- output?: string;
126
- }
127
-
128
- export interface CLIProvider {
129
- bundle: (options: BundleOptions) => Promise<CommandResult>;
130
- publish: (options: PublishOptions) => Promise<CommandResult>;
131
- symbolicate: (options: SymbolicateOptions) => Promise<CommandResult>;
132
- upload: (options: UploadOptions) => Promise<CommandResult>;
133
-
134
- createApp: (name: string, platform: Platform) => Promise<CommandResult>;
135
- listApps: (platform?: Platform) => Promise<CommandResult>;
136
- getSelectedApp: (
137
- platform?: Platform,
138
- config?: string,
139
- ) => Promise<{ appId: string; platform: Platform }>;
140
-
141
- listVersions: (appId: string) => Promise<CommandResult>;
142
- updateVersion: (
143
- appId: string,
144
- versionId: string,
145
- updates: UpdateVersionOptions,
146
- ) => Promise<CommandResult>;
147
-
148
- getPlatform: (platform?: Platform) => Promise<Platform>;
149
- loadSession: () => Promise<Session>;
150
- }
package/src/user.ts DELETED
@@ -1,39 +0,0 @@
1
- import crypto from 'crypto';
2
- import { closeSession, get, post, replaceSession, saveSession } from './api';
3
- import type { CommandContext } from './types';
4
- import { question } from './utils';
5
- import { addGitIgnore } from './utils/add-gitignore';
6
- import { t } from './utils/i18n';
7
-
8
- function md5(str: string) {
9
- return crypto.createHash('md5').update(str).digest('hex');
10
- }
11
-
12
- export const userCommands = {
13
- login: async ({ args }: { args: string[] }) => {
14
- const email = args[0] || (await question('email:'));
15
- const pwd = args[1] || (await question('password:', true));
16
- const { token, info } = await post('/user/login', {
17
- email,
18
- pwd: md5(pwd),
19
- });
20
- replaceSession({ token });
21
- await saveSession();
22
- // make sure the token file is ignored before the user's next commit,
23
- // not only when they first run `bundle`
24
- addGitIgnore();
25
- console.log(t('welcomeMessage', { name: info.name }));
26
- },
27
- logout: async (_context: CommandContext) => {
28
- await closeSession();
29
- console.log(t('loggedOut'));
30
- },
31
- me: async () => {
32
- const me = await get('/user/me');
33
- for (const k in me) {
34
- if (k !== 'ok') {
35
- console.log(`${k}: ${me[k]}`);
36
- }
37
- }
38
- },
39
- };
@@ -1,35 +0,0 @@
1
- import fs from 'fs';
2
- // import path from 'path';
3
- import { credentialFile, tempDir } from './constants';
4
- import { t } from './i18n';
5
-
6
- export function addGitIgnore() {
7
- const shouldIgnore = [credentialFile, tempDir];
8
-
9
- const gitignorePath = '.gitignore';
10
-
11
- if (!fs.existsSync(gitignorePath)) {
12
- return;
13
- }
14
-
15
- const gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
16
-
17
- const gitignoreLines = gitignoreContent.split('\n');
18
-
19
- for (const line of gitignoreLines) {
20
- const index = shouldIgnore.indexOf(line.trim());
21
- if (index !== -1) {
22
- shouldIgnore.splice(index, 1);
23
- }
24
- }
25
-
26
- if (shouldIgnore.length > 0) {
27
- gitignoreLines.push('# react-native-update');
28
- for (const line of shouldIgnore) {
29
- gitignoreLines.push(line);
30
- console.log(t('addedToGitignore', { line }));
31
- }
32
-
33
- fs.writeFileSync(gitignorePath, gitignoreLines.join('\n'));
34
- }
35
- }