@devvit/cli 0.11.17 → 0.11.18-next-2025-06-16-20-45-28-cf17b48ff.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.
- package/bin/devvit.js +3 -0
- package/dist/commands/playtest.d.ts +1 -1
- package/dist/commands/playtest.d.ts.map +1 -1
- package/dist/commands/playtest.js +65 -45
- package/dist/commands/upload.d.ts.map +1 -1
- package/dist/commands/upload.js +58 -6
- package/dist/lib/http/gql.d.ts +7 -0
- package/dist/lib/http/gql.d.ts.map +1 -1
- package/dist/lib/http/gql.js +32 -9
- package/dist/templates/blocks-post/package.json +2 -2
- package/dist/templates/empty/package.json +2 -2
- package/dist/templates/payments/package.json +3 -3
- package/dist/templates/payments-web-view/package.json +3 -3
- package/dist/templates/pen/package.json +2 -2
- package/dist/templates/web-view-post/package.json +2 -2
- package/dist/util/AssetUploader.d.ts +3 -3
- package/dist/util/AssetUploader.d.ts.map +1 -1
- package/dist/util/AssetUploader.js +64 -44
- package/dist/util/AssetUploader.test.js +19 -9
- package/dist/util/common-actions/installOnSubreddit.d.ts +4 -0
- package/dist/util/common-actions/installOnSubreddit.d.ts.map +1 -0
- package/dist/util/common-actions/installOnSubreddit.js +14 -0
- package/dist/util/common-actions/waitUntilVersionBuildComplete.d.ts +4 -0
- package/dist/util/common-actions/waitUntilVersionBuildComplete.d.ts.map +1 -0
- package/dist/util/common-actions/waitUntilVersionBuildComplete.js +23 -0
- package/dist/util/project.d.ts +6 -0
- package/dist/util/project.d.ts.map +1 -1
- package/dist/util/project.js +31 -0
- package/dist/util/project.test.js +13 -0
- package/package.json +9 -8
package/bin/devvit.js
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
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';
|
|
6
7
|
|
|
7
8
|
import { getCurrentCommandEventData } from '../dist/lib/hooks/init/fire-event.js';
|
|
8
9
|
import { sendEvent } from '../dist/util/metrics.js';
|
|
9
10
|
|
|
11
|
+
dotenvConfig();
|
|
12
|
+
|
|
10
13
|
run(undefined, import.meta.url)
|
|
11
14
|
.then(() => flush())
|
|
12
15
|
.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, Record<string, unknown>>;
|
|
20
|
+
readonly subreddit: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, 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":"AAqCA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAQlE,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,aAAa;;IACjD,OAAgB,WAAW,SACgK;IAE3L,OAAgB,QAAQ,WAKtB;IAEF,OAAgB,KAAK;;;;;;;;;;;;MAoBV;IAEX,OAAgB,IAAI;;MAMT;IAuDI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;cAyKV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA8P/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,
|
|
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;
|
|
13
13
|
import { updateBundleServer, updateBundleVersion } from '@devvit/build-pack/esbuild/ESBuildPack.js';
|
|
14
|
-
import {
|
|
14
|
+
import { 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,6 +34,8 @@ 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';
|
|
37
39
|
import { getAppBySlug } from '../util/getAppBySlug.js';
|
|
38
40
|
import { Project } from '../util/project.js';
|
|
39
41
|
import Logs from './logs.js';
|
|
@@ -117,14 +119,15 @@ class Playtest extends DevvitCommand {
|
|
|
117
119
|
appSlug: __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.slug,
|
|
118
120
|
appSemver: __classPrivateFieldGet(this, _Playtest_version, "f"),
|
|
119
121
|
visibility: VersionVisibility.PRIVATE,
|
|
120
|
-
}, __classPrivateFieldGet(this, _Playtest_lastBundles, "f")
|
|
122
|
+
}, __classPrivateFieldGet(this, _Playtest_lastBundles, "f"), true // The playtest subreddit should've already been created so we prevent creating a new one
|
|
123
|
+
);
|
|
121
124
|
if (__classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f")) {
|
|
122
125
|
// No need to go further if there's a newer playtest version is waiting
|
|
123
126
|
__classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_runQueuedBundlePlaytest).call(this, __classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f"));
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
126
129
|
// 5. confirm new version has finished building
|
|
127
|
-
await __classPrivateFieldGet(this,
|
|
130
|
+
await waitUntilVersionBuildComplete(this, __classPrivateFieldGet(this, _Playtest_appVersionClient, "f"), appVersionInfo);
|
|
128
131
|
if (__classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f")) {
|
|
129
132
|
// No need to go further if there's a newer playtest version is waiting
|
|
130
133
|
__classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_runQueuedBundlePlaytest).call(this, __classPrivateFieldGet(this, _Playtest_lastQueuedBundles, "f"));
|
|
@@ -160,8 +163,8 @@ class Playtest extends DevvitCommand {
|
|
|
160
163
|
});
|
|
161
164
|
const { args, flags } = await this.parse(_a);
|
|
162
165
|
__classPrivateFieldSet(this, _Playtest_flags, flags, "f");
|
|
163
|
-
__classPrivateFieldSet(this, _Playtest_subreddit, getSubredditNameWithoutPrefix(args.subreddit), "f");
|
|
164
166
|
this.project.flag.watchDebounceMillis = __classPrivateFieldGet(this, _Playtest_flags, "f")?.['debounce'];
|
|
167
|
+
this.project.flag.subreddit = args.subreddit;
|
|
165
168
|
const token = await getAccessTokenAndLoginIfNeeded();
|
|
166
169
|
const username = await this.getUserDisplayName(token);
|
|
167
170
|
await this.checkDeveloperAccount();
|
|
@@ -181,28 +184,65 @@ class Playtest extends DevvitCommand {
|
|
|
181
184
|
if (!__classPrivateFieldGet(this, _Playtest_appInfo, "f")?.app) {
|
|
182
185
|
this.error("Your app doesn't exist yet - you'll need to run 'devvit upload' before you can playtest your app.");
|
|
183
186
|
}
|
|
187
|
+
this.project.app.defaultPlaytestSubredditId = __classPrivateFieldGet(this, _Playtest_appInfo, "f").app.defaultPlaytestSubredditId;
|
|
184
188
|
const isOwner = __classPrivateFieldGet(this, _Playtest_appInfo, "f")?.app?.owner?.displayName === username;
|
|
185
189
|
await __classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_checkIfUserAllowedToPlaytestThisApp).call(this, this.project.name, isOwner, token, flags['employee-update']);
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
// Set the target subreddit to the passed argument, or to the config subreddit, or to the app's default, in this order.
|
|
191
|
+
// If none of these are set, it will be undefined, and we will create a new playtest subreddit.
|
|
192
|
+
const targetSubreddit = this.project.getSubreddit('Dev');
|
|
193
|
+
if (targetSubreddit) {
|
|
194
|
+
__classPrivateFieldSet(this, _Playtest_subreddit, getSubredditNameWithoutPrefix(targetSubreddit), "f");
|
|
190
195
|
}
|
|
191
|
-
const
|
|
196
|
+
const shouldWriteToConfig = !__classPrivateFieldGet(this, _Playtest_subreddit, "f");
|
|
197
|
+
let latestVersion = __classPrivateFieldGet(this, _Playtest_appInfo, "f").versions[0];
|
|
192
198
|
__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. Please playtest on a different subreddit using `devvit playtest <your_subreddit>` instead.');
|
|
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
|
+
}
|
|
193
239
|
// before starting playtest session, make sure app has been installed to the test subreddit:
|
|
194
240
|
__classPrivateFieldSet(this, _Playtest_installationInfo, await __classPrivateFieldGet(this, _Playtest_instances, "m", _Playtest_getExistingInstallInfo).call(this, this.project.name, __classPrivateFieldGet(this, _Playtest_subreddit, "f")), "f");
|
|
195
241
|
if (!__classPrivateFieldGet(this, _Playtest_installationInfo, "f")) {
|
|
196
|
-
const userT2Id = await this.getUserT2Id(token);
|
|
197
242
|
ux.action.start(`Installing`);
|
|
198
243
|
try {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
runAs: userT2Id,
|
|
202
|
-
type: InstallationType.SUBREDDIT,
|
|
203
|
-
location: __classPrivateFieldGet(this, _Playtest_subreddit, "f"),
|
|
204
|
-
upgradeStrategy: 0,
|
|
205
|
-
}), "f");
|
|
244
|
+
const userT2Id = await this.getUserT2Id(token);
|
|
245
|
+
__classPrivateFieldSet(this, _Playtest_installationInfo, await installOnSubreddit(this, __classPrivateFieldGet(this, _Playtest_appVersionClient, "f"), __classPrivateFieldGet(this, _Playtest_installationsClient, "f"), userT2Id, latestVersion, __classPrivateFieldGet(this, _Playtest_subreddit, "f")), "f");
|
|
206
246
|
ux.action.stop();
|
|
207
247
|
}
|
|
208
248
|
catch (err) {
|
|
@@ -210,6 +250,10 @@ class Playtest extends DevvitCommand {
|
|
|
210
250
|
this.error(`An error occurred while installing your app: ${StringUtil.caughtToString(err, 'message')}`);
|
|
211
251
|
}
|
|
212
252
|
}
|
|
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
|
+
}
|
|
213
257
|
__classPrivateFieldSet(this, _Playtest_appLogSub, makeLogSubscription({
|
|
214
258
|
subreddit: __classPrivateFieldGet(this, _Playtest_installationInfo, "f").installation.location.id,
|
|
215
259
|
appName: this.project.name,
|
|
@@ -251,28 +295,6 @@ _a = Playtest, _Playtest_installationsClient = new WeakMap(), _Playtest_appClien
|
|
|
251
295
|
this.error('Something went wrong when checking for existing installations');
|
|
252
296
|
}
|
|
253
297
|
}
|
|
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
|
-
}
|
|
276
298
|
}, _Playtest_startWatchingSrc = function _Playtest_startWatchingSrc(username) {
|
|
277
299
|
const watchSrc = __classPrivateFieldGet(this, _Playtest_bundler, "f").watch(this.project, this.project.root, {
|
|
278
300
|
name: ACTOR_SRC_PRIMARY_NAME,
|
|
@@ -370,6 +392,7 @@ async function _Playtest_waitUntilVersionBuildComplete(appVersionInfo) {
|
|
|
370
392
|
};
|
|
371
393
|
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';
|
|
372
394
|
Playtest.examples = [
|
|
395
|
+
'$ devvit playtest',
|
|
373
396
|
'$ devvit playtest <subreddit>',
|
|
374
397
|
'$ devvit playtest r/myTestSubreddit',
|
|
375
398
|
'$ devvit playtest myOtherTestSubreddit',
|
|
@@ -396,12 +419,9 @@ Playtest.flags = {
|
|
|
396
419
|
};
|
|
397
420
|
Playtest.args = {
|
|
398
421
|
subreddit: Args.string({
|
|
399
|
-
description: `Provide the name of a small test subreddit with <${MAX_ALLOWED_SUBSCRIBER_COUNT} members. The "r/" prefix is optional
|
|
400
|
-
required:
|
|
422
|
+
description: `Provide the name of a small test subreddit with <${MAX_ALLOWED_SUBSCRIBER_COUNT} members. The "r/" prefix is optional. Leaving this empty will use the subreddit set in the in the "dev.subreddit" field of devvit.json. If neither is set, we will create a "r/[app-name]_dev" subreddit for you.`,
|
|
423
|
+
required: false,
|
|
401
424
|
parse: toLowerCaseArgParser,
|
|
402
425
|
}),
|
|
403
426
|
};
|
|
404
427
|
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":"AAgBA,OAAO,EAAiB,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAexE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAMlE,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,aAAa;;IAC/C,OAAgB,WAAW,SAA+M;IAE1O,OAAgB,KAAK;;;;;;;MA0CV;IAiBL,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAyMX,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAoD1D"}
|
package/dist/commands/upload.js
CHANGED
|
@@ -9,23 +9,25 @@ 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, _Upload_event, _Upload_eventSent, _Upload_checkDependencies, _Upload_canImportPublicAPI, _Upload_getNextVersionNumber, _Upload_bundleActors, _Upload_sendEventIfNotSent;
|
|
12
|
+
var _Upload_instances, _Upload_appClient, _Upload_installationsClient, _Upload_event, _Upload_eventSent, _Upload_checkDependencies, _Upload_canImportPublicAPI, _Upload_getNextVersionNumber, _Upload_bundleActors, _Upload_sendEventIfNotSent, _Upload_installOnDefaultPlaytestSubreddit;
|
|
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, VersionVisibility } from '@devvit/protos/community.js';
|
|
16
|
+
import { AppVersionInfo, FullAppInfo, FullInstallationInfo, 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';
|
|
22
23
|
import { isCurrentUserEmployee } from '../lib/http/gql.js';
|
|
23
24
|
import { AppUploader } from '../util/AppUploader.js';
|
|
24
25
|
import { AppVersionUploader } from '../util/AppVersionUploader.js';
|
|
25
26
|
import { getAccessTokenAndLoginIfNeeded } from '../util/auth.js';
|
|
26
27
|
import { Bundler } from '../util/Bundler.js';
|
|
27
|
-
import { createAppClient } from '../util/clientGenerators.js';
|
|
28
|
+
import { createAppClient, createAppVersionClient, createInstallationsClient, } from '../util/clientGenerators.js';
|
|
28
29
|
import { DevvitCommand } from '../util/commands/DevvitCommand.js';
|
|
30
|
+
import { installOnSubreddit } from '../util/common-actions/installOnSubreddit.js';
|
|
29
31
|
import { DEVVIT_PORTAL_URL } from '../util/config.js';
|
|
30
32
|
import { getAppBySlug } from '../util/getAppBySlug.js';
|
|
31
33
|
import { sendEvent } from '../util/metrics.js';
|
|
@@ -34,6 +36,7 @@ class Upload extends DevvitCommand {
|
|
|
34
36
|
super(...arguments);
|
|
35
37
|
_Upload_instances.add(this);
|
|
36
38
|
_Upload_appClient.set(this, createAppClient());
|
|
39
|
+
_Upload_installationsClient.set(this, createInstallationsClient());
|
|
37
40
|
_Upload_event.set(this, {
|
|
38
41
|
source: 'devplatform_cli',
|
|
39
42
|
action: 'ran',
|
|
@@ -97,6 +100,7 @@ class Upload extends DevvitCommand {
|
|
|
97
100
|
if (!appInfo?.app) {
|
|
98
101
|
this.error(`App ${this.project.name} is not found`);
|
|
99
102
|
}
|
|
103
|
+
this.project.app.defaultPlaytestSubredditId = appInfo.app.defaultPlaytestSubredditId;
|
|
100
104
|
// Now, create a new version.
|
|
101
105
|
const appVersionNumber = await __classPrivateFieldGet(this, _Upload_instances, "m", _Upload_getNextVersionNumber).call(this, appInfo, flags.bump);
|
|
102
106
|
__classPrivateFieldGet(this, _Upload_event, "f").devplatform.app_version_number = appVersionNumber.toString();
|
|
@@ -105,12 +109,32 @@ class Upload extends DevvitCommand {
|
|
|
105
109
|
ux.action.stop();
|
|
106
110
|
try {
|
|
107
111
|
const appVersionUploader = new AppVersionUploader(this, { verbose: flags.verbose });
|
|
108
|
-
|
|
112
|
+
const shouldCreatePlaytestSubreddit = !this.project.getSubreddit('Dev');
|
|
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({
|
|
109
117
|
appId: appInfo.app.id,
|
|
110
118
|
appSlug: appInfo.app.slug,
|
|
111
119
|
appSemver: appVersionNumber,
|
|
112
120
|
visibility: VersionVisibility.PRIVATE,
|
|
113
|
-
}, bundles);
|
|
121
|
+
}, bundles, !shouldCreatePlaytestSubreddit);
|
|
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
|
+
}
|
|
114
138
|
}
|
|
115
139
|
catch (err) {
|
|
116
140
|
const errMessage = StringUtil.caughtToString(err, 'message');
|
|
@@ -132,7 +156,7 @@ class Upload extends DevvitCommand {
|
|
|
132
156
|
return super.catch(err);
|
|
133
157
|
}
|
|
134
158
|
}
|
|
135
|
-
_Upload_appClient = new WeakMap(), _Upload_event = new WeakMap(), _Upload_eventSent = new WeakMap(), _Upload_instances = new WeakSet(), _Upload_checkDependencies =
|
|
159
|
+
_Upload_appClient = new WeakMap(), _Upload_installationsClient = new WeakMap(), _Upload_event = new WeakMap(), _Upload_eventSent = new WeakMap(), _Upload_instances = new WeakSet(), _Upload_checkDependencies =
|
|
136
160
|
/**
|
|
137
161
|
* If we're not just doing it, check and make sure there's a chance our build will succeed.
|
|
138
162
|
*/
|
|
@@ -187,6 +211,34 @@ async function _Upload_checkDependencies(justDoIt) {
|
|
|
187
211
|
__classPrivateFieldSet(this, _Upload_eventSent, true, "f");
|
|
188
212
|
await sendEvent(__classPrivateFieldGet(this, _Upload_event, "f"));
|
|
189
213
|
}
|
|
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.warn(`We couldn't find the default playtest subreddit for ${this.project.name}, but one will be created during your next ${'`devvit upload`'} or ${'`devvit playtest`'}.`);
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
ux.action.start('Installing app to default playtest subreddit');
|
|
232
|
+
const userT2Id = await this.getUserT2Id(token);
|
|
233
|
+
const installationInfo = await installOnSubreddit(this, createAppVersionClient(), __classPrivateFieldGet(this, _Upload_installationsClient, "f"), userT2Id, appVersion, appInfo.app.defaultPlaytestSubredditId);
|
|
234
|
+
ux.action.stop();
|
|
235
|
+
return installationInfo;
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
ux.action.stop('Warning');
|
|
239
|
+
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')}`);
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
190
242
|
};
|
|
191
243
|
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`;
|
|
192
244
|
Upload.flags = {
|
package/dist/lib/http/gql.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ 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
|
+
*/
|
|
14
21
|
export declare function fetchSubredditSubscriberCount(subreddit: string, token: StoredToken): Promise<number>;
|
|
15
22
|
export declare function getUserId(username: string, token: StoredToken): Promise<string>;
|
|
16
23
|
//# 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;AAI/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAY1D,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;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAmCjB;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,9 +1,11 @@
|
|
|
1
|
+
import { isT5ID } from '@devvit/shared-types/tid.js';
|
|
1
2
|
import { GQL_QUERY_URL } from '../../util/config.js';
|
|
2
3
|
import { MY_PORTAL_ENABLED } from '../config.js';
|
|
3
4
|
// TODO: figure out how to get proper types from graphql.ts in portal
|
|
4
5
|
const IDENTITY_QUERY_HASH = '1936294e5fc812fe34e30c5527b69400a8c44becf417c0c44acffebd3f1632d6';
|
|
5
6
|
const GET_SUBREDDIT_INFO_BY_NAME_QUERY_HASH = 'f1d2d2ac1ef6e39f9c4a103960d5b07d83665073a376c7852655fae2f1ad5159';
|
|
6
7
|
const GET_REDDITOR_INFO_BY_NAME_QUERY_HASH = '19b0be6bef17faf58939802d3858fec2622ba5ec28d6b8a2982998749ceca30b';
|
|
8
|
+
const GET_SUBREDDIT_INFO_BY_ID_QUERY_HASH = '109b67500ceb4e883d6a0e15e1699948e957bf85dc630651f1e10463b6ed5db6';
|
|
7
9
|
export async function gqlQuery(config) {
|
|
8
10
|
const resp = await fetch(`${GQL_QUERY_URL}`, {
|
|
9
11
|
method: 'POST',
|
|
@@ -38,20 +40,41 @@ export async function isCurrentUserEmployee(token) {
|
|
|
38
40
|
});
|
|
39
41
|
return identity.data.identity.isEmployee;
|
|
40
42
|
}
|
|
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
|
+
*/
|
|
41
50
|
export async function fetchSubredditSubscriberCount(subreddit, token) {
|
|
42
51
|
// Hack: GQL is failing below on snoodev.
|
|
43
52
|
if (MY_PORTAL_ENABLED)
|
|
44
53
|
return 0;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
if (isT5ID(subreddit)) {
|
|
55
|
+
const subredditInfo = await gqlQuery({
|
|
56
|
+
accessToken: token.accessToken,
|
|
57
|
+
hash: GET_SUBREDDIT_INFO_BY_ID_QUERY_HASH,
|
|
58
|
+
name: 'GetSubredditInfoById',
|
|
59
|
+
variables: { id: subreddit },
|
|
60
|
+
});
|
|
61
|
+
if (!subredditInfo.data.subredditInfoById) {
|
|
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;
|
|
53
77
|
}
|
|
54
|
-
return subredditInfo.data.subredditInfoByName.subscribersCount;
|
|
55
78
|
}
|
|
56
79
|
export async function getUserId(username, token) {
|
|
57
80
|
// Hack: GQL is failing below on snoodev.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "experience-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"typescript": "5.8.3"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "empty-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"typescript": "5.8.3"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "payment-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/payments": "0.11.
|
|
9
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/payments": "0.11.18-dev",
|
|
9
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"typescript": "5.8.3"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "payments-web-view-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/payments": "0.11.
|
|
9
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/payments": "0.11.18-dev",
|
|
9
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"typescript": "5.8.3"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "pen-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"typescript": "5.8.3"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": true,
|
|
3
3
|
"name": "web-view-template",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.18-dev",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@devvit/public-api": "0.11.
|
|
8
|
+
"@devvit/public-api": "0.11.18-dev"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"typescript": "5.8.3"
|
|
@@ -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_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): Buffer;
|
|
23
|
-
export declare function transformHTML(str: string): string;
|
|
22
|
+
export declare function transformHTMLBuffer(buf: Buffer, clientVersionNum: string | undefined): Buffer;
|
|
23
|
+
export declare function transformHTML(str: string, clientVersionNum: string | undefined): 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":"AASA,OAAO,EAEL,KAAK,QAAQ,EAKd,MAAM,gCAAgC,CAAC;AAUxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,eAAO,MAAM,aAAa,wDAAwD,CAAC;AAMnF,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;CA+OH;AA8DD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAI7F;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAuBvF"}
|
|
@@ -9,18 +9,20 @@ 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,
|
|
12
|
+
var _AssetUploader_instances, _AssetUploader_cmd, _AssetUploader_verbose, _AssetUploader_appClient, _AssetUploader_appSlug, _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';
|
|
15
16
|
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';
|
|
16
17
|
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';
|
|
17
19
|
import { ux } from '@oclif/core';
|
|
18
20
|
import { createHash } from 'crypto';
|
|
19
21
|
import { JSDOM } from 'jsdom';
|
|
20
22
|
import { default as tinyglob } from 'tiny-glob';
|
|
21
23
|
import { dirExists } from '../util/files.js';
|
|
22
24
|
import { createAppClient } from './clientGenerators.js';
|
|
23
|
-
export const
|
|
25
|
+
export const DEVVIT_JS_URL = 'https://webview.devvit.net/scripts/devvit.v1.min.js';
|
|
24
26
|
export class AssetUploader {
|
|
25
27
|
constructor(cmd, appSlug, { verbose }) {
|
|
26
28
|
_AssetUploader_instances.add(this);
|
|
@@ -41,11 +43,14 @@ export class AssetUploader {
|
|
|
41
43
|
* the asset map.
|
|
42
44
|
*/
|
|
43
45
|
async syncAssets() {
|
|
46
|
+
const clientVersion = readClientVersion(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root);
|
|
44
47
|
const [regularAssets, webViewAssets] = await Promise.all([
|
|
45
48
|
__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.mediaDir
|
|
46
|
-
? __classPrivateFieldGet(this,
|
|
49
|
+
? queryAssets(path.join(__classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.root, __classPrivateFieldGet(this, _AssetUploader_cmd, "f").project.mediaDir), ALLOWED_ASSET_EXTENSIONS, 'Media', clientVersion)
|
|
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)
|
|
47
53
|
: [],
|
|
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) : [],
|
|
49
54
|
]);
|
|
50
55
|
// Return early if no assets
|
|
51
56
|
if (regularAssets.length + webViewAssets.length === 0) {
|
|
@@ -65,40 +70,7 @@ export class AssetUploader {
|
|
|
65
70
|
return { assetMap, webViewAssetMap };
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
|
-
_AssetUploader_cmd = new WeakMap(), _AssetUploader_verbose = new WeakMap(), _AssetUploader_appClient = new WeakMap(), _AssetUploader_appSlug = new WeakMap(), _AssetUploader_instances = new WeakSet(),
|
|
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) {
|
|
73
|
+
_AssetUploader_cmd = new WeakMap(), _AssetUploader_verbose = new WeakMap(), _AssetUploader_appClient = new WeakMap(), _AssetUploader_appSlug = new WeakMap(), _AssetUploader_instances = new WeakSet(), _AssetUploader_processRegularAssets = async function _AssetUploader_processRegularAssets(assets) {
|
|
102
74
|
// early out to avoid logging if empty
|
|
103
75
|
if (assets.length === 0) {
|
|
104
76
|
return {};
|
|
@@ -247,27 +219,75 @@ async function _AssetUploader_mapAssets(assets, statuses) {
|
|
|
247
219
|
});
|
|
248
220
|
return { newAssets, duplicateAssets, existingAssets };
|
|
249
221
|
};
|
|
250
|
-
|
|
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) {
|
|
251
269
|
const inStr = new TextDecoder('utf-8').decode(buf);
|
|
252
|
-
const out = transformHTML(inStr);
|
|
270
|
+
const out = transformHTML(inStr, clientVersionNum);
|
|
253
271
|
return Buffer.from(out);
|
|
254
272
|
}
|
|
255
|
-
export function transformHTML(str) {
|
|
273
|
+
export function transformHTML(str, clientVersionNum) {
|
|
256
274
|
const { document } = new JSDOM(str).window;
|
|
257
275
|
// if no html tag, return early
|
|
258
276
|
const htmlTag = document.querySelector('html');
|
|
259
277
|
if (htmlTag == null) {
|
|
260
278
|
return str;
|
|
261
279
|
}
|
|
262
|
-
const
|
|
280
|
+
const clientVersionQueryArg = clientVersionNum
|
|
281
|
+
? `${clientVersionQueryParam}=${clientVersionNum}`
|
|
282
|
+
: '';
|
|
283
|
+
const scriptTag = `<script src="${DEVVIT_JS_URL}?${clientVersionQueryArg}"></script>`;
|
|
263
284
|
// if no head tag, create one after the html tag
|
|
264
285
|
const headTag = document.querySelector('head');
|
|
265
286
|
if (headTag == null) {
|
|
266
287
|
htmlTag.insertAdjacentHTML('afterbegin', `<head>${scriptTag}</head>`); // eslint-disable-line no-unsanitized/method
|
|
267
288
|
}
|
|
268
289
|
else {
|
|
269
|
-
|
|
270
|
-
headTag.insertAdjacentHTML('beforeend', scriptTag); // eslint-disable-line no-unsanitized/method
|
|
290
|
+
headTag.insertAdjacentHTML('afterbegin', scriptTag); // eslint-disable-line no-unsanitized/method
|
|
271
291
|
}
|
|
272
292
|
return document.documentElement.outerHTML;
|
|
273
293
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { clientVersionQueryParam } from '@devvit/shared-types/web-view-scripts-constants.js';
|
|
1
2
|
import { JSDOM } from 'jsdom';
|
|
2
3
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
+
import { DEVVIT_JS_URL, transformHTML } from './AssetUploader.js';
|
|
4
5
|
describe('HTML Transformation', () => {
|
|
5
6
|
describe('transformHTML', () => {
|
|
6
7
|
it('should add script tag to head when head exists', () => {
|
|
@@ -15,7 +16,7 @@ describe('HTML Transformation', () => {
|
|
|
15
16
|
</body>
|
|
16
17
|
</html>
|
|
17
18
|
`;
|
|
18
|
-
const result = transformHTML(input);
|
|
19
|
+
const result = transformHTML(input, '1.2.3');
|
|
19
20
|
const dom = new JSDOM(result);
|
|
20
21
|
const document = dom.window.document;
|
|
21
22
|
// Verify script tag exists in head
|
|
@@ -34,7 +35,7 @@ describe('HTML Transformation', () => {
|
|
|
34
35
|
</body>
|
|
35
36
|
</html>
|
|
36
37
|
`;
|
|
37
|
-
const result = transformHTML(input);
|
|
38
|
+
const result = transformHTML(input, '1.2.3');
|
|
38
39
|
const dom = new JSDOM(result);
|
|
39
40
|
const document = dom.window.document;
|
|
40
41
|
// Verify head tag exists
|
|
@@ -57,11 +58,22 @@ describe('HTML Transformation', () => {
|
|
|
57
58
|
</body>
|
|
58
59
|
</html>
|
|
59
60
|
`;
|
|
60
|
-
const result = transformHTML(input);
|
|
61
|
+
const result = transformHTML(input, '1.2.3');
|
|
61
62
|
const dom = new JSDOM(result);
|
|
62
63
|
const document = dom.window.document;
|
|
63
64
|
// Verify script tag exists
|
|
64
|
-
const script = document.querySelector(`script[src="${
|
|
65
|
+
const script = document.querySelector(`script[src="${DEVVIT_JS_URL}?${clientVersionQueryParam}=1.2.3"]`);
|
|
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"]`);
|
|
65
77
|
assertScriptExpectations(script);
|
|
66
78
|
});
|
|
67
79
|
it('should handle HTML with existing script tags', () => {
|
|
@@ -76,7 +88,7 @@ describe('HTML Transformation', () => {
|
|
|
76
88
|
</body>
|
|
77
89
|
</html>
|
|
78
90
|
`;
|
|
79
|
-
const result = transformHTML(input);
|
|
91
|
+
const result = transformHTML(input, '1.2.3');
|
|
80
92
|
const dom = new JSDOM(result);
|
|
81
93
|
const document = dom.window.document;
|
|
82
94
|
// Verify both script tags exist
|
|
@@ -90,10 +102,8 @@ describe('HTML Transformation', () => {
|
|
|
90
102
|
});
|
|
91
103
|
});
|
|
92
104
|
function selectScript(document) {
|
|
93
|
-
return document.querySelector(`head script[src="${
|
|
105
|
+
return document.querySelector(`head script[src="${DEVVIT_JS_URL}?${clientVersionQueryParam}=1.2.3"]`);
|
|
94
106
|
}
|
|
95
107
|
function assertScriptExpectations(script) {
|
|
96
108
|
expect(script).not.toBeNull();
|
|
97
|
-
expect(script?.getAttribute('async')).toBe('');
|
|
98
|
-
expect(script?.getAttribute('type')).toBe('module');
|
|
99
109
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
package/dist/util/project.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ 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;
|
|
37
41
|
};
|
|
38
42
|
readonly root: ProjectRootDir;
|
|
39
43
|
readonly filename: string;
|
|
@@ -47,6 +51,8 @@ export declare class Project {
|
|
|
47
51
|
get post(): Readonly<AppPostConfig | undefined>;
|
|
48
52
|
get server(): Readonly<AppServerConfig | undefined>;
|
|
49
53
|
get watchDebounceMillis(): number;
|
|
54
|
+
getSubreddit(mode: 'Dev' | 'Prod'): string | undefined;
|
|
55
|
+
setSubreddit(subreddit: string, mode: 'Dev' | 'Prod'): void;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
58
|
* 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,CAAA;KAAE,CAAM;
|
|
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,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAM;IACjG,QAAQ,CAAC,GAAG,EAAE;QAAE,0BAA0B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAM;IACvE,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;IAED,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAmBtD,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,MAAM;CAcrD;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,6 +51,7 @@ export class Project {
|
|
|
51
51
|
}
|
|
52
52
|
constructor(root, filename, config, packageConfig) {
|
|
53
53
|
this.flag = {};
|
|
54
|
+
this.app = {};
|
|
54
55
|
_Project_config.set(this, void 0);
|
|
55
56
|
/** @deprecated Use the config-file.v1.json schema instead. */
|
|
56
57
|
_Project_packageConfig.set(this, void 0);
|
|
@@ -92,6 +93,36 @@ export class Project {
|
|
|
92
93
|
get watchDebounceMillis() {
|
|
93
94
|
return this.flag.watchDebounceMillis ?? __classPrivateFieldGet(this, _Project_packageConfig, "f")?.playtest?.debounceConfigMs ?? 100;
|
|
94
95
|
}
|
|
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
|
+
}
|
|
95
126
|
}
|
|
96
127
|
_Project_config = new WeakMap(), _Project_packageConfig = new WeakMap();
|
|
97
128
|
/**
|
|
@@ -48,6 +48,19 @@ 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
|
+
});
|
|
51
64
|
});
|
|
52
65
|
describe('validateConfig()', () => {
|
|
53
66
|
test('blocks.entry', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/cli",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
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.
|
|
45
|
+
"@devvit/build-pack": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
46
46
|
"@devvit/play": "0.0.45",
|
|
47
|
-
"@devvit/protos": "0.11.
|
|
48
|
-
"@devvit/public-api": "0.11.
|
|
49
|
-
"@devvit/shared-types": "0.11.
|
|
47
|
+
"@devvit/protos": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
48
|
+
"@devvit/public-api": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
49
|
+
"@devvit/shared-types": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
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,6 +58,7 @@
|
|
|
58
58
|
"chalk": "4.1.2",
|
|
59
59
|
"chokidar": "3.5.3",
|
|
60
60
|
"date-fns": "2.29.3",
|
|
61
|
+
"dotenv": "16.5.0",
|
|
61
62
|
"file-type": "18.2.1",
|
|
62
63
|
"image-size": "1.2.1",
|
|
63
64
|
"inquirer": "9.1.4",
|
|
@@ -74,8 +75,8 @@
|
|
|
74
75
|
"ws": "8.18.0"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@devvit/repo-tools": "0.11.
|
|
78
|
-
"@devvit/tsconfig": "0.11.
|
|
78
|
+
"@devvit/repo-tools": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
79
|
+
"@devvit/tsconfig": "0.11.18-next-2025-06-16-20-45-28-cf17b48ff.0",
|
|
79
80
|
"@types/file-type": "10.9.1",
|
|
80
81
|
"@types/inquirer": "9.0.3",
|
|
81
82
|
"@types/js-yaml": "4.0.5",
|
|
@@ -112,5 +113,5 @@
|
|
|
112
113
|
]
|
|
113
114
|
}
|
|
114
115
|
},
|
|
115
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "0cda7b2dc87ba13711b2b7dd132d7cb7d4b58f02"
|
|
116
117
|
}
|