@devvit/cli 0.11.17-next-2025-06-16-17-18-06-5f55b09e2.0 → 0.11.17
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/bin/devvit.js +0 -3
- package/dist/commands/playtest.d.ts +1 -1
- package/dist/commands/playtest.d.ts.map +1 -1
- package/dist/commands/playtest.js +45 -65
- package/dist/commands/upload.d.ts.map +1 -1
- package/dist/commands/upload.js +6 -57
- package/dist/lib/http/gql.d.ts +0 -7
- package/dist/lib/http/gql.d.ts.map +1 -1
- package/dist/lib/http/gql.js +9 -32
- package/dist/util/AssetUploader.d.ts +3 -3
- package/dist/util/AssetUploader.d.ts.map +1 -1
- package/dist/util/AssetUploader.js +44 -64
- package/dist/util/AssetUploader.test.js +9 -19
- package/dist/util/project.d.ts +0 -6
- package/dist/util/project.d.ts.map +1 -1
- package/dist/util/project.js +0 -31
- package/dist/util/project.test.js +0 -13
- package/package.json +8 -9
- package/dist/util/common-actions/installOnSubreddit.d.ts +0 -4
- package/dist/util/common-actions/installOnSubreddit.d.ts.map +0 -1
- package/dist/util/common-actions/installOnSubreddit.js +0 -14
- package/dist/util/common-actions/waitUntilVersionBuildComplete.d.ts +0 -4
- package/dist/util/common-actions/waitUntilVersionBuildComplete.d.ts.map +0 -1
- package/dist/util/common-actions/waitUntilVersionBuildComplete.js +0 -23
package/bin/devvit.js
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import { StringUtil } from '@devvit/shared-types/StringUtil.js';
|
|
5
5
|
import { Errors, flush, run } from '@oclif/core';
|
|
6
|
-
import { config as dotenvConfig } from 'dotenv';
|
|
7
6
|
|
|
8
7
|
import { getCurrentCommandEventData } from '../dist/lib/hooks/init/fire-event.js';
|
|
9
8
|
import { sendEvent } from '../dist/util/metrics.js';
|
|
10
9
|
|
|
11
|
-
dotenvConfig();
|
|
12
|
-
|
|
13
10
|
run(undefined, import.meta.url)
|
|
14
11
|
.then(() => flush())
|
|
15
12
|
.catch(async (err) => {
|
|
@@ -17,7 +17,7 @@ export default class Playtest extends DevvitCommand {
|
|
|
17
17
|
readonly verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
18
18
|
};
|
|
19
19
|
static args: {
|
|
20
|
-
readonly subreddit: import("@oclif/core/lib/interfaces/parser.js").Arg<string
|
|
20
|
+
readonly subreddit: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
21
21
|
};
|
|
22
22
|
run(): Promise<void>;
|
|
23
23
|
protected init(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playtest.d.ts","sourceRoot":"","sources":["../../src/commands/playtest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"playtest.d.ts","sourceRoot":"","sources":["../../src/commands/playtest.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAMlE,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,aAAa;;IACjD,OAAgB,WAAW,SACgK;IAE3L,OAAgB,QAAQ,WAItB;IAEF,OAAgB,KAAK;;;;;;;;;;;;MAoBV;IAEX,OAAgB,IAAI;;MAMT;IAkFI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;cA+GV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA6P/C"}
|
|
@@ -9,9 +9,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _Playtest_instances, _a, _Playtest_installationsClient, _Playtest_appClient, _Playtest_appVersionClient, _Playtest_bundler, _Playtest_subreddit, _Playtest_flags, _Playtest_appInfo, _Playtest_version, _Playtest_installationInfo, _Playtest_lastBundles, _Playtest_lastQueuedBundles, _Playtest_isOnWatchExecuting, _Playtest_appLogSub, _Playtest_watchSrc, _Playtest_watchAssets, _Playtest_watchConfigFile, _Playtest_server, _Playtest_getExistingInstallInfo, _Playtest_startWatchingSrc, _Playtest_startWatchingAssets, _Playtest_startWatchingConfigFile, _Playtest_onWatch, _Playtest_onWatchActual, _Playtest_onWatchError, _Playtest_runQueuedBundlePlaytest, _Playtest_checkIfUserAllowedToPlaytestThisApp, _Playtest_onExit;
|
|
12
|
+
var _Playtest_instances, _a, _Playtest_installationsClient, _Playtest_appClient, _Playtest_appVersionClient, _Playtest_bundler, _Playtest_subreddit, _Playtest_flags, _Playtest_appInfo, _Playtest_version, _Playtest_installationInfo, _Playtest_lastBundles, _Playtest_lastQueuedBundles, _Playtest_isOnWatchExecuting, _Playtest_appLogSub, _Playtest_watchSrc, _Playtest_watchAssets, _Playtest_watchConfigFile, _Playtest_server, _Playtest_getExistingInstallInfo, _Playtest_waitUntilVersionBuildComplete, _Playtest_startWatchingSrc, _Playtest_startWatchingAssets, _Playtest_startWatchingConfigFile, _Playtest_onWatch, _Playtest_onWatchActual, _Playtest_onWatchError, _Playtest_runQueuedBundlePlaytest, _Playtest_checkIfUserAllowedToPlaytestThisApp, _Playtest_onExit;
|
|
13
13
|
import { updateBundleServer, updateBundleVersion } from '@devvit/build-pack/esbuild/ESBuildPack.js';
|
|
14
|
-
import { InstallationType, VersionVisibility } from '@devvit/protos/community.js';
|
|
14
|
+
import { BuildStatus, InstallationType, VersionVisibility, } from '@devvit/protos/community.js';
|
|
15
15
|
import { ACTOR_SRC_DIR, ACTOR_SRC_PRIMARY_NAME, MAX_ALLOWED_SUBSCRIBER_COUNT, PRODUCTS_JSON_FILE, } from '@devvit/shared-types/constants.js';
|
|
16
16
|
import { debounce } from '@devvit/shared-types/debounce.js';
|
|
17
17
|
import { StringUtil } from '@devvit/shared-types/StringUtil.js';
|
|
@@ -34,8 +34,6 @@ import { createAppClient, createAppVersionClient, createInstallationsClient, } f
|
|
|
34
34
|
import { toLowerCaseArgParser } from '../util/commands/DevvitCommand.js';
|
|
35
35
|
import { DevvitCommand } from '../util/commands/DevvitCommand.js';
|
|
36
36
|
import { getSubredditNameWithoutPrefix } from '../util/common-actions/getSubredditNameWithoutPrefix.js';
|
|
37
|
-
import { installOnSubreddit } from '../util/common-actions/installOnSubreddit.js';
|
|
38
|
-
import { waitUntilVersionBuildComplete } from '../util/common-actions/waitUntilVersionBuildComplete.js';
|
|
39
37
|
import { getAppBySlug } from '../util/getAppBySlug.js';
|
|
40
38
|
import { Project } from '../util/project.js';
|
|
41
39
|
import Logs from './logs.js';
|
|
@@ -119,15 +117,14 @@ class Playtest extends DevvitCommand {
|
|
|
119
117
|
appSlug: __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.slug,
|
|
120
118
|
appSemver: __classPrivateFieldGet(this, _Playtest_version, "f"),
|
|
121
119
|
visibility: VersionVisibility.PRIVATE,
|
|
122
|
-
}, __classPrivateFieldGet(this, _Playtest_lastBundles, "f")
|
|
123
|
-
);
|
|
120
|
+
}, __classPrivateFieldGet(this, _Playtest_lastBundles, "f"));
|
|
124
121
|
if (__classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f")) {
|
|
125
122
|
// No need to go further if there's a newer playtest version is waiting
|
|
126
123
|
__classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_runQueuedBundlePlaytest).call(this, __classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f"));
|
|
127
124
|
return;
|
|
128
125
|
}
|
|
129
126
|
// 5. confirm new version has finished building
|
|
130
|
-
await
|
|
127
|
+
await __classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_waitUntilVersionBuildComplete).call(this, appVersionInfo);
|
|
131
128
|
if (__classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f")) {
|
|
132
129
|
// No need to go further if there's a newer playtest version is waiting
|
|
133
130
|
__classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_runQueuedBundlePlaytest).call(this, __classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f"));
|
|
@@ -163,8 +160,8 @@ class Playtest extends DevvitCommand {
|
|
|
163
160
|
});
|
|
164
161
|
const { args, flags } = await this.parse(_a);
|
|
165
162
|
__classPrivateFieldSet(this, _Playtest_flags, flags, "f");
|
|
163
|
+
__classPrivateFieldSet(this, _Playtest_subreddit, getSubredditNameWithoutPrefix(args.subreddit), "f");
|
|
166
164
|
this.project.flag.watchDebounceMillis = __classPrivateFieldGet(this, _Playtest_flags, "f")?.['debounce'];
|
|
167
|
-
this.project.flag.subreddit = args.subreddit;
|
|
168
165
|
const token = await getAccessTokenAndLoginIfNeeded();
|
|
169
166
|
const username = await this.getUserDisplayName(token);
|
|
170
167
|
await this.checkDeveloperAccount();
|
|
@@ -184,65 +181,28 @@ class Playtest extends DevvitCommand {
|
|
|
184
181
|
if (!__classPrivateFieldGet(this, _Playtest_appInfo, "f")?.app) {
|
|
185
182
|
this.error("Your app doesn't exist yet - you'll need to run 'devvit upload' before you can playtest your app.");
|
|
186
183
|
}
|
|
187
|
-
this.project.app.defaultPlaytestSubredditId = __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.defaultPlaytestSubredditId;
|
|
188
184
|
const isOwner = __classPrivateFieldGet(this, _Playtest_appInfo, "f")?.app?.owner?.displayName === username;
|
|
189
185
|
await __classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_checkIfUserAllowedToPlaytestThisApp).call(this, this.project.name, isOwner, token, flags['employee-update']);
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
__classPrivateFieldSet(this, _Playtest_subreddit, getSubredditNameWithoutPrefix(targetSubreddit), "f");
|
|
186
|
+
// alert user if they're about to run playtest in a large subreddit
|
|
187
|
+
const subscriberCount = await fetchSubredditSubscriberCount(__classPrivateFieldGet(this, _Playtest_subreddit, "f"), token);
|
|
188
|
+
if (subscriberCount > MAX_ALLOWED_SUBSCRIBER_COUNT) {
|
|
189
|
+
this.error(`Playtest can only be used in a small test subreddit. Please try again in a community with less than ${MAX_ALLOWED_SUBSCRIBER_COUNT} members.`);
|
|
195
190
|
}
|
|
196
|
-
const
|
|
197
|
-
let latestVersion = __classPrivateFieldGet(this, _Playtest_appInfo, "f").versions[0];
|
|
191
|
+
const latestVersion = __classPrivateFieldGet(this, _Playtest_appInfo, "f").versions[0];
|
|
198
192
|
__classPrivateFieldSet(this, _Playtest_version, new DevvitVersion(latestVersion.majorVersion, latestVersion.minorVersion, latestVersion.patchVersion, latestVersion.prereleaseVersion), "f");
|
|
199
|
-
if (__classPrivateFieldGet(this, _Playtest_subreddit, "f")) {
|
|
200
|
-
// alert user if they're about to run playtest in a large subreddit
|
|
201
|
-
const subscriberCount = await fetchSubredditSubscriberCount(__classPrivateFieldGet(this, _Playtest_subreddit, "f"), token);
|
|
202
|
-
if (subscriberCount > MAX_ALLOWED_SUBSCRIBER_COUNT) {
|
|
203
|
-
this.error(`Playtest can only be used in a small test subreddit. Please try again in a community with less than ${MAX_ALLOWED_SUBSCRIBER_COUNT} members.`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this.log(chalk.green(`We'll create a default playtest subreddit for your app!`));
|
|
208
|
-
// TODO: consider having a dedicated endpoint to create the playtest subreddit so we don't have to upload a new version
|
|
209
|
-
// We need to upload a new version to create a new playtest subreddit
|
|
210
|
-
__classPrivateFieldGet(this, _Playtest_version, "f").bumpVersion(VersionBumpType.Prerelease);
|
|
211
|
-
const appVersionCreator = new AppVersionUploader(this, {
|
|
212
|
-
verbose: Boolean(__classPrivateFieldGet(this, _Playtest_flags, "f")?.verbose),
|
|
213
|
-
});
|
|
214
|
-
const bundles = await __classPrivateFieldGet(this, _Playtest_bundler, "f").bundle(this.project, {
|
|
215
|
-
name: ACTOR_SRC_PRIMARY_NAME,
|
|
216
|
-
owner: username,
|
|
217
|
-
version: __classPrivateFieldGet(this, _Playtest_version, "f").toString(),
|
|
218
|
-
});
|
|
219
|
-
latestVersion = await appVersionCreator.createVersion({
|
|
220
|
-
appId: __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.id,
|
|
221
|
-
appSlug: __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.slug,
|
|
222
|
-
appSemver: __classPrivateFieldGet(this, _Playtest_version, "f"),
|
|
223
|
-
visibility: VersionVisibility.PRIVATE,
|
|
224
|
-
}, bundles, false);
|
|
225
|
-
// Since we created a subreddit, we reload the app info to get the newly created subreddit ID
|
|
226
|
-
__classPrivateFieldSet(this, _Playtest_appInfo, await getAppBySlug(__classPrivateFieldGet(this, _Playtest_appClient, "f"), {
|
|
227
|
-
slug: this.project.name,
|
|
228
|
-
limit: 1, // fetched version limit; we only need the latest one
|
|
229
|
-
}), "f");
|
|
230
|
-
if (!__classPrivateFieldGet(this, _Playtest_appInfo, "f")?.app) {
|
|
231
|
-
this.error('Something went wrong: we could not find your app after creating a new playtest subreddit. Please try again.');
|
|
232
|
-
}
|
|
233
|
-
else if (!__classPrivateFieldGet(this, _Playtest_appInfo, "f").app.defaultPlaytestSubredditId) {
|
|
234
|
-
this.error('Something went wrong: we could not find the newly created playtest subreddit ID. Please try again.');
|
|
235
|
-
}
|
|
236
|
-
__classPrivateFieldSet(this, _Playtest_subreddit, __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.defaultPlaytestSubredditId, "f");
|
|
237
|
-
// Delay writing to the config so we can write the subreddit name from the installation instead of the ID
|
|
238
|
-
}
|
|
239
193
|
// before starting playtest session, make sure app has been installed to the test subreddit:
|
|
240
194
|
__classPrivateFieldSet(this, _Playtest_installationInfo, await __classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_getExistingInstallInfo).call(this, this.project.name, __classPrivateFieldGet(this, _Playtest_subreddit, "f")), "f");
|
|
241
195
|
if (!__classPrivateFieldGet(this, _Playtest_installationInfo, "f")) {
|
|
196
|
+
const userT2Id = await this.getUserT2Id(token);
|
|
242
197
|
ux.action.start(`Installing`);
|
|
243
198
|
try {
|
|
244
|
-
|
|
245
|
-
|
|
199
|
+
__classPrivateFieldSet(this, _Playtest_installationInfo, await __classPrivateFieldGet(this, _Playtest_installationsClient, "f").Create({
|
|
200
|
+
appVersionId: latestVersion.id,
|
|
201
|
+
runAs: userT2Id,
|
|
202
|
+
type: InstallationType.SUBREDDIT,
|
|
203
|
+
location: __classPrivateFieldGet(this, _Playtest_subreddit, "f"),
|
|
204
|
+
upgradeStrategy: 0,
|
|
205
|
+
}), "f");
|
|
246
206
|
ux.action.stop();
|
|
247
207
|
}
|
|
248
208
|
catch (err) {
|
|
@@ -250,10 +210,6 @@ class Playtest extends DevvitCommand {
|
|
|
250
210
|
this.error(`An error occurred while installing your app: ${StringUtil.caughtToString(err, 'message')}`);
|
|
251
211
|
}
|
|
252
212
|
}
|
|
253
|
-
__classPrivateFieldSet(this, _Playtest_subreddit, __classPrivateFieldGet(this, _Playtest_installationInfo, "f").installation.location.name, "f");
|
|
254
|
-
if (shouldWriteToConfig) {
|
|
255
|
-
this.project.setSubreddit(__classPrivateFieldGet(this, _Playtest_subreddit, "f"), 'Dev'); // Write the new default playtest subreddit to the project config
|
|
256
|
-
}
|
|
257
213
|
__classPrivateFieldSet(this, _Playtest_appLogSub, makeLogSubscription({
|
|
258
214
|
subreddit: __classPrivateFieldGet(this, _Playtest_installationInfo, "f").installation.location.id,
|
|
259
215
|
appName: this.project.name,
|
|
@@ -295,6 +251,28 @@ _a = Playtest, _Playtest_installationsClient = new WeakMap(), _Playtest_appClien
|
|
|
295
251
|
this.error('Something went wrong when checking for existing installations');
|
|
296
252
|
}
|
|
297
253
|
}
|
|
254
|
+
}, _Playtest_waitUntilVersionBuildComplete =
|
|
255
|
+
/**
|
|
256
|
+
* Re-fetching AppVersionInfo to check the current BuildStatus
|
|
257
|
+
*/
|
|
258
|
+
async function _Playtest_waitUntilVersionBuildComplete(appVersionInfo) {
|
|
259
|
+
ux.action.start('App is building remotely');
|
|
260
|
+
for (let i = 0; i < 10 && appVersionInfo.buildStatus === BuildStatus.BUILDING; i++) {
|
|
261
|
+
// version is still building: wait and try again
|
|
262
|
+
await sleep(3000);
|
|
263
|
+
const info = await __classPrivateFieldGet(this, _Playtest_appVersionClient, "f").Get({ id: appVersionInfo.id });
|
|
264
|
+
if (!info.appVersion) {
|
|
265
|
+
throw new Error('Something went wrong, no app version available.');
|
|
266
|
+
}
|
|
267
|
+
appVersionInfo = info.appVersion;
|
|
268
|
+
if (i === 5) {
|
|
269
|
+
this.log(`Your app's taking a while to build - sorry for the delay!`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
ux.action.stop();
|
|
273
|
+
if (appVersionInfo.buildStatus !== BuildStatus.READY) {
|
|
274
|
+
throw new Error('Something went wrong: the previous version did not build successfully.');
|
|
275
|
+
}
|
|
298
276
|
}, _Playtest_startWatchingSrc = function _Playtest_startWatchingSrc(username) {
|
|
299
277
|
const watchSrc = __classPrivateFieldGet(this, _Playtest_bundler, "f").watch(this.project, this.project.root, {
|
|
300
278
|
name: ACTOR_SRC_PRIMARY_NAME,
|
|
@@ -392,7 +370,6 @@ _a = Playtest, _Playtest_installationsClient = new WeakMap(), _Playtest_appClien
|
|
|
392
370
|
};
|
|
393
371
|
Playtest.description = 'Installs your app to your test subreddit and starts a playtest session where a new version is installed whenever you save changes to your app code, and logs are continuously streamed';
|
|
394
372
|
Playtest.examples = [
|
|
395
|
-
'$ devvit playtest',
|
|
396
373
|
'$ devvit playtest <subreddit>',
|
|
397
374
|
'$ devvit playtest r/myTestSubreddit',
|
|
398
375
|
'$ devvit playtest myOtherTestSubreddit',
|
|
@@ -419,9 +396,12 @@ Playtest.flags = {
|
|
|
419
396
|
};
|
|
420
397
|
Playtest.args = {
|
|
421
398
|
subreddit: Args.string({
|
|
422
|
-
description: `Provide the name of a small test subreddit with <${MAX_ALLOWED_SUBSCRIBER_COUNT} members. The "r/" prefix is optional
|
|
423
|
-
required:
|
|
399
|
+
description: `Provide the name of a small test subreddit with <${MAX_ALLOWED_SUBSCRIBER_COUNT} members. The "r/" prefix is optional`,
|
|
400
|
+
required: true,
|
|
424
401
|
parse: toLowerCaseArgParser,
|
|
425
402
|
}),
|
|
426
403
|
};
|
|
427
404
|
export default Playtest;
|
|
405
|
+
function sleep(ms) {
|
|
406
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
407
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"AAWA,OAAO,EAAiB,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AASxE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAKlE,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,aAAa;;IAC/C,OAAgB,WAAW,SAA+M;IAE1O,OAAgB,KAAK;;;;;;;MA0CV;IAgBL,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA6KX,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAM1D"}
|
package/dist/commands/upload.js
CHANGED
|
@@ -9,25 +9,23 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _Upload_instances, _Upload_appClient,
|
|
12
|
+
var _Upload_instances, _Upload_appClient, _Upload_event, _Upload_eventSent, _Upload_checkDependencies, _Upload_canImportPublicAPI, _Upload_getNextVersionNumber, _Upload_bundleActors, _Upload_sendEventIfNotSent;
|
|
13
13
|
import { exec } from 'node:child_process';
|
|
14
14
|
import fs from 'node:fs';
|
|
15
15
|
import path from 'node:path';
|
|
16
|
-
import { AppVersionInfo, FullAppInfo,
|
|
16
|
+
import { AppVersionInfo, FullAppInfo, VersionVisibility } from '@devvit/protos/community.js';
|
|
17
17
|
import { ACTOR_SRC_PRIMARY_NAME, MAX_ALLOWED_SUBSCRIBER_COUNT, } from '@devvit/shared-types/constants.js';
|
|
18
18
|
import { StringUtil } from '@devvit/shared-types/StringUtil.js';
|
|
19
19
|
import { DevvitVersion, VersionBumpType } from '@devvit/shared-types/Version.js';
|
|
20
20
|
import { Flags, ux } from '@oclif/core';
|
|
21
21
|
import chalk from 'chalk';
|
|
22
|
-
import { REDDIT_DESKTOP } from '../lib/config.js';
|
|
23
22
|
import { isCurrentUserEmployee } from '../lib/http/gql.js';
|
|
24
23
|
import { AppUploader } from '../util/AppUploader.js';
|
|
25
24
|
import { AppVersionUploader } from '../util/AppVersionUploader.js';
|
|
26
25
|
import { getAccessTokenAndLoginIfNeeded } from '../util/auth.js';
|
|
27
26
|
import { Bundler } from '../util/Bundler.js';
|
|
28
|
-
import { createAppClient
|
|
27
|
+
import { createAppClient } from '../util/clientGenerators.js';
|
|
29
28
|
import { DevvitCommand } from '../util/commands/DevvitCommand.js';
|
|
30
|
-
import { installOnSubreddit } from '../util/common-actions/installOnSubreddit.js';
|
|
31
29
|
import { DEVVIT_PORTAL_URL } from '../util/config.js';
|
|
32
30
|
import { getAppBySlug } from '../util/getAppBySlug.js';
|
|
33
31
|
import { sendEvent } from '../util/metrics.js';
|
|
@@ -36,7 +34,6 @@ class Upload extends DevvitCommand {
|
|
|
36
34
|
super(...arguments);
|
|
37
35
|
_Upload_instances.add(this);
|
|
38
36
|
_Upload_appClient.set(this, createAppClient());
|
|
39
|
-
_Upload_installationsClient.set(this, createInstallationsClient());
|
|
40
37
|
_Upload_event.set(this, {
|
|
41
38
|
source: 'devplatform_cli',
|
|
42
39
|
action: 'ran',
|
|
@@ -100,7 +97,6 @@ class Upload extends DevvitCommand {
|
|
|
100
97
|
if (!appInfo?.app) {
|
|
101
98
|
this.error(`App ${this.project.name} is not found`);
|
|
102
99
|
}
|
|
103
|
-
this.project.app.defaultPlaytestSubredditId = appInfo.app.defaultPlaytestSubredditId;
|
|
104
100
|
// Now, create a new version.
|
|
105
101
|
const appVersionNumber = await __classPrivateFieldGet(this, _Upload_instances, "m", _Upload_getNextVersionNumber).call(this, appInfo, flags.bump);
|
|
106
102
|
__classPrivateFieldGet(this, _Upload_event, "f").devplatform.app_version_number = appVersionNumber.toString();
|
|
@@ -109,32 +105,12 @@ class Upload extends DevvitCommand {
|
|
|
109
105
|
ux.action.stop();
|
|
110
106
|
try {
|
|
111
107
|
const appVersionUploader = new AppVersionUploader(this, { verbose: flags.verbose });
|
|
112
|
-
|
|
113
|
-
if (shouldCreatePlaytestSubreddit) {
|
|
114
|
-
this.log(chalk.green(`We'll create a default playtest subreddit for your app!`));
|
|
115
|
-
}
|
|
116
|
-
const latestVersion = await appVersionUploader.createVersion({
|
|
108
|
+
await appVersionUploader.createVersion({
|
|
117
109
|
appId: appInfo.app.id,
|
|
118
110
|
appSlug: appInfo.app.slug,
|
|
119
111
|
appSemver: appVersionNumber,
|
|
120
112
|
visibility: VersionVisibility.PRIVATE,
|
|
121
|
-
}, bundles
|
|
122
|
-
// Install the app to the default playtest subreddit, if it was created.
|
|
123
|
-
if (shouldCreatePlaytestSubreddit) {
|
|
124
|
-
const installationInfo = await __classPrivateFieldGet(this, _Upload_instances, "m", _Upload_installOnDefaultPlaytestSubreddit).call(this, token, latestVersion);
|
|
125
|
-
if (installationInfo) {
|
|
126
|
-
const devSubredditName = installationInfo.installation?.location?.name;
|
|
127
|
-
if (devSubredditName) {
|
|
128
|
-
const playtestUrl = chalk.bold.green(`${REDDIT_DESKTOP}/r/${devSubredditName}`);
|
|
129
|
-
this.log(`We have created a playtest subreddit for you at ${playtestUrl}`);
|
|
130
|
-
this.project.setSubreddit(devSubredditName, 'Dev');
|
|
131
|
-
ux.action.stop();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
this.warn(`We couldn't install your app to the new playtest subreddit, but you can still do so manually.`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
113
|
+
}, bundles);
|
|
138
114
|
}
|
|
139
115
|
catch (err) {
|
|
140
116
|
const errMessage = StringUtil.caughtToString(err, 'message');
|
|
@@ -156,7 +132,7 @@ class Upload extends DevvitCommand {
|
|
|
156
132
|
return super.catch(err);
|
|
157
133
|
}
|
|
158
134
|
}
|
|
159
|
-
_Upload_appClient = new WeakMap(),
|
|
135
|
+
_Upload_appClient = new WeakMap(), _Upload_event = new WeakMap(), _Upload_eventSent = new WeakMap(), _Upload_instances = new WeakSet(), _Upload_checkDependencies =
|
|
160
136
|
/**
|
|
161
137
|
* If we're not just doing it, check and make sure there's a chance our build will succeed.
|
|
162
138
|
*/
|
|
@@ -211,33 +187,6 @@ async function _Upload_checkDependencies(justDoIt) {
|
|
|
211
187
|
__classPrivateFieldSet(this, _Upload_eventSent, true, "f");
|
|
212
188
|
await sendEvent(__classPrivateFieldGet(this, _Upload_event, "f"));
|
|
213
189
|
}
|
|
214
|
-
}, _Upload_installOnDefaultPlaytestSubreddit =
|
|
215
|
-
// Install the app to the default playtest subreddit, if it was created.
|
|
216
|
-
// For convenience, returns the name of the subreddit if the app is successfully installed.
|
|
217
|
-
async function _Upload_installOnDefaultPlaytestSubreddit(token, appVersion) {
|
|
218
|
-
const appInfo = await getAppBySlug(__classPrivateFieldGet(this, _Upload_appClient, "f"), {
|
|
219
|
-
slug: this.project.name,
|
|
220
|
-
hidePrereleaseVersions: true,
|
|
221
|
-
limit: 1, // fetched version limit; we only need the latest one
|
|
222
|
-
});
|
|
223
|
-
if (!appInfo?.app) {
|
|
224
|
-
this.error(`Something went wrong: couldn't find the app ${this.project.name} after creating a playtest subreddit.`);
|
|
225
|
-
}
|
|
226
|
-
else if (!appInfo.app.defaultPlaytestSubredditId) {
|
|
227
|
-
this.error(`Something went wrong: the app ${this.project.name} doesn't have a default playtest subreddit ID.`);
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
ux.action.start('Installing app to default playtest subreddit');
|
|
231
|
-
const userT2Id = await this.getUserT2Id(token);
|
|
232
|
-
const installationInfo = await installOnSubreddit(this, createAppVersionClient(), __classPrivateFieldGet(this, _Upload_installationsClient, "f"), userT2Id, appVersion, appInfo.app.defaultPlaytestSubredditId);
|
|
233
|
-
ux.action.stop();
|
|
234
|
-
return installationInfo;
|
|
235
|
-
}
|
|
236
|
-
catch (err) {
|
|
237
|
-
ux.action.stop('Warning');
|
|
238
|
-
this.warn(`We couldn't install your app to the new playtest subreddit at ${appInfo.app.defaultPlaytestSubredditId}, but you can still do so manually. ${StringUtil.caughtToString(err, 'message')}`);
|
|
239
|
-
}
|
|
240
|
-
return undefined;
|
|
241
190
|
};
|
|
242
191
|
Upload.description = `Upload the app to the App Directory. Uploaded apps are only visible to you (the app owner) and can only be installed to a small test subreddit with less than ${MAX_ALLOWED_SUBSCRIBER_COUNT} subscribers`;
|
|
243
192
|
Upload.flags = {
|
package/dist/lib/http/gql.d.ts
CHANGED
|
@@ -11,13 +11,6 @@ export declare function gqlQuery<T, V extends JSONObject>(config: GQLQueryConfig
|
|
|
11
11
|
data: T;
|
|
12
12
|
}>;
|
|
13
13
|
export declare function isCurrentUserEmployee(token: StoredToken): Promise<boolean>;
|
|
14
|
-
/**
|
|
15
|
-
* Get the number of subscribers of a subreddit.
|
|
16
|
-
*
|
|
17
|
-
* @param subreddit - The name or t5 ID of the subreddit.
|
|
18
|
-
* @param token - The stored token for authentication.
|
|
19
|
-
* @returns A Promise that resolves to the number of subscribers if the subreddit exists.
|
|
20
|
-
*/
|
|
21
14
|
export declare function fetchSubredditSubscriberCount(subreddit: string, token: StoredToken): Promise<number>;
|
|
22
15
|
export declare function getUserId(username: string, token: StoredToken): Promise<string>;
|
|
23
16
|
//# sourceMappingURL=gql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../../../src/lib/http/gql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../../../src/lib/http/gql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAU1D,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,UAAU,IAAI;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,CAAC;CACf,CAAC;AAEF,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,EACpD,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAuBtB;AAED,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAUhF;AAED,wBAAsB,6BAA6B,CACjD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAWrF"}
|
package/dist/lib/http/gql.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { isT5ID } from '@devvit/shared-types/tid.js';
|
|
2
1
|
import { GQL_QUERY_URL } from '../../util/config.js';
|
|
3
2
|
import { MY_PORTAL_ENABLED } from '../config.js';
|
|
4
3
|
// TODO: figure out how to get proper types from graphql.ts in portal
|
|
5
4
|
const IDENTITY_QUERY_HASH = '1936294e5fc812fe34e30c5527b69400a8c44becf417c0c44acffebd3f1632d6';
|
|
6
5
|
const GET_SUBREDDIT_INFO_BY_NAME_QUERY_HASH = 'f1d2d2ac1ef6e39f9c4a103960d5b07d83665073a376c7852655fae2f1ad5159';
|
|
7
6
|
const GET_REDDITOR_INFO_BY_NAME_QUERY_HASH = '19b0be6bef17faf58939802d3858fec2622ba5ec28d6b8a2982998749ceca30b';
|
|
8
|
-
const GET_SUBREDDIT_INFO_BY_ID_QUERY_HASH = '109b67500ceb4e883d6a0e15e1699948e957bf85dc630651f1e10463b6ed5db6';
|
|
9
7
|
export async function gqlQuery(config) {
|
|
10
8
|
const resp = await fetch(`${GQL_QUERY_URL}`, {
|
|
11
9
|
method: 'POST',
|
|
@@ -40,41 +38,20 @@ export async function isCurrentUserEmployee(token) {
|
|
|
40
38
|
});
|
|
41
39
|
return identity.data.identity.isEmployee;
|
|
42
40
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Get the number of subscribers of a subreddit.
|
|
45
|
-
*
|
|
46
|
-
* @param subreddit - The name or t5 ID of the subreddit.
|
|
47
|
-
* @param token - The stored token for authentication.
|
|
48
|
-
* @returns A Promise that resolves to the number of subscribers if the subreddit exists.
|
|
49
|
-
*/
|
|
50
41
|
export async function fetchSubredditSubscriberCount(subreddit, token) {
|
|
51
42
|
// Hack: GQL is failing below on snoodev.
|
|
52
43
|
if (MY_PORTAL_ENABLED)
|
|
53
44
|
return 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error(`Community with ID '${subreddit}' not found.`);
|
|
63
|
-
}
|
|
64
|
-
return subredditInfo.data.subredditInfoById.subscribersCount;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const subredditInfo = await gqlQuery({
|
|
68
|
-
accessToken: token.accessToken,
|
|
69
|
-
hash: GET_SUBREDDIT_INFO_BY_NAME_QUERY_HASH,
|
|
70
|
-
name: 'GetSubredditInfoByName',
|
|
71
|
-
variables: { name: subreddit },
|
|
72
|
-
});
|
|
73
|
-
if (!subredditInfo.data.subredditInfoByName) {
|
|
74
|
-
throw new Error(`Community '${subreddit}' not found.`);
|
|
75
|
-
}
|
|
76
|
-
return subredditInfo.data.subredditInfoByName.subscribersCount;
|
|
45
|
+
const subredditInfo = await gqlQuery({
|
|
46
|
+
accessToken: token.accessToken,
|
|
47
|
+
hash: GET_SUBREDDIT_INFO_BY_NAME_QUERY_HASH,
|
|
48
|
+
name: 'GetSubredditInfoByName',
|
|
49
|
+
variables: { name: subreddit },
|
|
50
|
+
});
|
|
51
|
+
if (!subredditInfo.data.subredditInfoByName) {
|
|
52
|
+
throw new Error(`Community '${subreddit}' not found.`);
|
|
77
53
|
}
|
|
54
|
+
return subredditInfo.data.subredditInfoByName.subscribersCount;
|
|
78
55
|
}
|
|
79
56
|
export async function getUserId(username, token) {
|
|
80
57
|
// Hack: GQL is failing below on snoodev.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AssetMap } from '@devvit/shared-types/Assets.js';
|
|
2
2
|
import type { DevvitCommand } from './commands/DevvitCommand.js';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const DEVVIT_ANALYTICS_JS_URL = "https://webview.devvit.net/scripts/devvit.v1.min.js";
|
|
4
4
|
export declare class AssetUploader {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(cmd: DevvitCommand, appSlug: string, { verbose }: {
|
|
@@ -19,6 +19,6 @@ export declare class AssetUploader {
|
|
|
19
19
|
webViewAssetMap?: AssetMap;
|
|
20
20
|
}>;
|
|
21
21
|
}
|
|
22
|
-
export declare function transformHTMLBuffer(buf: Buffer
|
|
23
|
-
export declare function transformHTML(str: string
|
|
22
|
+
export declare function transformHTMLBuffer(buf: Buffer): Buffer;
|
|
23
|
+
export declare function transformHTML(str: string): string;
|
|
24
24
|
//# sourceMappingURL=AssetUploader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetUploader.d.ts","sourceRoot":"","sources":["../../src/util/AssetUploader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AssetUploader.d.ts","sourceRoot":"","sources":["../../src/util/AssetUploader.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,KAAK,QAAQ,EAKd,MAAM,gCAAgC,CAAC;AASxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,eAAO,MAAM,uBAAuB,wDAAwD,CAAC;AAM7F,qBAAa,aAAa;;gBAQZ,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE;IAMlF;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC;QAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACpB,eAAe,CAAC,EAAE,QAAQ,CAAC;KAC5B,CAAC;CAkRH;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBjD"}
|
|
@@ -9,20 +9,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _AssetUploader_instances, _AssetUploader_cmd, _AssetUploader_verbose, _AssetUploader_appClient, _AssetUploader_appSlug, _AssetUploader_processRegularAssets, _AssetUploader_processWebViewAssets, _AssetUploader_uploadNewAssets, _AssetUploader_mapAssets;
|
|
12
|
+
var _AssetUploader_instances, _AssetUploader_cmd, _AssetUploader_verbose, _AssetUploader_appClient, _AssetUploader_appSlug, _AssetUploader_getAssets, _AssetUploader_processRegularAssets, _AssetUploader_processWebViewAssets, _AssetUploader_uploadNewAssets, _AssetUploader_mapAssets;
|
|
13
13
|
import fsp from 'node:fs/promises';
|
|
14
14
|
import path from 'node:path';
|
|
15
|
-
import { requireFromDir } from '@devvit/build-pack/esbuild/BuildInfoUtil.js';
|
|
16
15
|
import { ALLOWED_ASSET_EXTENSIONS, MAX_ASSET_FOLDER_SIZE_BYTES, MAX_ASSET_GIF_SIZE, MAX_ASSET_NON_GIF_SIZE, prettyPrintSize, } from '@devvit/shared-types/Assets.js';
|
|
17
16
|
import { ASSET_HASHING_ALGO, ASSET_UPLOAD_BATCH_SIZE } from '@devvit/shared-types/constants.js';
|
|
18
|
-
import { clientVersionQueryParam } from '@devvit/shared-types/web-view-scripts-constants.js';
|
|
19
17
|
import { ux } from '@oclif/core';
|
|
20
18
|
import { createHash } from 'crypto';
|
|
21
19
|
import { JSDOM } from 'jsdom';
|
|
22
20
|
import { default as tinyglob } from 'tiny-glob';
|
|
23
21
|
import { dirExists } from '../util/files.js';
|
|
24
22
|
import { createAppClient } from './clientGenerators.js';
|
|
25
|
-
export const
|
|
23
|
+
export const DEVVIT_ANALYTICS_JS_URL = 'https://webview.devvit.net/scripts/devvit.v1.min.js';
|
|
26
24
|
export class AssetUploader {
|
|
27
25
|
constructor(cmd, appSlug, { verbose }) {
|
|
28
26
|
_AssetUploader_instances.add(this);
|
|
@@ -43,14 +41,11 @@ export class AssetUploader {
|
|
|
43
41
|
* the asset map.
|
|
44
42
|
*/
|
|
45
43
|
async syncAssets() {
|
|
46
|
-
const clientVersion = readClientVersion(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root);
|
|
47
44
|
const [regularAssets, webViewAssets] = await Promise.all([
|
|
48
45
|
__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.mediaDir
|
|
49
|
-
?
|
|
50
|
-
: [],
|
|
51
|
-
__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.clientDir
|
|
52
|
-
? queryAssets(path.join(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root, __classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.clientDir), [], 'Client', clientVersion)
|
|
46
|
+
? __classPrivateFieldGet(this, _AssetUploader_instances, "m", _AssetUploader_getAssets).call(this, __classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.mediaDir, ALLOWED_ASSET_EXTENSIONS)
|
|
53
47
|
: [],
|
|
48
|
+
__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.clientDir ? __classPrivateFieldGet(this, _AssetUploader_instances, "m", _AssetUploader_getAssets).call(this, __classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.clientDir, [], true) : [],
|
|
54
49
|
]);
|
|
55
50
|
// Return early if no assets
|
|
56
51
|
if (regularAssets.length + webViewAssets.length === 0) {
|
|
@@ -70,7 +65,40 @@ export class AssetUploader {
|
|
|
70
65
|
return { assetMap, webViewAssetMap };
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
|
-
_AssetUploader_cmd = new WeakMap(), _AssetUploader_verbose = new WeakMap(), _AssetUploader_appClient = new WeakMap(), _AssetUploader_appSlug = new WeakMap(), _AssetUploader_instances = new WeakSet(),
|
|
68
|
+
_AssetUploader_cmd = new WeakMap(), _AssetUploader_verbose = new WeakMap(), _AssetUploader_appClient = new WeakMap(), _AssetUploader_appSlug = new WeakMap(), _AssetUploader_instances = new WeakSet(), _AssetUploader_getAssets = async function _AssetUploader_getAssets(folder, allowedExtensions = [], webViewAssets = false) {
|
|
69
|
+
if (!(await dirExists(path.join(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root, folder)))) {
|
|
70
|
+
// Return early if there isn't an assets directory
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const assetsPath = path.join(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root, folder);
|
|
74
|
+
const assetsGlob = path
|
|
75
|
+
.join(assetsPath, '**', '*')
|
|
76
|
+
// Note: tiny-glob *always* uses `/` as its path separator, even on Windows, so we need to
|
|
77
|
+
// replace whatever the system path separator is with `/`
|
|
78
|
+
.replaceAll(path.sep, '/');
|
|
79
|
+
const assets = (await tinyglob(assetsGlob, {
|
|
80
|
+
filesOnly: true,
|
|
81
|
+
absolute: true,
|
|
82
|
+
})).filter((asset) => allowedExtensions.length === 0 || allowedExtensions.includes(path.extname(asset)));
|
|
83
|
+
return await Promise.all(assets.map(async (asset) => {
|
|
84
|
+
const filename = path.relative(assetsPath, asset).replaceAll(path.sep, '/');
|
|
85
|
+
let file = await fsp.readFile(asset);
|
|
86
|
+
// If the webview asses is an HTML file, inject the Devvit analytics script
|
|
87
|
+
if (webViewAssets && filename.match(/\.html?$/)) {
|
|
88
|
+
file = transformHTMLBuffer(file);
|
|
89
|
+
}
|
|
90
|
+
const size = Buffer.byteLength(file);
|
|
91
|
+
const contents = new Uint8Array(file);
|
|
92
|
+
const hash = createHash(ASSET_HASHING_ALGO).update(file).digest('hex');
|
|
93
|
+
return {
|
|
94
|
+
filePath: filename,
|
|
95
|
+
size,
|
|
96
|
+
hash,
|
|
97
|
+
isWebviewAsset: webViewAssets,
|
|
98
|
+
contents,
|
|
99
|
+
};
|
|
100
|
+
}));
|
|
101
|
+
}, _AssetUploader_processRegularAssets = async function _AssetUploader_processRegularAssets(assets) {
|
|
74
102
|
// early out to avoid logging if empty
|
|
75
103
|
if (assets.length === 0) {
|
|
76
104
|
return {};
|
|
@@ -219,75 +247,27 @@ async function _AssetUploader_mapAssets(assets, statuses) {
|
|
|
219
247
|
});
|
|
220
248
|
return { newAssets, duplicateAssets, existingAssets };
|
|
221
249
|
};
|
|
222
|
-
|
|
223
|
-
* Read assets from disk and transform them.
|
|
224
|
-
*
|
|
225
|
-
* Asset kind controls transform. Client (historically webroot/) is for web view
|
|
226
|
-
* assets. Media (historically assets/) is for everything else.
|
|
227
|
-
*/
|
|
228
|
-
async function queryAssets(dir, allowedExtensions, assetKind, clientVersionNum) {
|
|
229
|
-
if (!(await dirExists(dir))) {
|
|
230
|
-
// Return early if there isn't an assets directory
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
const assetsGlob = path
|
|
234
|
-
.join(dir, '**', '*')
|
|
235
|
-
// Note: tiny-glob *always* uses `/` as its path separator, even on Windows, so we need to
|
|
236
|
-
// replace whatever the system path separator is with `/`
|
|
237
|
-
.replaceAll(path.sep, '/');
|
|
238
|
-
const assets = (await tinyglob(assetsGlob, { filesOnly: true, absolute: true })).filter((asset) => allowedExtensions.length === 0 || allowedExtensions.includes(path.extname(asset)));
|
|
239
|
-
return await Promise.all(assets.map(async (asset) => {
|
|
240
|
-
const filename = path.relative(dir, asset).replaceAll(path.sep, '/');
|
|
241
|
-
let file = await fsp.readFile(asset);
|
|
242
|
-
// If the webview assets is an HTML file, inject the Devvit analytics
|
|
243
|
-
// script.
|
|
244
|
-
if (assetKind === 'Client' && filename.match(/\.html?$/)) {
|
|
245
|
-
file = transformHTMLBuffer(file, clientVersionNum);
|
|
246
|
-
}
|
|
247
|
-
const size = Buffer.byteLength(file);
|
|
248
|
-
const contents = new Uint8Array(file);
|
|
249
|
-
const hash = createHash(ASSET_HASHING_ALGO).update(file).digest('hex');
|
|
250
|
-
return {
|
|
251
|
-
filePath: filename,
|
|
252
|
-
size,
|
|
253
|
-
hash,
|
|
254
|
-
isWebviewAsset: assetKind === 'Client',
|
|
255
|
-
contents,
|
|
256
|
-
};
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
|
-
function readClientVersion(root) {
|
|
260
|
-
try {
|
|
261
|
-
const pkg = requireFromDir(root, '@devvit/client/package.json');
|
|
262
|
-
return pkg.version;
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
export function transformHTMLBuffer(buf, clientVersionNum) {
|
|
250
|
+
export function transformHTMLBuffer(buf) {
|
|
269
251
|
const inStr = new TextDecoder('utf-8').decode(buf);
|
|
270
|
-
const out = transformHTML(inStr
|
|
252
|
+
const out = transformHTML(inStr);
|
|
271
253
|
return Buffer.from(out);
|
|
272
254
|
}
|
|
273
|
-
export function transformHTML(str
|
|
255
|
+
export function transformHTML(str) {
|
|
274
256
|
const { document } = new JSDOM(str).window;
|
|
275
257
|
// if no html tag, return early
|
|
276
258
|
const htmlTag = document.querySelector('html');
|
|
277
259
|
if (htmlTag == null) {
|
|
278
260
|
return str;
|
|
279
261
|
}
|
|
280
|
-
const
|
|
281
|
-
? `${clientVersionQueryParam}=${clientVersionNum}`
|
|
282
|
-
: '';
|
|
283
|
-
const scriptTag = `<script src="${DEVVIT_JS_URL}?${clientVersionQueryArg}"></script>`;
|
|
262
|
+
const scriptTag = `<script async type="module" src="${DEVVIT_ANALYTICS_JS_URL}"></script>`;
|
|
284
263
|
// if no head tag, create one after the html tag
|
|
285
264
|
const headTag = document.querySelector('head');
|
|
286
265
|
if (headTag == null) {
|
|
287
266
|
htmlTag.insertAdjacentHTML('afterbegin', `<head>${scriptTag}</head>`); // eslint-disable-line no-unsanitized/method
|
|
288
267
|
}
|
|
289
268
|
else {
|
|
290
|
-
|
|
269
|
+
// if head tag exists, append the script tag to it
|
|
270
|
+
headTag.insertAdjacentHTML('beforeend', scriptTag); // eslint-disable-line no-unsanitized/method
|
|
291
271
|
}
|
|
292
272
|
return document.documentElement.outerHTML;
|
|
293
273
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { clientVersionQueryParam } from '@devvit/shared-types/web-view-scripts-constants.js';
|
|
2
1
|
import { JSDOM } from 'jsdom';
|
|
3
2
|
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import {
|
|
3
|
+
import { DEVVIT_ANALYTICS_JS_URL, transformHTML } from './AssetUploader.js';
|
|
5
4
|
describe('HTML Transformation', () => {
|
|
6
5
|
describe('transformHTML', () => {
|
|
7
6
|
it('should add script tag to head when head exists', () => {
|
|
@@ -16,7 +15,7 @@ describe('HTML Transformation', () => {
|
|
|
16
15
|
</body>
|
|
17
16
|
</html>
|
|
18
17
|
`;
|
|
19
|
-
const result = transformHTML(input
|
|
18
|
+
const result = transformHTML(input);
|
|
20
19
|
const dom = new JSDOM(result);
|
|
21
20
|
const document = dom.window.document;
|
|
22
21
|
// Verify script tag exists in head
|
|
@@ -35,7 +34,7 @@ describe('HTML Transformation', () => {
|
|
|
35
34
|
</body>
|
|
36
35
|
</html>
|
|
37
36
|
`;
|
|
38
|
-
const result = transformHTML(input
|
|
37
|
+
const result = transformHTML(input);
|
|
39
38
|
const dom = new JSDOM(result);
|
|
40
39
|
const document = dom.window.document;
|
|
41
40
|
// Verify head tag exists
|
|
@@ -58,22 +57,11 @@ describe('HTML Transformation', () => {
|
|
|
58
57
|
</body>
|
|
59
58
|
</html>
|
|
60
59
|
`;
|
|
61
|
-
const result = transformHTML(input
|
|
60
|
+
const result = transformHTML(input);
|
|
62
61
|
const dom = new JSDOM(result);
|
|
63
62
|
const document = dom.window.document;
|
|
64
63
|
// Verify script tag exists
|
|
65
|
-
const script = document.querySelector(`script[src="${
|
|
66
|
-
assertScriptExpectations(script);
|
|
67
|
-
});
|
|
68
|
-
it('should handle non-HTML gracefully', () => {
|
|
69
|
-
const input = `
|
|
70
|
-
<
|
|
71
|
-
`;
|
|
72
|
-
const result = transformHTML(input, '1.2.3');
|
|
73
|
-
const dom = new JSDOM(result);
|
|
74
|
-
const document = dom.window.document;
|
|
75
|
-
// Verify script tag exists
|
|
76
|
-
const script = document.querySelector(`script[src="${DEVVIT_JS_URL}?${clientVersionQueryParam}=1.2.3"]`);
|
|
64
|
+
const script = document.querySelector(`script[src="${DEVVIT_ANALYTICS_JS_URL}"]`);
|
|
77
65
|
assertScriptExpectations(script);
|
|
78
66
|
});
|
|
79
67
|
it('should handle HTML with existing script tags', () => {
|
|
@@ -88,7 +76,7 @@ describe('HTML Transformation', () => {
|
|
|
88
76
|
</body>
|
|
89
77
|
</html>
|
|
90
78
|
`;
|
|
91
|
-
const result = transformHTML(input
|
|
79
|
+
const result = transformHTML(input);
|
|
92
80
|
const dom = new JSDOM(result);
|
|
93
81
|
const document = dom.window.document;
|
|
94
82
|
// Verify both script tags exist
|
|
@@ -102,8 +90,10 @@ describe('HTML Transformation', () => {
|
|
|
102
90
|
});
|
|
103
91
|
});
|
|
104
92
|
function selectScript(document) {
|
|
105
|
-
return document.querySelector(`head script[src="${
|
|
93
|
+
return document.querySelector(`head script[src="${DEVVIT_ANALYTICS_JS_URL}"]`);
|
|
106
94
|
}
|
|
107
95
|
function assertScriptExpectations(script) {
|
|
108
96
|
expect(script).not.toBeNull();
|
|
97
|
+
expect(script?.getAttribute('async')).toBe('');
|
|
98
|
+
expect(script?.getAttribute('type')).toBe('module');
|
|
109
99
|
}
|
package/dist/util/project.d.ts
CHANGED
|
@@ -34,10 +34,6 @@ export declare class Project {
|
|
|
34
34
|
static new(root: string, filename: string, mode: BuildMode): Promise<Project>;
|
|
35
35
|
readonly flag: {
|
|
36
36
|
watchDebounceMillis?: number | undefined;
|
|
37
|
-
subreddit?: string | undefined;
|
|
38
|
-
};
|
|
39
|
-
readonly app: {
|
|
40
|
-
defaultPlaytestSubredditId?: string | undefined;
|
|
41
37
|
};
|
|
42
38
|
readonly root: ProjectRootDir;
|
|
43
39
|
readonly filename: string;
|
|
@@ -51,8 +47,6 @@ export declare class Project {
|
|
|
51
47
|
get post(): Readonly<AppPostConfig | undefined>;
|
|
52
48
|
get server(): Readonly<AppServerConfig | undefined>;
|
|
53
49
|
get watchDebounceMillis(): number;
|
|
54
|
-
getSubreddit(mode: 'Dev' | 'Prod'): string | undefined;
|
|
55
|
-
setSubreddit(subreddit: string, mode: 'Dev' | 'Prod'): void;
|
|
56
50
|
}
|
|
57
51
|
/**
|
|
58
52
|
* Searches for dir containing the config filename. If found, returns a cached
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/util/project.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,EAErB,MAAM,gDAAgD,CAAC;AAKxD,OAAO,EAAE,KAAK,mBAAmB,EAAmB,MAAM,oCAAoC,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7C,iCAAiC;AACjC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAExD,0CAA0C;AAC1C,eAAO,MAAM,2BAA2B,EAAE,MAAsB,CAAC;AACjE,4CAA4C;AAC5C,eAAO,MAAM,sBAAsB,EAAE,MAAsB,CAAC;AAE5D,uDAAuD;AACvD,qBAAa,OAAO;;IAClB;;;OAGG;WACU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAenF,QAAQ,CAAC,IAAI,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/util/project.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,EAErB,MAAM,gDAAgD,CAAC;AAKxD,OAAO,EAAE,KAAK,mBAAmB,EAAmB,MAAM,oCAAoC,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7C,iCAAiC;AACjC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAExD,0CAA0C;AAC1C,eAAO,MAAM,2BAA2B,EAAE,MAAsB,CAAC;AACjE,4CAA4C;AAC5C,eAAO,MAAM,sBAAsB,EAAE,MAAsB,CAAC;AAE5D,uDAAuD;AACvD,qBAAa,OAAO;;IAClB;;;OAGG;WACU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAenF,QAAQ,CAAC,IAAI,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAM;IACjE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAMxB,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,EACpB,aAAa,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,SAAS;IAQ1D,IAAI,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAE/C;IAGD,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAGD,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAIpB;IAED,IAAI,WAAW,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,SAAS,CAE3D;IAED,IAAI,IAAI,IAAI,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC,CAE9C;IAED,IAAI,MAAM,IAAI,QAAQ,CAAC,eAAe,GAAG,SAAS,CAAC,CAElD;IAGD,IAAI,mBAAmB,IAAI,MAAM,CAEhC;CACF;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAO9B;AAED,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,SAAS,CAE/E;AAED,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAShE;AAoBD,iBAAiB;AACjB,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAC3B,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,EACzC,IAAI,EAAE,SAAS,GACd,MAAM,EAAE,CAgCV"}
|
package/dist/util/project.js
CHANGED
|
@@ -51,7 +51,6 @@ export class Project {
|
|
|
51
51
|
}
|
|
52
52
|
constructor(root, filename, config, packageConfig) {
|
|
53
53
|
this.flag = {};
|
|
54
|
-
this.app = {};
|
|
55
54
|
_Project_config.set(this, void 0);
|
|
56
55
|
/** @deprecated Use the config-file.v1.json schema instead. */
|
|
57
56
|
_Project_packageConfig.set(this, void 0);
|
|
@@ -93,36 +92,6 @@ export class Project {
|
|
|
93
92
|
get watchDebounceMillis() {
|
|
94
93
|
return this.flag.watchDebounceMillis ?? __classPrivateFieldGet(this, _Project_packageConfig, "f")?.playtest?.debounceConfigMs ?? 100;
|
|
95
94
|
}
|
|
96
|
-
getSubreddit(mode) {
|
|
97
|
-
if (mode === 'Prod') {
|
|
98
|
-
throw Error(`Getting Prod subreddits isn't supported yet.`);
|
|
99
|
-
}
|
|
100
|
-
const trimmedEnvVar = process.env?.DEVVIT_DEV_SUBREDDIT?.trim();
|
|
101
|
-
if (trimmedEnvVar) {
|
|
102
|
-
return process.env.DEVVIT_DEV_SUBREDDIT;
|
|
103
|
-
}
|
|
104
|
-
const trimmedFlag = this.flag.subreddit?.trim();
|
|
105
|
-
if (trimmedFlag) {
|
|
106
|
-
return this.flag.subreddit;
|
|
107
|
-
}
|
|
108
|
-
if (isAppConfig(__classPrivateFieldGet(this, _Project_config, "f")) && __classPrivateFieldGet(this, _Project_config, "f").dev?.subreddit) {
|
|
109
|
-
return __classPrivateFieldGet(this, _Project_config, "f").dev.subreddit;
|
|
110
|
-
}
|
|
111
|
-
return this.app.defaultPlaytestSubredditId;
|
|
112
|
-
}
|
|
113
|
-
setSubreddit(subreddit, mode) {
|
|
114
|
-
var _a, _b;
|
|
115
|
-
if (mode === 'Prod') {
|
|
116
|
-
throw Error(`Setting Prod subreddits isn't supported yet.`);
|
|
117
|
-
}
|
|
118
|
-
if (!isAppConfig(__classPrivateFieldGet(this, _Project_config, "f")))
|
|
119
|
-
return;
|
|
120
|
-
(_a = __classPrivateFieldGet(this, _Project_config, "f")).dev ?? (_a.dev = {});
|
|
121
|
-
__classPrivateFieldGet(this, _Project_config, "f").dev.subreddit = subreddit;
|
|
122
|
-
(_b = __classPrivateFieldGet(this, _Project_config, "f").json).dev ?? (_b.dev = {});
|
|
123
|
-
__classPrivateFieldGet(this, _Project_config, "f").json.dev.subreddit = subreddit;
|
|
124
|
-
writeConfig(this.root, this.filename, __classPrivateFieldGet(this, _Project_config, "f"));
|
|
125
|
-
}
|
|
126
95
|
}
|
|
127
96
|
_Project_config = new WeakMap(), _Project_packageConfig = new WeakMap();
|
|
128
97
|
/**
|
|
@@ -48,19 +48,6 @@ describe('Project', () => {
|
|
|
48
48
|
project.flag.watchDebounceMillis = 200;
|
|
49
49
|
expect(project.watchDebounceMillis).toBe(200);
|
|
50
50
|
});
|
|
51
|
-
test('dev.subreddit', () => {
|
|
52
|
-
const config = {
|
|
53
|
-
schema: 'v1',
|
|
54
|
-
name: 'name',
|
|
55
|
-
permissions: noPermissions,
|
|
56
|
-
json: { name: 'name' },
|
|
57
|
-
dev: { subreddit: 'devsubreddit' },
|
|
58
|
-
};
|
|
59
|
-
const project = new Project('root', 'filename', config, undefined);
|
|
60
|
-
expect(project.getSubreddit('Dev')).toBe('devsubreddit');
|
|
61
|
-
project.setSubreddit('newsubreddit', 'Dev');
|
|
62
|
-
expect(project.getSubreddit('Dev')).toBe('newsubreddit');
|
|
63
|
-
});
|
|
64
51
|
});
|
|
65
52
|
describe('validateConfig()', () => {
|
|
66
53
|
test('blocks.entry', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/cli",
|
|
3
|
-
"version": "0.11.17
|
|
3
|
+
"version": "0.11.17",
|
|
4
4
|
"description": "Reddit's Dev Platform CLI Tool",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"author": "@reddit/dev-platform",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
},
|
|
43
43
|
"types": "dist/index.d.ts",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@devvit/build-pack": "0.11.17
|
|
45
|
+
"@devvit/build-pack": "0.11.17",
|
|
46
46
|
"@devvit/play": "0.0.45",
|
|
47
|
-
"@devvit/protos": "0.11.17
|
|
48
|
-
"@devvit/public-api": "0.11.17
|
|
49
|
-
"@devvit/shared-types": "0.11.17
|
|
47
|
+
"@devvit/protos": "0.11.17",
|
|
48
|
+
"@devvit/public-api": "0.11.17",
|
|
49
|
+
"@devvit/shared-types": "0.11.17",
|
|
50
50
|
"@improbable-eng/grpc-web": "0.15.0",
|
|
51
51
|
"@improbable-eng/grpc-web-node-http-transport": "0.15.0",
|
|
52
52
|
"@oclif/core": "2.9.4",
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"chalk": "4.1.2",
|
|
59
59
|
"chokidar": "3.5.3",
|
|
60
60
|
"date-fns": "2.29.3",
|
|
61
|
-
"dotenv": "16.5.0",
|
|
62
61
|
"file-type": "18.2.1",
|
|
63
62
|
"image-size": "1.2.1",
|
|
64
63
|
"inquirer": "9.1.4",
|
|
@@ -75,8 +74,8 @@
|
|
|
75
74
|
"ws": "8.18.0"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
|
-
"@devvit/repo-tools": "0.11.17
|
|
79
|
-
"@devvit/tsconfig": "0.11.17
|
|
77
|
+
"@devvit/repo-tools": "0.11.17",
|
|
78
|
+
"@devvit/tsconfig": "0.11.17",
|
|
80
79
|
"@types/file-type": "10.9.1",
|
|
81
80
|
"@types/inquirer": "9.0.3",
|
|
82
81
|
"@types/js-yaml": "4.0.5",
|
|
@@ -113,5 +112,5 @@
|
|
|
113
112
|
]
|
|
114
113
|
}
|
|
115
114
|
},
|
|
116
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "33c31788acc196624783f9eef0e7faa9fd0b7ded"
|
|
117
116
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type AppVersionClient, AppVersionInfo, FullInstallationInfo, type InstallationsClient } from '@devvit/protos/community.js';
|
|
2
|
-
import { DevvitCommand } from '../commands/DevvitCommand.js';
|
|
3
|
-
export declare function installOnSubreddit(command: DevvitCommand, appVersionClient: AppVersionClient, installationsClient: InstallationsClient, userT2Id: `t2_${string}`, appVersion: AppVersionInfo, subreddit: string): Promise<FullInstallationInfo>;
|
|
4
|
-
//# sourceMappingURL=installOnSubreddit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"installOnSubreddit.d.ts","sourceRoot":"","sources":["../../../src/util/common-actions/installOnSubreddit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,cAAc,EACd,oBAAoB,EACpB,KAAK,mBAAmB,EAEzB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,mBAAmB,EACxC,QAAQ,EAAE,MAAM,MAAM,EAAE,EACxB,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,CAAC,CAW/B"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AppVersionInfo, FullInstallationInfo, InstallationType, } from '@devvit/protos/community.js';
|
|
2
|
-
import { DevvitCommand } from '../commands/DevvitCommand.js';
|
|
3
|
-
import { waitUntilVersionBuildComplete } from '../common-actions/waitUntilVersionBuildComplete.js';
|
|
4
|
-
export async function installOnSubreddit(command, appVersionClient, installationsClient, userT2Id, appVersion, subreddit) {
|
|
5
|
-
// Wait for the app version to be built.
|
|
6
|
-
await waitUntilVersionBuildComplete(command, appVersionClient, appVersion);
|
|
7
|
-
return await installationsClient.Create({
|
|
8
|
-
appVersionId: appVersion.id,
|
|
9
|
-
runAs: userT2Id,
|
|
10
|
-
type: InstallationType.SUBREDDIT,
|
|
11
|
-
location: subreddit,
|
|
12
|
-
upgradeStrategy: 0,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type AppVersionClient, AppVersionInfo } from '@devvit/protos/community.js';
|
|
2
|
-
import { DevvitCommand } from '../commands/DevvitCommand.js';
|
|
3
|
-
export declare function waitUntilVersionBuildComplete(command: DevvitCommand, appVersionClient: AppVersionClient, appVersionInfo: AppVersionInfo): Promise<void>;
|
|
4
|
-
//# sourceMappingURL=waitUntilVersionBuildComplete.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntilVersionBuildComplete.d.ts","sourceRoot":"","sources":["../../../src/util/common-actions/waitUntilVersionBuildComplete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,cAAc,EAAe,MAAM,6BAA6B,CAAC;AAGjG,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AppVersionInfo, BuildStatus } from '@devvit/protos/community.js';
|
|
2
|
-
import { ux } from '@oclif/core';
|
|
3
|
-
import { DevvitCommand } from '../commands/DevvitCommand.js';
|
|
4
|
-
import { sleep } from '../sleep.js';
|
|
5
|
-
export async function waitUntilVersionBuildComplete(command, appVersionClient, appVersionInfo) {
|
|
6
|
-
ux.action.start('App is building remotely');
|
|
7
|
-
for (let i = 0; i < 10 && appVersionInfo.buildStatus === BuildStatus.BUILDING; i++) {
|
|
8
|
-
// version is still building: wait and try again
|
|
9
|
-
await sleep(3000);
|
|
10
|
-
const info = await appVersionClient.Get({ id: appVersionInfo.id });
|
|
11
|
-
if (!info.appVersion) {
|
|
12
|
-
throw new Error('Something went wrong, no app version available.');
|
|
13
|
-
}
|
|
14
|
-
appVersionInfo = info.appVersion;
|
|
15
|
-
if (i === 5) {
|
|
16
|
-
command.log(`Your app's taking a while to build - sorry for the delay!`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
ux.action.stop();
|
|
20
|
-
if (appVersionInfo.buildStatus !== BuildStatus.READY) {
|
|
21
|
-
throw new Error('Something went wrong: the previous version did not build successfully.');
|
|
22
|
-
}
|
|
23
|
-
}
|