@puzzmo/cli 1.0.80 → 1.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/lib/commands/game/create.d.ts +11 -1
- package/lib/commands/game/create.js +62 -2
- package/lib/commands/game/create.js.map +1 -1
- package/lib/commands/puzzles.d.ts +8 -0
- package/lib/commands/puzzles.js +107 -0
- package/lib/commands/puzzles.js.map +1 -0
- package/lib/index.js +18 -1
- package/lib/index.js.map +1 -1
- package/lib/queries/__generated__/cliAddPuzzlesToPoolMutation.graphql.d.ts +30 -0
- package/lib/queries/__generated__/cliAddPuzzlesToPoolMutation.graphql.js +123 -0
- package/lib/queries/__generated__/cliAddPuzzlesToPoolMutation.graphql.js.map +1 -0
- package/lib/queries/__generated__/cliGamesForAccessTokenQuery.graphql.d.ts +19 -0
- package/lib/queries/__generated__/cliGamesForAccessTokenQuery.graphql.js +67 -0
- package/lib/queries/__generated__/cliGamesForAccessTokenQuery.graphql.js.map +1 -0
- package/lib/queries/__generated__/cliValidatePoolPuzzlesQuery.graphql.d.ts +27 -0
- package/lib/queries/__generated__/cliValidatePoolPuzzlesQuery.graphql.js +105 -0
- package/lib/queries/__generated__/cliValidatePoolPuzzlesQuery.graphql.js.map +1 -0
- package/lib/queries/puzzlePool.d.ts +21 -0
- package/lib/queries/puzzlePool.js +59 -0
- package/lib/queries/puzzlePool.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/game/adoptPico8Cart.test.ts +33 -0
- package/src/commands/game/create.ts +67 -3
- package/src/commands/puzzles.ts +121 -0
- package/src/index.ts +20 -1
- package/src/queries/__generated__/cliAddPuzzlesToPoolMutation.graphql.ts +157 -0
- package/src/queries/__generated__/cliGamesForAccessTokenQuery.graphql.ts +88 -0
- package/src/queries/__generated__/cliValidatePoolPuzzlesQuery.graphql.ts +136 -0
- package/src/queries/puzzlePool.ts +65 -0
- package/templates/pico8/README.md +49 -0
- package/templates/pico8/cart/game.p8 +183 -0
- package/templates/pico8/cart/puzzmo.lua +133 -0
- package/templates/pico8/fixtures/puzzles/easy/five.txt +1 -0
- package/templates/pico8/fixtures/puzzles/easy/twelve.txt +1 -0
- package/templates/pico8/fixtures/puzzles/hard/ninety-nine.txt +1 -0
- package/templates/pico8/index.html +7 -0
- package/templates/pico8/package.json +20 -0
- package/templates/pico8/puzzmo.json +11 -0
- package/templates/pico8/src/main.ts +6 -0
- package/templates/pico8/tsconfig.json +13 -0
- package/templates/pico8/vite.config.ts +11 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<76fc8a9b6e4d8ebe2c47a8b32617c0be>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
import { ConcreteRequest } from 'relay-runtime';
|
|
6
|
+
export type cliGamesForAccessTokenQuery$variables = {
|
|
7
|
+
token: string;
|
|
8
|
+
};
|
|
9
|
+
export type cliGamesForAccessTokenQuery$data = {
|
|
10
|
+
readonly gamesForAccessToken: ReadonlyArray<{
|
|
11
|
+
readonly slug: string;
|
|
12
|
+
}> | null | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type cliGamesForAccessTokenQuery = {
|
|
15
|
+
response: cliGamesForAccessTokenQuery$data;
|
|
16
|
+
variables: cliGamesForAccessTokenQuery$variables;
|
|
17
|
+
};
|
|
18
|
+
declare const node: ConcreteRequest;
|
|
19
|
+
export default node;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<76fc8a9b6e4d8ebe2c47a8b32617c0be>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
const node = (function () {
|
|
6
|
+
var v0 = [
|
|
7
|
+
{
|
|
8
|
+
"defaultValue": null,
|
|
9
|
+
"kind": "LocalArgument",
|
|
10
|
+
"name": "token"
|
|
11
|
+
}
|
|
12
|
+
], v1 = [
|
|
13
|
+
{
|
|
14
|
+
"alias": null,
|
|
15
|
+
"args": [
|
|
16
|
+
{
|
|
17
|
+
"kind": "Variable",
|
|
18
|
+
"name": "token",
|
|
19
|
+
"variableName": "token"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"concreteType": "AccessibleGame",
|
|
23
|
+
"kind": "LinkedField",
|
|
24
|
+
"name": "gamesForAccessToken",
|
|
25
|
+
"plural": true,
|
|
26
|
+
"selections": [
|
|
27
|
+
{
|
|
28
|
+
"alias": null,
|
|
29
|
+
"args": null,
|
|
30
|
+
"kind": "ScalarField",
|
|
31
|
+
"name": "slug",
|
|
32
|
+
"storageKey": null
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"storageKey": null
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
return {
|
|
39
|
+
"fragment": {
|
|
40
|
+
"argumentDefinitions": (v0 /*:: as any*/),
|
|
41
|
+
"kind": "Fragment",
|
|
42
|
+
"metadata": null,
|
|
43
|
+
"name": "cliGamesForAccessTokenQuery",
|
|
44
|
+
"selections": (v1 /*:: as any*/),
|
|
45
|
+
"type": "Query",
|
|
46
|
+
"abstractKey": null
|
|
47
|
+
},
|
|
48
|
+
"kind": "Request",
|
|
49
|
+
"operation": {
|
|
50
|
+
"argumentDefinitions": (v0 /*:: as any*/),
|
|
51
|
+
"kind": "Operation",
|
|
52
|
+
"name": "cliGamesForAccessTokenQuery",
|
|
53
|
+
"selections": (v1 /*:: as any*/)
|
|
54
|
+
},
|
|
55
|
+
"params": {
|
|
56
|
+
"cacheID": "95e52459ee4e3b5b63aebf0a956d84b9",
|
|
57
|
+
"id": null,
|
|
58
|
+
"metadata": {},
|
|
59
|
+
"name": "cliGamesForAccessTokenQuery",
|
|
60
|
+
"operationKind": "query",
|
|
61
|
+
"text": "query cliGamesForAccessTokenQuery(\n $token: String!\n) {\n gamesForAccessToken(token: $token) {\n slug\n }\n}\n"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
node.hash = "5e25f82f0177e712ee4d7e9e95245d28";
|
|
66
|
+
export default node;
|
|
67
|
+
//# sourceMappingURL=cliGamesForAccessTokenQuery.graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliGamesForAccessTokenQuery.graphql.js","sourceRoot":"","sources":["../../../src/queries/__generated__/cliGamesForAccessTokenQuery.graphql.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,MAAM,IAAI,GAAoB,CAAC;IAC/B,IAAI,EAAE,GAAG;QACP;YACE,cAAc,EAAE,IAAI;YACpB,MAAM,EAAE,eAAe;YACvB,MAAM,EAAE,OAAO;SAChB;KACF,EACD,EAAE,GAAG;QACH;YACE,OAAO,EAAE,IAAI;YACb,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,UAAU;oBAClB,MAAM,EAAE,OAAO;oBACf,cAAc,EAAE,OAAO;iBACxB;aACF;YACD,cAAc,EAAE,gBAAgB;YAChC,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,qBAAqB;YAC7B,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE;gBACZ;oBACE,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,MAAM;oBACd,YAAY,EAAE,IAAI;iBACnB;aACF;YACD,YAAY,EAAE,IAAI;SACnB;KACF,CAAC;IACF,OAAO;QACL,UAAU,EAAE;YACV,qBAAqB,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;YACxC,MAAM,EAAE,UAAU;YAClB,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,6BAA6B;YACrC,YAAY,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;YAC/B,MAAM,EAAE,OAAO;YACf,aAAa,EAAE,IAAI;SACpB;QACD,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE;YACX,qBAAqB,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;YACxC,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,6BAA6B;YACrC,YAAY,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;SAChC;QACD,QAAQ,EAAE;YACR,SAAS,EAAE,kCAAkC;YAC7C,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,6BAA6B;YACrC,eAAe,EAAE,OAAO;YACxB,MAAM,EAAE,wHAAwH;SACjI;KACF,CAAC;AACF,CAAC,CAAC,EAAE,CAAC;AAEJ,IAAY,CAAC,IAAI,GAAG,kCAAkC,CAAC;AAExD,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<8b45a4259087b0ba56f45d09b2de210b>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
import { ConcreteRequest } from 'relay-runtime';
|
|
6
|
+
export type McpPuzzleFileInput = {
|
|
7
|
+
content: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
};
|
|
10
|
+
export type cliValidatePoolPuzzlesQuery$variables = {
|
|
11
|
+
gameSlug: string;
|
|
12
|
+
puzzles: ReadonlyArray<McpPuzzleFileInput>;
|
|
13
|
+
token: string;
|
|
14
|
+
};
|
|
15
|
+
export type cliValidatePoolPuzzlesQuery$data = {
|
|
16
|
+
readonly validatePoolPuzzles: ReadonlyArray<{
|
|
17
|
+
readonly errors: ReadonlyArray<string>;
|
|
18
|
+
readonly filename: string;
|
|
19
|
+
readonly valid: boolean;
|
|
20
|
+
}> | null | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type cliValidatePoolPuzzlesQuery = {
|
|
23
|
+
response: cliValidatePoolPuzzlesQuery$data;
|
|
24
|
+
variables: cliValidatePoolPuzzlesQuery$variables;
|
|
25
|
+
};
|
|
26
|
+
declare const node: ConcreteRequest;
|
|
27
|
+
export default node;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<8b45a4259087b0ba56f45d09b2de210b>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
const node = (function () {
|
|
6
|
+
var v0 = {
|
|
7
|
+
"defaultValue": null,
|
|
8
|
+
"kind": "LocalArgument",
|
|
9
|
+
"name": "gameSlug"
|
|
10
|
+
}, v1 = {
|
|
11
|
+
"defaultValue": null,
|
|
12
|
+
"kind": "LocalArgument",
|
|
13
|
+
"name": "puzzles"
|
|
14
|
+
}, v2 = {
|
|
15
|
+
"defaultValue": null,
|
|
16
|
+
"kind": "LocalArgument",
|
|
17
|
+
"name": "token"
|
|
18
|
+
}, v3 = [
|
|
19
|
+
{
|
|
20
|
+
"alias": null,
|
|
21
|
+
"args": [
|
|
22
|
+
{
|
|
23
|
+
"kind": "Variable",
|
|
24
|
+
"name": "gameSlug",
|
|
25
|
+
"variableName": "gameSlug"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"kind": "Variable",
|
|
29
|
+
"name": "puzzles",
|
|
30
|
+
"variableName": "puzzles"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"kind": "Variable",
|
|
34
|
+
"name": "token",
|
|
35
|
+
"variableName": "token"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"concreteType": "McpPoolPuzzleValidation",
|
|
39
|
+
"kind": "LinkedField",
|
|
40
|
+
"name": "validatePoolPuzzles",
|
|
41
|
+
"plural": true,
|
|
42
|
+
"selections": [
|
|
43
|
+
{
|
|
44
|
+
"alias": null,
|
|
45
|
+
"args": null,
|
|
46
|
+
"kind": "ScalarField",
|
|
47
|
+
"name": "filename",
|
|
48
|
+
"storageKey": null
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"alias": null,
|
|
52
|
+
"args": null,
|
|
53
|
+
"kind": "ScalarField",
|
|
54
|
+
"name": "valid",
|
|
55
|
+
"storageKey": null
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"alias": null,
|
|
59
|
+
"args": null,
|
|
60
|
+
"kind": "ScalarField",
|
|
61
|
+
"name": "errors",
|
|
62
|
+
"storageKey": null
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"storageKey": null
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
return {
|
|
69
|
+
"fragment": {
|
|
70
|
+
"argumentDefinitions": [
|
|
71
|
+
(v0 /*:: as any*/),
|
|
72
|
+
(v1 /*:: as any*/),
|
|
73
|
+
(v2 /*:: as any*/)
|
|
74
|
+
],
|
|
75
|
+
"kind": "Fragment",
|
|
76
|
+
"metadata": null,
|
|
77
|
+
"name": "cliValidatePoolPuzzlesQuery",
|
|
78
|
+
"selections": (v3 /*:: as any*/),
|
|
79
|
+
"type": "Query",
|
|
80
|
+
"abstractKey": null
|
|
81
|
+
},
|
|
82
|
+
"kind": "Request",
|
|
83
|
+
"operation": {
|
|
84
|
+
"argumentDefinitions": [
|
|
85
|
+
(v2 /*:: as any*/),
|
|
86
|
+
(v0 /*:: as any*/),
|
|
87
|
+
(v1 /*:: as any*/)
|
|
88
|
+
],
|
|
89
|
+
"kind": "Operation",
|
|
90
|
+
"name": "cliValidatePoolPuzzlesQuery",
|
|
91
|
+
"selections": (v3 /*:: as any*/)
|
|
92
|
+
},
|
|
93
|
+
"params": {
|
|
94
|
+
"cacheID": "934ec64898f9b820ebc69f223fd50cc5",
|
|
95
|
+
"id": null,
|
|
96
|
+
"metadata": {},
|
|
97
|
+
"name": "cliValidatePoolPuzzlesQuery",
|
|
98
|
+
"operationKind": "query",
|
|
99
|
+
"text": "query cliValidatePoolPuzzlesQuery(\n $token: String!\n $gameSlug: String!\n $puzzles: [McpPuzzleFileInput!]!\n) {\n validatePoolPuzzles(token: $token, gameSlug: $gameSlug, puzzles: $puzzles) {\n filename\n valid\n errors\n }\n}\n"
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
})();
|
|
103
|
+
node.hash = "08673f877fe016f880516c4a9fdcf03d";
|
|
104
|
+
export default node;
|
|
105
|
+
//# sourceMappingURL=cliValidatePoolPuzzlesQuery.graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliValidatePoolPuzzlesQuery.graphql.js","sourceRoot":"","sources":["../../../src/queries/__generated__/cliValidatePoolPuzzlesQuery.graphql.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4BH,MAAM,IAAI,GAAoB,CAAC;IAC/B,IAAI,EAAE,GAAG;QACP,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE,UAAU;KACnB,EACD,EAAE,GAAG;QACH,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE,SAAS;KAClB,EACD,EAAE,GAAG;QACH,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE,OAAO;KAChB,EACD,EAAE,GAAG;QACH;YACE,OAAO,EAAE,IAAI;YACb,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,UAAU;oBAClB,MAAM,EAAE,UAAU;oBAClB,cAAc,EAAE,UAAU;iBAC3B;gBACD;oBACE,MAAM,EAAE,UAAU;oBAClB,MAAM,EAAE,SAAS;oBACjB,cAAc,EAAE,SAAS;iBAC1B;gBACD;oBACE,MAAM,EAAE,UAAU;oBAClB,MAAM,EAAE,OAAO;oBACf,cAAc,EAAE,OAAO;iBACxB;aACF;YACD,cAAc,EAAE,yBAAyB;YACzC,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,qBAAqB;YAC7B,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE;gBACZ;oBACE,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,UAAU;oBAClB,YAAY,EAAE,IAAI;iBACnB;gBACD;oBACE,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,OAAO;oBACf,YAAY,EAAE,IAAI;iBACnB;gBACD;oBACE,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,QAAQ;oBAChB,YAAY,EAAE,IAAI;iBACnB;aACF;YACD,YAAY,EAAE,IAAI;SACnB;KACF,CAAC;IACF,OAAO;QACL,UAAU,EAAE;YACV,qBAAqB,EAAE;gBACrB,CAAC,EAAE,CAAA,aAAa,CAAC;gBACjB,CAAC,EAAE,CAAA,aAAa,CAAC;gBACjB,CAAC,EAAE,CAAA,aAAa,CAAC;aAClB;YACD,MAAM,EAAE,UAAU;YAClB,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,6BAA6B;YACrC,YAAY,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;YAC/B,MAAM,EAAE,OAAO;YACf,aAAa,EAAE,IAAI;SACpB;QACD,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE;YACX,qBAAqB,EAAE;gBACrB,CAAC,EAAE,CAAA,aAAa,CAAC;gBACjB,CAAC,EAAE,CAAA,aAAa,CAAC;gBACjB,CAAC,EAAE,CAAA,aAAa,CAAC;aAClB;YACD,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,6BAA6B;YACrC,YAAY,EAAE,CAAC,EAAE,CAAA,aAAa,CAAC;SAChC;QACD,QAAQ,EAAE;YACR,SAAS,EAAE,kCAAkC;YAC7C,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,6BAA6B;YACrC,eAAe,EAAE,OAAO;YACxB,MAAM,EAAE,qPAAqP;SAC9P;KACF,CAAC;AACF,CAAC,CAAC,EAAE,CAAC;AAEJ,IAAY,CAAC,IAAI,GAAG,kCAAkC,CAAC;AAExD,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type PuzzleFile = {
|
|
2
|
+
filename: string;
|
|
3
|
+
content: string;
|
|
4
|
+
};
|
|
5
|
+
/** The slugs of the games a token can manage, or null when the server rejects the token. */
|
|
6
|
+
export declare const fetchGameSlugsForToken: (apiURL: string, token: string) => Promise<string[] | null>;
|
|
7
|
+
/** Checks puzzle files against the game's pool rules without uploading them. */
|
|
8
|
+
export declare const validatePoolPuzzles: (apiURL: string, token: string, gameSlug: string, puzzles: PuzzleFile[]) => Promise<readonly {
|
|
9
|
+
readonly errors: ReadonlyArray<string>;
|
|
10
|
+
readonly filename: string;
|
|
11
|
+
readonly valid: boolean;
|
|
12
|
+
}[]>;
|
|
13
|
+
/** Adds puzzle files to the end of the game's pool; invalid files come back in `failed`. */
|
|
14
|
+
export declare const addPuzzlesToPool: (apiURL: string, token: string, gameSlug: string, puzzles: PuzzleFile[]) => Promise<{
|
|
15
|
+
readonly failed: ReadonlyArray<{
|
|
16
|
+
readonly filename: string;
|
|
17
|
+
readonly message: string;
|
|
18
|
+
}>;
|
|
19
|
+
readonly poolCount: number;
|
|
20
|
+
readonly uploadedFilenames: ReadonlyArray<string>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { graphql, query } from "../util/belay.js";
|
|
2
|
+
const gamesForAccessTokenQuery = graphql `
|
|
3
|
+
query cliGamesForAccessTokenQuery($token: String!) {
|
|
4
|
+
gamesForAccessToken(token: $token) {
|
|
5
|
+
slug
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
const validatePoolPuzzlesQuery = graphql `
|
|
10
|
+
query cliValidatePoolPuzzlesQuery($token: String!, $gameSlug: String!, $puzzles: [McpPuzzleFileInput!]!) {
|
|
11
|
+
validatePoolPuzzles(token: $token, gameSlug: $gameSlug, puzzles: $puzzles) {
|
|
12
|
+
filename
|
|
13
|
+
valid
|
|
14
|
+
errors
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
const addPuzzlesToPoolMutation = graphql `
|
|
19
|
+
mutation cliAddPuzzlesToPoolMutation($token: String!, $gameSlug: String!, $puzzles: [McpPuzzleFileInput!]!) {
|
|
20
|
+
addPuzzlesToPool(token: $token, gameSlug: $gameSlug, puzzles: $puzzles) {
|
|
21
|
+
uploadedFilenames
|
|
22
|
+
failed {
|
|
23
|
+
filename
|
|
24
|
+
message
|
|
25
|
+
}
|
|
26
|
+
poolCount
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
/** The slugs of the games a token can manage, or null when the server rejects the token. */
|
|
31
|
+
export const fetchGameSlugsForToken = async (apiURL, token) => {
|
|
32
|
+
const { data } = await query(gamesForAccessTokenQuery, { variables: { token }, url: `${apiURL}/graphql` });
|
|
33
|
+
return data?.gamesForAccessToken?.map((g) => g.slug) ?? null;
|
|
34
|
+
};
|
|
35
|
+
/** Checks puzzle files against the game's pool rules without uploading them. */
|
|
36
|
+
export const validatePoolPuzzles = async (apiURL, token, gameSlug, puzzles) => {
|
|
37
|
+
const { data, errors } = await query(validatePoolPuzzlesQuery, {
|
|
38
|
+
variables: { token, gameSlug, puzzles },
|
|
39
|
+
url: `${apiURL}/graphql`,
|
|
40
|
+
});
|
|
41
|
+
if (errors?.length)
|
|
42
|
+
throw new Error(errors.map((e) => e.message).join("; "));
|
|
43
|
+
if (!data?.validatePoolPuzzles)
|
|
44
|
+
throw new Error(`No game named "${gameSlug}" is accessible with that token.`);
|
|
45
|
+
return data.validatePoolPuzzles;
|
|
46
|
+
};
|
|
47
|
+
/** Adds puzzle files to the end of the game's pool; invalid files come back in `failed`. */
|
|
48
|
+
export const addPuzzlesToPool = async (apiURL, token, gameSlug, puzzles) => {
|
|
49
|
+
const { data, errors } = await query(addPuzzlesToPoolMutation, {
|
|
50
|
+
variables: { token, gameSlug, puzzles },
|
|
51
|
+
url: `${apiURL}/graphql`,
|
|
52
|
+
});
|
|
53
|
+
if (errors?.length)
|
|
54
|
+
throw new Error(errors.map((e) => e.message).join("; "));
|
|
55
|
+
if (!data?.addPuzzlesToPool)
|
|
56
|
+
throw new Error(`No game named "${gameSlug}" is accessible with that token.`);
|
|
57
|
+
return data.addPuzzlesToPool;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=puzzlePool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puzzlePool.js","sourceRoot":"","sources":["../../src/queries/puzzlePool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAKjD,MAAM,wBAAwB,GAAG,OAAO,CAAA;;;;;;CAMvC,CAAA;AAED,MAAM,wBAAwB,GAAG,OAAO,CAAA;;;;;;;;CAQvC,CAAA;AAED,MAAM,wBAAwB,GAAG,OAAO,CAAA;;;;;;;;;;;CAWvC,CAAA;AAID,4FAA4F;AAC5F,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,MAAc,EAAE,KAAa,EAA4B,EAAE;IACtG,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAA8B,wBAAwB,EAAE,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,MAAM,UAAU,EAAE,CAAC,CAAA;IACvI,OAAO,IAAI,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAC9D,CAAC,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAE,KAAa,EAAE,QAAgB,EAAE,OAAqB,EAAE,EAAE;IAClH,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAA8B,wBAAwB,EAAE;QAC1F,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE;QACvC,GAAG,EAAE,GAAG,MAAM,UAAU;KACzB,CAAC,CAAA;IACF,IAAI,MAAM,EAAE,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAC5E,IAAI,CAAC,IAAI,EAAE,mBAAmB;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,kCAAkC,CAAC,CAAA;IAC7G,OAAO,IAAI,CAAC,mBAAmB,CAAA;AACjC,CAAC,CAAA;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAc,EAAE,KAAa,EAAE,QAAgB,EAAE,OAAqB,EAAE,EAAE;IAC/G,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAA8B,wBAAwB,EAAE;QAC1F,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE;QACvC,GAAG,EAAE,GAAG,MAAM,UAAU;KACzB,CAAC,CAAA;IACF,IAAI,MAAM,EAAE,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAC5E,IAAI,CAAC,IAAI,EAAE,gBAAgB;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,kCAAkC,CAAC,CAAA;IAC1G,OAAO,IAAI,CAAC,gBAAgB,CAAA;AAC9B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import os from "node:os"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import { describe, expect, it } from "vitest"
|
|
5
|
+
|
|
6
|
+
import { adoptPico8Cart } from "./create.js"
|
|
7
|
+
|
|
8
|
+
const cart = (lua: string) => `pico-8 cartridge // http://www.pico-8.com\nversion 41\n__lua__\n${lua}\n__gfx__\n0000\n`
|
|
9
|
+
|
|
10
|
+
const adopt = (contents: string) => {
|
|
11
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pico8-cart-"))
|
|
12
|
+
fs.writeFileSync(path.join(dir, "in.p8"), contents)
|
|
13
|
+
const result = adoptPico8Cart(path.join(dir, "in.p8"), path.join(dir, "out.p8"))
|
|
14
|
+
return { ...result, out: fs.readFileSync(path.join(dir, "out.p8"), "utf-8") }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("adoptPico8Cart", () => {
|
|
18
|
+
it("adds the bridge's #include at the top of the cart's code", () => {
|
|
19
|
+
const { addedInclude, out } = adopt(cart("function _init() end"))
|
|
20
|
+
expect(addedInclude).toBe(true)
|
|
21
|
+
expect(out).toContain("__lua__\n#include puzzmo.lua\nfunction _init() end")
|
|
22
|
+
expect(out).toContain("__gfx__\n0000")
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it("leaves a cart which already includes it alone", () => {
|
|
26
|
+
const original = cart("#include puzzmo.lua\nfunction _init() end")
|
|
27
|
+
expect(adopt(original)).toEqual({ addedInclude: false, out: original })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("refuses something which isn't a cart", () => {
|
|
31
|
+
expect(() => adopt("hello")).toThrow(/doesn't look like a PICO-8 cart/)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -18,7 +18,7 @@ import { decodeTokenPayload, getTokens, tokenHelp, type TokenEntry } from "../..
|
|
|
18
18
|
import { slugify } from "../../util/slugify.js"
|
|
19
19
|
import { detectRepoContext, type RepoContext, type RepoType } from "./detectRepo.js"
|
|
20
20
|
|
|
21
|
-
export type Strategy = "import" | "blank" | "prompt"
|
|
21
|
+
export type Strategy = "import" | "blank" | "prompt" | "pico8"
|
|
22
22
|
|
|
23
23
|
export type CreateOptions = {
|
|
24
24
|
name?: string
|
|
@@ -30,6 +30,8 @@ export type CreateOptions = {
|
|
|
30
30
|
pm?: string
|
|
31
31
|
strategy?: Strategy
|
|
32
32
|
prompt?: string
|
|
33
|
+
/** An existing .p8 to start a PICO-8 game from */
|
|
34
|
+
cart?: string
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** Writes .mcp.json pointing at the Workshop MCP server */
|
|
@@ -192,6 +194,20 @@ const copyTemplate = (sourceDir: string, targetDir: string, replacements: Record
|
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Swaps the PICO-8 template's example cart for one the player already has. The bridge needs `#include puzzmo.lua`
|
|
199
|
+
* before anything calls it, so that's added at the top of the cart's code when it's missing. The calls to
|
|
200
|
+
* `pz_init()` and `pz_update()` depend on how the cart is written, so those are left to the person.
|
|
201
|
+
*/
|
|
202
|
+
export const adoptPico8Cart = (source: string, target: string): { addedInclude: boolean } => {
|
|
203
|
+
let cart = fs.readFileSync(source, "utf-8")
|
|
204
|
+
if (!cart.includes("__lua__")) throw new Error(`${source} doesn't look like a PICO-8 cart (there's no __lua__ section)`)
|
|
205
|
+
const addedInclude = !/^\s*#include\s+puzzmo\.lua/im.test(cart)
|
|
206
|
+
if (addedInclude) cart = cart.replace(/__lua__\r?\n/, (lua) => `${lua}#include puzzmo.lua\n`)
|
|
207
|
+
fs.writeFileSync(target, cart)
|
|
208
|
+
return { addedInclude }
|
|
209
|
+
}
|
|
210
|
+
|
|
195
211
|
/** Picks an agent interactively, returning the agent id or "none" */
|
|
196
212
|
const pickAgent = async (preselected?: string): Promise<string> => {
|
|
197
213
|
const supported = new Set(agentNames())
|
|
@@ -277,6 +293,7 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
277
293
|
message: "How would you like to create your game?",
|
|
278
294
|
options: [
|
|
279
295
|
{ value: "blank" as const, label: "Blank game (Minesweeper template)" },
|
|
296
|
+
{ value: "pico8" as const, label: "PICO-8 game (a cart, plus the bridge to Puzzmo)" },
|
|
280
297
|
{ value: "import" as const, label: "Import from an existing URL (uses an LLM to migrate)" },
|
|
281
298
|
{ value: "prompt" as const, label: "From a prompt (Builds on template + LLM customizations)" },
|
|
282
299
|
],
|
|
@@ -310,6 +327,7 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
310
327
|
|
|
311
328
|
let importedTitle: string | undefined
|
|
312
329
|
let userPrompt: string | undefined
|
|
330
|
+
let cartPath: string | undefined
|
|
313
331
|
|
|
314
332
|
if (strategy === "import") {
|
|
315
333
|
let url = opts.url
|
|
@@ -322,6 +340,28 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
322
340
|
const { title } = await downloadPage(url, tmpDir)
|
|
323
341
|
s.stop("Download complete.")
|
|
324
342
|
importedTitle = title
|
|
343
|
+
} else if (strategy === "pico8") {
|
|
344
|
+
cartPath = opts.cart
|
|
345
|
+
if (cartPath === undefined && !opts.strategy) {
|
|
346
|
+
const answer = (await p.text({
|
|
347
|
+
message: "Path to a .p8 cart you already have (leave empty to start from an example)",
|
|
348
|
+
placeholder: "~/pico-8/carts/mygame.p8",
|
|
349
|
+
validate: (v) => (v && !fs.existsSync(expandHome(v)) ? "Can't find that file" : undefined),
|
|
350
|
+
})) as string
|
|
351
|
+
if (p.isCancel(answer)) process.exit(0)
|
|
352
|
+
cartPath = answer || undefined
|
|
353
|
+
}
|
|
354
|
+
if (cartPath) {
|
|
355
|
+
cartPath = path.resolve(expandHome(cartPath))
|
|
356
|
+
if (!fs.existsSync(cartPath)) {
|
|
357
|
+
p.log.error(`Can't find the cart at ${cartPath}`)
|
|
358
|
+
process.exit(1)
|
|
359
|
+
}
|
|
360
|
+
importedTitle = path
|
|
361
|
+
.basename(cartPath, ".p8")
|
|
362
|
+
.replace(/[-_]+/g, " ")
|
|
363
|
+
.replace(/\b\w/g, (c) => c.toUpperCase())
|
|
364
|
+
}
|
|
325
365
|
} else if (strategy === "prompt") {
|
|
326
366
|
userPrompt = opts.prompt
|
|
327
367
|
if (!userPrompt) {
|
|
@@ -359,7 +399,7 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
359
399
|
|
|
360
400
|
// Materialize the starter (after we know the slug/name). Imports get it too — porting a
|
|
361
401
|
// downloaded game into a project that already builds beats rebuilding the project by hand.
|
|
362
|
-
const templateDir = resolveTemplateDir("minesweeper")
|
|
402
|
+
const templateDir = resolveTemplateDir(strategy === "pico8" ? "pico8" : "minesweeper")
|
|
363
403
|
if (!fs.existsSync(templateDir)) {
|
|
364
404
|
p.log.error(`Bundled template not found at ${templateDir}`)
|
|
365
405
|
process.exit(1)
|
|
@@ -375,6 +415,22 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
375
415
|
if (strategy === "import") seedImportedGame(tmpDir, templateDir, materialize)
|
|
376
416
|
else materialize(templateDir, tmpDir)
|
|
377
417
|
|
|
418
|
+
if (cartPath) {
|
|
419
|
+
const { addedInclude } = adoptPico8Cart(cartPath, path.join(tmpDir, "cart", "game.p8"))
|
|
420
|
+
p.note(
|
|
421
|
+
[
|
|
422
|
+
...(addedInclude ? ["Added `#include puzzmo.lua` to the top of your cart's code. Then, in cart/game.p8:"] : ["In cart/game.p8:"]),
|
|
423
|
+
" - call pz_init() in _init, and pz_update() first thing in _update",
|
|
424
|
+
" - wait for pz.ready, then build the level from pz.puzzle",
|
|
425
|
+
" - take input while pz.started is true and pz.paused is false",
|
|
426
|
+
" - pz_save(str) after each move, pz_complete(points, str) when it's solved",
|
|
427
|
+
" - pz_finished() when your victory animation is done",
|
|
428
|
+
"The README walks through each of these.",
|
|
429
|
+
].join("\n"),
|
|
430
|
+
"Your cart is in, a few hooks left to add",
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
|
|
378
434
|
// Step 6: Place files
|
|
379
435
|
let gameDir: string
|
|
380
436
|
let repoType: RepoType = repo.repoType
|
|
@@ -475,13 +531,21 @@ export const gameCreate = async (opts: CreateOptions) => {
|
|
|
475
531
|
const relativePath = path.relative(process.cwd(), gameDir)
|
|
476
532
|
|
|
477
533
|
p.note(
|
|
478
|
-
[
|
|
534
|
+
[
|
|
535
|
+
`cd ${relativePath}`,
|
|
536
|
+
`${runCmd} vite # Start development server`,
|
|
537
|
+
`${runCmd} vite build # Build for production`,
|
|
538
|
+
...(strategy === "pico8" ? ["", "Then open cart/game.p8 in PICO-8: saving it reloads the game in the simulator."] : []),
|
|
539
|
+
].join("\n"),
|
|
479
540
|
"Next steps",
|
|
480
541
|
)
|
|
481
542
|
|
|
482
543
|
p.outro(`Done! Your game is in ./${relativePath}/`)
|
|
483
544
|
}
|
|
484
545
|
|
|
546
|
+
/** Expands a leading `~` in a path typed into a prompt, which the shell didn't get the chance to. */
|
|
547
|
+
const expandHome = (p: string) => (p.startsWith("~") ? path.join(process.env.HOME ?? "", p.slice(1)) : p)
|
|
548
|
+
|
|
485
549
|
/** `--pm` arrives as a plain string; anything unexpected falls back to the repo's own manager */
|
|
486
550
|
const packageManagerFrom = (value: string | undefined, fallback: PackageManagerName): PackageManagerName =>
|
|
487
551
|
value === "npm" || value === "yarn" || value === "pnpm" ? value : fallback
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
import { addPuzzlesToPool, fetchGameSlugsForToken, type PuzzleFile, validatePoolPuzzles } from "../queries/puzzlePool.js"
|
|
5
|
+
import { getTokens, isServerReachable, sortByServerPriority, sourceToURL, tokenHelp, type TokenEntry } from "../util/config.js"
|
|
6
|
+
|
|
7
|
+
type PuzzlesUploadOptions = {
|
|
8
|
+
game: string
|
|
9
|
+
/** Validate every file without uploading any */
|
|
10
|
+
dryRun?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Matches the API's per-call cap
|
|
14
|
+
const maxBatchCount = 100
|
|
15
|
+
// The API's /graphql route takes 1MiB bodies, leave room for the query and JSON escaping
|
|
16
|
+
const maxBatchBytes = 900_000
|
|
17
|
+
|
|
18
|
+
/** CLI command: puzzmo puzzles upload <path> --game <slug> — adds puzzle files to the end of a game's puzzle pool */
|
|
19
|
+
export const puzzlesUpload = async (target: string, options: PuzzlesUploadOptions) => {
|
|
20
|
+
const files = readPuzzleFiles(target)
|
|
21
|
+
if (!files.length) {
|
|
22
|
+
console.error(`No puzzle files found at ${target}`)
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const entry = await findTokenForGame(options.game)
|
|
27
|
+
if (!entry) {
|
|
28
|
+
console.error(`None of your saved tokens can manage a game with the slug "${options.game}".\n${tokenHelp}`)
|
|
29
|
+
process.exit(1)
|
|
30
|
+
}
|
|
31
|
+
const apiURL = sourceToURL(entry.source)
|
|
32
|
+
|
|
33
|
+
const oversized = files.filter((f) => payloadBytes(f) > maxBatchBytes)
|
|
34
|
+
if (oversized.length) {
|
|
35
|
+
for (const { filename } of oversized)
|
|
36
|
+
console.error(`FAIL ${filename}\n File is too large to upload (max ~${maxBatchBytes / 1000}KB)`)
|
|
37
|
+
console.error(`\n${oversized.length} of ${files.length} puzzle files are too large, nothing was uploaded.`)
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
|
40
|
+
const batches = toBatches(files)
|
|
41
|
+
|
|
42
|
+
// Validate everything up front so a bad file doesn't leave half a batch in the pool
|
|
43
|
+
const invalid: { filename: string; errors: readonly string[] }[] = []
|
|
44
|
+
for (const batch of batches) {
|
|
45
|
+
const results = await validatePoolPuzzles(apiURL, entry.token, options.game, batch)
|
|
46
|
+
invalid.push(...results.filter((r) => !r.valid))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (invalid.length) {
|
|
50
|
+
for (const { filename, errors } of invalid) console.error(`FAIL ${filename}\n ${errors.join("\n ")}`)
|
|
51
|
+
console.error(`\n${invalid.length} of ${files.length} puzzle files are invalid, nothing was uploaded.`)
|
|
52
|
+
process.exit(1)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (options.dryRun) {
|
|
56
|
+
console.log(`All ${files.length} puzzle files are valid for ${options.game}. Nothing was uploaded (--dry-run).`)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let uploaded = 0
|
|
61
|
+
let poolCount = 0
|
|
62
|
+
const failed: { filename: string; message: string }[] = []
|
|
63
|
+
for (const batch of batches) {
|
|
64
|
+
const result = await addPuzzlesToPool(apiURL, entry.token, options.game, batch)
|
|
65
|
+
uploaded += result.uploadedFilenames.length
|
|
66
|
+
poolCount = result.poolCount
|
|
67
|
+
failed.push(...result.failed)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const { filename, message } of failed) console.error(`FAIL ${filename}: ${message}`)
|
|
71
|
+
console.log(`Uploaded ${uploaded} puzzle${uploaded === 1 ? "" : "s"} to ${options.game}'s pool (${poolCount} waiting in the pool).`)
|
|
72
|
+
if (failed.length) process.exit(1)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Reads a single file, or every non-hidden file directly inside a directory, sorted by name */
|
|
76
|
+
const readPuzzleFiles = (target: string): PuzzleFile[] => {
|
|
77
|
+
const resolved = path.resolve(target)
|
|
78
|
+
if (!fs.existsSync(resolved)) return []
|
|
79
|
+
|
|
80
|
+
const paths = fs.statSync(resolved).isDirectory()
|
|
81
|
+
? fs
|
|
82
|
+
.readdirSync(resolved, { withFileTypes: true })
|
|
83
|
+
.filter((d) => d.isFile() && !d.name.startsWith("."))
|
|
84
|
+
.map((d) => path.join(resolved, d.name))
|
|
85
|
+
: [resolved]
|
|
86
|
+
|
|
87
|
+
return paths
|
|
88
|
+
.sort((a, b) => path.basename(a).localeCompare(path.basename(b)))
|
|
89
|
+
.map((p) => ({ filename: path.basename(p), content: fs.readFileSync(p, "utf-8") }))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Finds the first saved token, in server priority order, whose team owns the game */
|
|
93
|
+
const findTokenForGame = async (gameSlug: string): Promise<TokenEntry | null> => {
|
|
94
|
+
for (const entry of sortByServerPriority(getTokens())) {
|
|
95
|
+
if (!(await isServerReachable(entry.source))) continue
|
|
96
|
+
const slugs = await fetchGameSlugsForToken(sourceToURL(entry.source), entry.token).catch(() => null)
|
|
97
|
+
if (slugs?.includes(gameSlug)) return entry
|
|
98
|
+
}
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Splits files into batches which stay under both the API's per-call count and its request size limit */
|
|
103
|
+
const toBatches = (files: PuzzleFile[]): PuzzleFile[][] => {
|
|
104
|
+
const batches: PuzzleFile[][] = []
|
|
105
|
+
let current: PuzzleFile[] = []
|
|
106
|
+
let currentBytes = 0
|
|
107
|
+
for (const file of files) {
|
|
108
|
+
const bytes = payloadBytes(file)
|
|
109
|
+
if (current.length && (current.length >= maxBatchCount || currentBytes + bytes > maxBatchBytes)) {
|
|
110
|
+
batches.push(current)
|
|
111
|
+
current = []
|
|
112
|
+
currentBytes = 0
|
|
113
|
+
}
|
|
114
|
+
current.push(file)
|
|
115
|
+
currentBytes += bytes
|
|
116
|
+
}
|
|
117
|
+
if (current.length) batches.push(current)
|
|
118
|
+
return batches
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const payloadBytes = (file: PuzzleFile) => Buffer.byteLength(JSON.stringify(file), "utf-8")
|