@puzzmo/cli 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +0 -0
- package/package.json +12 -6
- package/lib/lib/api.d.ts +0 -10
- package/lib/lib/api.js +0 -53
- package/lib/lib/api.js.map +0 -1
- package/lib/lib/config.d.ts +0 -13
- package/lib/lib/config.js +0 -29
- package/lib/lib/config.js.map +0 -1
- package/lib/lib/exec.d.ts +0 -15
- package/lib/lib/exec.js +0 -34
- package/lib/lib/exec.js.map +0 -1
- package/lib/lib/package-manager.d.ts +0 -2
- package/lib/lib/package-manager.js +0 -15
- package/lib/lib/package-manager.js.map +0 -1
- package/src/lib/api.ts +0 -75
- package/src/lib/config.ts +0 -37
- package/src/lib/exec.ts +0 -38
package/lib/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puzzmo/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"puzzmo": "./lib/index.js"
|
|
7
7
|
},
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/puzzmo-com/oss.git",
|
|
12
|
+
"directory": "packages/cli"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true,
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
9
19
|
"scripts": {
|
|
10
20
|
"build": "tsc",
|
|
11
21
|
"type-check": "tsc --noEmit"
|
|
12
22
|
},
|
|
13
23
|
"dependencies": {
|
|
14
|
-
"@puzzmo/agent-cli-detect": "
|
|
15
|
-
},
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@types/node": "^20.1.0",
|
|
18
|
-
"typescript": "catalog:"
|
|
24
|
+
"@puzzmo/agent-cli-detect": "*"
|
|
19
25
|
}
|
|
20
26
|
}
|
package/lib/lib/api.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type CompleteResponse = {
|
|
2
|
-
cdnBase: string;
|
|
3
|
-
versionID: string;
|
|
4
|
-
error?: string;
|
|
5
|
-
};
|
|
6
|
-
/** Callback for reporting batch upload progress */
|
|
7
|
-
export type UploadProgress = (batch: number, totalBatches: number, uploaded: number) => void;
|
|
8
|
-
/** Multi-step upload: init -> batched file uploads -> complete */
|
|
9
|
-
export declare const uploadFiles: (token: string, gameSlug: string, sha: string, filePaths: string[], baseDir: string, onProgress?: UploadProgress) => Promise<CompleteResponse>;
|
|
10
|
-
export {};
|
package/lib/lib/api.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { getAPIURL } from "./config.js";
|
|
4
|
-
const BATCH_SIZE = 10;
|
|
5
|
-
/** Sends a JSON POST request */
|
|
6
|
-
const jsonPost = async (url, token, body) => {
|
|
7
|
-
const res = await fetch(url, {
|
|
8
|
-
method: "POST",
|
|
9
|
-
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
10
|
-
body: JSON.stringify(body),
|
|
11
|
-
});
|
|
12
|
-
const json = await res.json();
|
|
13
|
-
if (!res.ok)
|
|
14
|
-
throw new Error(`Server error (${res.status}): ${json.error || "Unknown error"}`);
|
|
15
|
-
return json;
|
|
16
|
-
};
|
|
17
|
-
/** Uploads a single file as raw binary with filename in query param */
|
|
18
|
-
const uploadFile = async (url, token, filePath, baseDir) => {
|
|
19
|
-
const relativePath = path.relative(baseDir, filePath);
|
|
20
|
-
const content = fs.readFileSync(filePath);
|
|
21
|
-
const res = await fetch(`${url}?name=${encodeURIComponent(relativePath)}`, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: {
|
|
24
|
-
Authorization: `Bearer ${token}`,
|
|
25
|
-
"Content-Type": "application/octet-stream",
|
|
26
|
-
},
|
|
27
|
-
body: content,
|
|
28
|
-
});
|
|
29
|
-
const json = await res.json();
|
|
30
|
-
if (!res.ok)
|
|
31
|
-
throw new Error(`Server error (${res.status}): ${json.error || "Unknown error"}`);
|
|
32
|
-
return json;
|
|
33
|
-
};
|
|
34
|
-
/** Multi-step upload: init -> batched file uploads -> complete */
|
|
35
|
-
export const uploadFiles = async (token, gameSlug, sha, filePaths, baseDir, onProgress) => {
|
|
36
|
-
const apiURL = getAPIURL();
|
|
37
|
-
// Step 1: Init session
|
|
38
|
-
const init = (await jsonPost(`${apiURL}/cliUpload`, token, { gameSlug, sha }));
|
|
39
|
-
// Step 2: Upload files in concurrent batches
|
|
40
|
-
const fileURL = `${apiURL}/cliUpload/${init.sessionID}/file`;
|
|
41
|
-
const totalBatches = Math.ceil(filePaths.length / BATCH_SIZE);
|
|
42
|
-
let totalUploaded = 0;
|
|
43
|
-
for (let i = 0; i < filePaths.length; i += BATCH_SIZE) {
|
|
44
|
-
const batch = filePaths.slice(i, i + BATCH_SIZE);
|
|
45
|
-
const batchNum = Math.floor(i / BATCH_SIZE) + 1;
|
|
46
|
-
await Promise.all(batch.map((fp) => uploadFile(fileURL, token, fp, baseDir)));
|
|
47
|
-
totalUploaded += batch.length;
|
|
48
|
-
onProgress?.(batchNum, totalBatches, totalUploaded);
|
|
49
|
-
}
|
|
50
|
-
// Step 3: Complete
|
|
51
|
-
return (await jsonPost(`${apiURL}/cliUpload/${init.sessionID}/complete`, token, {}));
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=api.js.map
|
package/lib/lib/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,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AAA;QAC7B,UAAU,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAA;IACrD,CAAC;IAED,mBAAmB;IACnB,OAAO,CAAC,MAAM,QAAQ,CAAC,GAAG,MAAM,cAAc,IAAI,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,EAAE,CAAC,CAAqB,CAAA;AAC1G,CAAC,CAAA"}
|
package/lib/lib/config.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type Config = {
|
|
2
|
-
token?: string;
|
|
3
|
-
apiURL?: string;
|
|
4
|
-
};
|
|
5
|
-
/** Reads the CLI config from ~/.puzzmo/config.json */
|
|
6
|
-
export declare const readConfig: () => Config;
|
|
7
|
-
/** Writes the CLI config to ~/.puzzmo/config.json */
|
|
8
|
-
export declare const writeConfig: (config: Config) => void;
|
|
9
|
-
/** Returns the auth token from config or PUZZMO_TOKEN env var */
|
|
10
|
-
export declare const getToken: () => string | undefined;
|
|
11
|
-
/** Returns the API base URL */
|
|
12
|
-
export declare const getAPIURL: () => string;
|
|
13
|
-
export {};
|
package/lib/lib/config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
const configDir = path.join(os.homedir(), ".puzzmo");
|
|
5
|
-
const configPath = path.join(configDir, "config.json");
|
|
6
|
-
/** Reads the CLI config from ~/.puzzmo/config.json */
|
|
7
|
-
export const readConfig = () => {
|
|
8
|
-
try {
|
|
9
|
-
const raw = fs.readFileSync(configPath, "utf-8");
|
|
10
|
-
return JSON.parse(raw);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
/** Writes the CLI config to ~/.puzzmo/config.json */
|
|
17
|
-
export const writeConfig = (config) => {
|
|
18
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
19
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
20
|
-
};
|
|
21
|
-
/** Returns the auth token from config or PUZZMO_TOKEN env var */
|
|
22
|
-
export const getToken = () => {
|
|
23
|
-
return process.env.PUZZMO_TOKEN || readConfig().token;
|
|
24
|
-
};
|
|
25
|
-
/** Returns the API base URL */
|
|
26
|
-
export const getAPIURL = () => {
|
|
27
|
-
return process.env.PUZZMO_API_URL || readConfig().apiURL || "https://api.puzzmo.com";
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=config.js.map
|
package/lib/lib/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;AACpD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AAOtD,sDAAsD;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAChD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE;IAC5C,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5C,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;AACtE,CAAC,CAAA;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAuB,EAAE;IAC/C,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,UAAU,EAAE,CAAC,KAAK,CAAA;AACvD,CAAC,CAAA;AAED,+BAA+B;AAC/B,MAAM,CAAC,MAAM,SAAS,GAAG,GAAW,EAAE;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,UAAU,EAAE,CAAC,MAAM,IAAI,wBAAwB,CAAA;AACtF,CAAC,CAAA"}
|
package/lib/lib/exec.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type ExecOptions = {
|
|
2
|
-
cwd?: string;
|
|
3
|
-
};
|
|
4
|
-
/** Runs a shell command, printing output */
|
|
5
|
-
export declare const runCommand: (cmd: string, opts?: ExecOptions) => void;
|
|
6
|
-
/** Runs a command and returns stdout */
|
|
7
|
-
export declare const runCommandOutput: (cmd: string, opts?: ExecOptions) => string;
|
|
8
|
-
/** Creates a git commit */
|
|
9
|
-
export declare const gitCommit: (message: string, opts?: ExecOptions) => void;
|
|
10
|
-
/** Runs vite build and returns success/failure */
|
|
11
|
-
export declare const verifyBuild: (cwd: string) => {
|
|
12
|
-
success: boolean;
|
|
13
|
-
error?: string;
|
|
14
|
-
};
|
|
15
|
-
export {};
|
package/lib/lib/exec.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
|
-
/** Runs a shell command, printing output */
|
|
3
|
-
export const runCommand = (cmd, opts = {}) => {
|
|
4
|
-
execSync(cmd, {
|
|
5
|
-
cwd: opts.cwd,
|
|
6
|
-
stdio: "inherit",
|
|
7
|
-
encoding: "utf-8",
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/** Runs a command and returns stdout */
|
|
11
|
-
export const runCommandOutput = (cmd, opts = {}) => {
|
|
12
|
-
return execSync(cmd, {
|
|
13
|
-
cwd: opts.cwd,
|
|
14
|
-
encoding: "utf-8",
|
|
15
|
-
}).trim();
|
|
16
|
-
};
|
|
17
|
-
/** Creates a git commit */
|
|
18
|
-
export const gitCommit = (message, opts = {}) => {
|
|
19
|
-
execSync(`git commit -m "${message}"`, {
|
|
20
|
-
cwd: opts.cwd,
|
|
21
|
-
stdio: "inherit",
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
/** Runs vite build and returns success/failure */
|
|
25
|
-
export const verifyBuild = (cwd) => {
|
|
26
|
-
try {
|
|
27
|
-
execSync("npx vite build", { cwd, encoding: "utf-8", stdio: "pipe" });
|
|
28
|
-
return { success: true };
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
return { success: false, error: e.stderr || e.stdout || e.message };
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=exec.js.map
|
package/lib/lib/exec.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/lib/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAI7C,4CAA4C;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,OAAoB,EAAE,EAAE,EAAE;IAChE,QAAQ,CAAC,GAAG,EAAE;QACZ,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,OAAoB,EAAE,EAAU,EAAE;IAC9E,OAAO,QAAQ,CAAC,GAAG,EAAE;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC,IAAI,EAAE,CAAA;AACX,CAAC,CAAA;AAED,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,OAAoB,EAAE,EAAE,EAAE;IACnE,QAAQ,CAAC,kBAAkB,OAAO,GAAG,EAAE;QACrC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,kDAAkD;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAwC,EAAE;IAC/E,IAAI,CAAC;QACH,QAAQ,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;QACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA;IACrE,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
/** Detects the user's package manager from env or lockfiles */
|
|
3
|
-
export const detectPackageManager = () => {
|
|
4
|
-
const ua = process.env.npm_config_user_agent ?? "";
|
|
5
|
-
if (ua.startsWith("yarn"))
|
|
6
|
-
return "yarn";
|
|
7
|
-
if (ua.startsWith("pnpm"))
|
|
8
|
-
return "pnpm";
|
|
9
|
-
if (fs.existsSync("yarn.lock"))
|
|
10
|
-
return "yarn";
|
|
11
|
-
if (fs.existsSync("pnpm-lock.yaml"))
|
|
12
|
-
return "pnpm";
|
|
13
|
-
return "npm";
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=package-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/lib/package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AAExB,+DAA+D;AAC/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAA4B,EAAE;IAChE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAA;IAClD,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACxC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAExC,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;QAAE,OAAO,MAAM,CAAA;IAC7C,IAAI,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAO,MAAM,CAAA;IAClD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/src/lib/api.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
|
|
4
|
-
import { getAPIURL } from "./config.js"
|
|
5
|
-
|
|
6
|
-
const BATCH_SIZE = 10
|
|
7
|
-
|
|
8
|
-
type InitResponse = { sessionID: string; basePath: string; error?: string }
|
|
9
|
-
type FileResponse = { path: string; error?: string }
|
|
10
|
-
type CompleteResponse = { cdnBase: string; versionID: string; error?: string }
|
|
11
|
-
|
|
12
|
-
/** Callback for reporting batch upload progress */
|
|
13
|
-
export type UploadProgress = (batch: number, totalBatches: number, uploaded: number) => void
|
|
14
|
-
|
|
15
|
-
/** Sends a JSON POST request */
|
|
16
|
-
const jsonPost = async (url: string, token: string, body: object) => {
|
|
17
|
-
const res = await fetch(url, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify(body),
|
|
21
|
-
})
|
|
22
|
-
const json = await res.json()
|
|
23
|
-
if (!res.ok) throw new Error(`Server error (${res.status}): ${(json as any).error || "Unknown error"}`)
|
|
24
|
-
return json
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Uploads a single file as raw binary with filename in query param */
|
|
28
|
-
const uploadFile = async (url: string, token: string, filePath: string, baseDir: string): Promise<FileResponse> => {
|
|
29
|
-
const relativePath = path.relative(baseDir, filePath)
|
|
30
|
-
const content = fs.readFileSync(filePath)
|
|
31
|
-
|
|
32
|
-
const res = await fetch(`${url}?name=${encodeURIComponent(relativePath)}`, {
|
|
33
|
-
method: "POST",
|
|
34
|
-
headers: {
|
|
35
|
-
Authorization: `Bearer ${token}`,
|
|
36
|
-
"Content-Type": "application/octet-stream",
|
|
37
|
-
},
|
|
38
|
-
body: content,
|
|
39
|
-
})
|
|
40
|
-
const json = await res.json()
|
|
41
|
-
if (!res.ok) throw new Error(`Server error (${res.status}): ${(json as any).error || "Unknown error"}`)
|
|
42
|
-
return json as FileResponse
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Multi-step upload: init -> batched file uploads -> complete */
|
|
46
|
-
export const uploadFiles = async (
|
|
47
|
-
token: string,
|
|
48
|
-
gameSlug: string,
|
|
49
|
-
sha: string,
|
|
50
|
-
filePaths: string[],
|
|
51
|
-
baseDir: string,
|
|
52
|
-
onProgress?: UploadProgress,
|
|
53
|
-
): Promise<CompleteResponse> => {
|
|
54
|
-
const apiURL = getAPIURL()
|
|
55
|
-
|
|
56
|
-
// Step 1: Init session
|
|
57
|
-
const init = (await jsonPost(`${apiURL}/cliUpload`, token, { gameSlug, sha })) as InitResponse
|
|
58
|
-
|
|
59
|
-
// Step 2: Upload files in concurrent batches
|
|
60
|
-
const fileURL = `${apiURL}/cliUpload/${init.sessionID}/file`
|
|
61
|
-
const totalBatches = Math.ceil(filePaths.length / BATCH_SIZE)
|
|
62
|
-
let totalUploaded = 0
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < filePaths.length; i += BATCH_SIZE) {
|
|
65
|
-
const batch = filePaths.slice(i, i + BATCH_SIZE)
|
|
66
|
-
const batchNum = Math.floor(i / BATCH_SIZE) + 1
|
|
67
|
-
await Promise.all(batch.map((fp) => uploadFile(fileURL, token, fp, baseDir)))
|
|
68
|
-
totalUploaded += batch.length
|
|
69
|
-
onProgress?.(batchNum, totalBatches, totalUploaded)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Step 3: Complete
|
|
73
|
-
return (await jsonPost(`${apiURL}/cliUpload/${init.sessionID}/complete`, token, {})) as CompleteResponse
|
|
74
|
-
}
|
|
75
|
-
|
package/src/lib/config.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs"
|
|
2
|
-
import os from "node:os"
|
|
3
|
-
import path from "node:path"
|
|
4
|
-
|
|
5
|
-
const configDir = path.join(os.homedir(), ".puzzmo")
|
|
6
|
-
const configPath = path.join(configDir, "config.json")
|
|
7
|
-
|
|
8
|
-
type Config = {
|
|
9
|
-
token?: string
|
|
10
|
-
apiURL?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Reads the CLI config from ~/.puzzmo/config.json */
|
|
14
|
-
export const readConfig = (): Config => {
|
|
15
|
-
try {
|
|
16
|
-
const raw = fs.readFileSync(configPath, "utf-8")
|
|
17
|
-
return JSON.parse(raw)
|
|
18
|
-
} catch {
|
|
19
|
-
return {}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Writes the CLI config to ~/.puzzmo/config.json */
|
|
24
|
-
export const writeConfig = (config: Config) => {
|
|
25
|
-
fs.mkdirSync(configDir, { recursive: true })
|
|
26
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Returns the auth token from config or PUZZMO_TOKEN env var */
|
|
30
|
-
export const getToken = (): string | undefined => {
|
|
31
|
-
return process.env.PUZZMO_TOKEN || readConfig().token
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Returns the API base URL */
|
|
35
|
-
export const getAPIURL = (): string => {
|
|
36
|
-
return process.env.PUZZMO_API_URL || readConfig().apiURL || "https://api.puzzmo.com"
|
|
37
|
-
}
|
package/src/lib/exec.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process"
|
|
2
|
-
|
|
3
|
-
type ExecOptions = { cwd?: string }
|
|
4
|
-
|
|
5
|
-
/** Runs a shell command, printing output */
|
|
6
|
-
export const runCommand = (cmd: string, opts: ExecOptions = {}) => {
|
|
7
|
-
execSync(cmd, {
|
|
8
|
-
cwd: opts.cwd,
|
|
9
|
-
stdio: "inherit",
|
|
10
|
-
encoding: "utf-8",
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Runs a command and returns stdout */
|
|
15
|
-
export const runCommandOutput = (cmd: string, opts: ExecOptions = {}): string => {
|
|
16
|
-
return execSync(cmd, {
|
|
17
|
-
cwd: opts.cwd,
|
|
18
|
-
encoding: "utf-8",
|
|
19
|
-
}).trim()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Creates a git commit */
|
|
23
|
-
export const gitCommit = (message: string, opts: ExecOptions = {}) => {
|
|
24
|
-
execSync(`git commit -m "${message}"`, {
|
|
25
|
-
cwd: opts.cwd,
|
|
26
|
-
stdio: "inherit",
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Runs vite build and returns success/failure */
|
|
31
|
-
export const verifyBuild = (cwd: string): { success: boolean; error?: string } => {
|
|
32
|
-
try {
|
|
33
|
-
execSync("npx vite build", { cwd, encoding: "utf-8", stdio: "pipe" })
|
|
34
|
-
return { success: true }
|
|
35
|
-
} catch (e: any) {
|
|
36
|
-
return { success: false, error: e.stderr || e.stdout || e.message }
|
|
37
|
-
}
|
|
38
|
-
}
|