@shop-on/theme-cli 0.13.2 → 0.14.0-next.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/dist/theme/source.mjs +57 -9
- package/package.json +5 -4
package/dist/theme/source.mjs
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
import { processIo } from "../audit/command.mjs";
|
|
3
3
|
import { noHardLinks } from "./tar.mjs";
|
|
4
4
|
import { isDirectory, isFile, themeHandle } from "./pack.mjs";
|
|
5
|
-
import { readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
5
|
+
import { lstatSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
import { create } from "tar";
|
|
9
|
+
import ignore from "ignore";
|
|
9
10
|
// src/theme/source.ts
|
|
10
11
|
const USAGE = `usage: shop-on theme source [--theme <dir>] [--out <path>]
|
|
11
12
|
|
|
12
13
|
--theme <dir> the theme to pack (default: the current directory)
|
|
13
14
|
--out <path> where to write the tarball, a file or a directory
|
|
14
|
-
(default: <handle>-<version>-source.tar.gz in the theme directory)
|
|
15
|
+
(default: <handle>-<version>-source.tar.gz in the theme directory)
|
|
16
|
+
|
|
17
|
+
A .themeignore in the theme directory (gitignore syntax) leaves out more.`;
|
|
18
|
+
/** The author's own list, beside package.json, on top of `skipReason`'s. */
|
|
19
|
+
const IGNORE_FILE = ".themeignore";
|
|
15
20
|
/** The files the api refuses a submission without, at the archive root
|
|
16
21
|
* (`Theme::Submissions::Create::REQUIRED_FILES`). */
|
|
17
22
|
const REQUIRED_FILES = ["package.json", "pnpm-lock.yaml"];
|
|
@@ -38,23 +43,34 @@ const BUILD_OUTPUT = /* @__PURE__ */ new Set([
|
|
|
38
43
|
".turbo"
|
|
39
44
|
]);
|
|
40
45
|
const SKIPPED_AT_ROOT = /* @__PURE__ */ new Set([".shop-on", "tsconfig.tsbuildinfo"]);
|
|
46
|
+
const AGENT_FILES = ".claude";
|
|
41
47
|
/**
|
|
42
48
|
* Why the entry at `relPath` (archive-relative, `/`-separated) stays out of
|
|
43
|
-
* the source tarball: `"build-output"`
|
|
44
|
-
* keeps it.
|
|
49
|
+
* the source tarball: `"build-output"` and `"agent-files"` are said aloud,
|
|
50
|
+
* `"skipped"` isn't; null keeps it. `.themeignore` can't bring one back.
|
|
45
51
|
*/
|
|
46
52
|
function skipReason(relPath) {
|
|
47
53
|
const segments = relPath.split("/");
|
|
48
54
|
const base = segments[segments.length - 1] ?? "";
|
|
49
55
|
const atRoot = segments.length === 1;
|
|
50
56
|
if (SKIPPED_ANYWHERE.has(base) || base.startsWith("._")) return "skipped";
|
|
51
|
-
|
|
52
|
-
if (
|
|
57
|
+
const name = base.toLowerCase();
|
|
58
|
+
if ((name === ".env" || name.startsWith(".env.")) && name !== ".env.example") return "skipped";
|
|
59
|
+
if (name === ".npmrc" || name === ".dev.vars") return "skipped";
|
|
53
60
|
if (!atRoot) return null;
|
|
54
61
|
if (BUILD_OUTPUT.has(base)) return "build-output";
|
|
62
|
+
if (name === AGENT_FILES) return "agent-files";
|
|
55
63
|
if (SKIPPED_AT_ROOT.has(base)) return "skipped";
|
|
56
64
|
return /\.(tar\.gz|tgz)(\.partial)?$/.test(base) ? "skipped" : null;
|
|
57
65
|
}
|
|
66
|
+
/** The theme's `.themeignore`; empty without one. Throws on one it can't read. */
|
|
67
|
+
function readIgnoreFile(themeDir) {
|
|
68
|
+
const file = path.join(themeDir, IGNORE_FILE);
|
|
69
|
+
const ignored = ignore({ ignorecase: false });
|
|
70
|
+
if (!lstatSync(file, { throwIfNoEntry: false })) return ignored;
|
|
71
|
+
const patterns = new TextDecoder("utf-8", { fatal: true }).decode(readFileSync(file));
|
|
72
|
+
return ignored.add(patterns.normalize("NFC"));
|
|
73
|
+
}
|
|
58
74
|
/** Why the api would refuse `relPath` as an entry path, or null. */
|
|
59
75
|
function pathRefusal(relPath) {
|
|
60
76
|
const depth = relPath.split("/").filter(Boolean).length;
|
|
@@ -104,6 +120,14 @@ async function runSource({ argv, cwd = process.cwd(), io = processIo }) {
|
|
|
104
120
|
};
|
|
105
121
|
const missing = REQUIRED_FILES.filter((rel) => !isFile(path.join(themeDir, rel)));
|
|
106
122
|
if (missing.length > 0) return fail(`${themeDir} has no ${missing.join(" or ")}; a submission needs both at the project root (run \`pnpm install\` for the lockfile)`);
|
|
123
|
+
let ignored;
|
|
124
|
+
try {
|
|
125
|
+
ignored = readIgnoreFile(themeDir);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
return fail(`could not read ${IGNORE_FILE} (UTF-8 text): ${err.message}`);
|
|
128
|
+
}
|
|
129
|
+
const dropped = REQUIRED_FILES.filter((rel) => ignored.ignores(rel));
|
|
130
|
+
if (dropped.length > 0) return fail(`${IGNORE_FILE} leaves out ${dropped.join(" and ")}; a submission needs both`);
|
|
107
131
|
let pkg;
|
|
108
132
|
try {
|
|
109
133
|
pkg = JSON.parse(readFileSync(path.join(themeDir, "package.json"), "utf8"));
|
|
@@ -120,6 +144,9 @@ async function runSource({ argv, cwd = process.cwd(), io = processIo }) {
|
|
|
120
144
|
const tmpPath = `${outPath}.partial`;
|
|
121
145
|
const skippedLinks = [];
|
|
122
146
|
const skippedOutput = [];
|
|
147
|
+
let skippedAgentFiles = false;
|
|
148
|
+
let ignoredEntries = 0;
|
|
149
|
+
const packed = /* @__PURE__ */ new Map();
|
|
123
150
|
let refusal = null;
|
|
124
151
|
let entries = 0;
|
|
125
152
|
let bytes = 0;
|
|
@@ -134,6 +161,7 @@ async function runSource({ argv, cwd = process.cwd(), io = processIo }) {
|
|
|
134
161
|
const rel = entryPath.replace(/^\.\//, "");
|
|
135
162
|
const reason = skipReason(rel);
|
|
136
163
|
if (reason === "build-output") skippedOutput.push(rel);
|
|
164
|
+
if (reason === "agent-files") skippedAgentFiles = true;
|
|
137
165
|
if (reason) return false;
|
|
138
166
|
const abs = path.join(themeDir, rel);
|
|
139
167
|
if (abs === tmpPath || abs === outPath) return false;
|
|
@@ -142,11 +170,20 @@ async function runSource({ argv, cwd = process.cwd(), io = processIo }) {
|
|
|
142
170
|
skippedLinks.push(rel);
|
|
143
171
|
return false;
|
|
144
172
|
}
|
|
145
|
-
const
|
|
173
|
+
const archived = stat.isDirectory() ? `${rel}/` : rel;
|
|
174
|
+
if (ignored.ignores(archived.normalize("NFC"))) {
|
|
175
|
+
ignoredEntries += 1;
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const unsafe = pathRefusal(archived);
|
|
146
179
|
if (unsafe) refusal ??= `${rel} ${unsafe}`;
|
|
147
180
|
if (stat.isFile() && stat.size > LIMITS.singleFileBytes) refusal ??= `${rel} is ${mb(stat.size)} MB (the limit for one file is ${mb(LIMITS.singleFileBytes)} MB)`;
|
|
148
181
|
entries += 1;
|
|
149
|
-
if (stat.isFile())
|
|
182
|
+
if (stat.isFile()) {
|
|
183
|
+
bytes += stat.size;
|
|
184
|
+
const top = rel.includes("/") ? rel.slice(0, rel.indexOf("/")) : "";
|
|
185
|
+
packed.set(top, (packed.get(top) ?? 0) + 1);
|
|
186
|
+
}
|
|
150
187
|
return true;
|
|
151
188
|
}
|
|
152
189
|
}, readdirSync(themeDir).sort());
|
|
@@ -162,12 +199,23 @@ async function runSource({ argv, cwd = process.cwd(), io = processIo }) {
|
|
|
162
199
|
}
|
|
163
200
|
renameSync(tmpPath, outPath);
|
|
164
201
|
for (const dir of skippedOutput) io.err(`skipped ${dir}/: build output, Lite builds the theme`);
|
|
202
|
+
if (skippedAgentFiles) io.err(`skipped ${AGENT_FILES}/: not part of the theme`);
|
|
203
|
+
if (ignoredEntries > 0) {
|
|
204
|
+
const noun = ignoredEntries === 1 ? "entry" : "entries";
|
|
205
|
+
io.err(`left out ${ignoredEntries} ${noun} named in ${IGNORE_FILE}`);
|
|
206
|
+
}
|
|
165
207
|
for (const link of skippedLinks) io.err(`skipped ${link}: links can't be submitted`);
|
|
166
208
|
const shown = path.relative(cwd, outPath);
|
|
167
209
|
io.out(`${shown.startsWith("..") ? outPath : shown} (v${pkg.version}, ${entries} entries, ${Math.round(size / 1024)} KB)`);
|
|
210
|
+
for (const line of packedLines(packed)) io.out(line);
|
|
168
211
|
return 0;
|
|
169
212
|
}
|
|
213
|
+
function packedLines(packed) {
|
|
214
|
+
const rows = [...packed].sort(([a], [b]) => a < b ? -1 : 1).map(([top, count]) => [top ? `${top}/` : "(root)", count]);
|
|
215
|
+
const width = Math.max(...rows.map(([label]) => label.length));
|
|
216
|
+
return rows.map(([label, count]) => ` ${label.padEnd(width)} ${count} ${count === 1 ? "file" : "files"}`);
|
|
217
|
+
}
|
|
170
218
|
function mb(n) {
|
|
171
219
|
return (n / 1024 / 1024).toFixed(1);
|
|
172
220
|
}
|
|
173
|
-
export { LIMITS, REQUIRED_FILES, USAGE, pathRefusal, runSource, skipReason };
|
|
221
|
+
export { IGNORE_FILE, LIMITS, REQUIRED_FILES, USAGE, pathRefusal, runSource, skipReason };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/theme-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-next.1",
|
|
4
4
|
"description": "The Shop-On theme developer CLI: `shop-on login`, `shop-on theme init`, `shop-on theme dev`, `shop-on theme mcp`, `shop-on theme audit`, `shop-on theme pack` and `shop-on theme source`.",
|
|
5
5
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
6
6
|
"bin": {
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
15
15
|
"@orpc/client": "1.16.2",
|
|
16
|
-
"@shop-on/create-theme": "0.
|
|
17
|
-
"@shop-on/theme-contract": "0.
|
|
18
|
-
"@shop-on/theme-dev-host": "0.
|
|
16
|
+
"@shop-on/create-theme": "0.14.0-next.1",
|
|
17
|
+
"@shop-on/theme-contract": "0.14.0-next.1",
|
|
18
|
+
"@shop-on/theme-dev-host": "0.14.0-next.1",
|
|
19
19
|
"chrome-launcher": "^1.2.3",
|
|
20
|
+
"ignore": "^7.0.17",
|
|
20
21
|
"lighthouse": "^13.6.0",
|
|
21
22
|
"tar": "^7.5.23",
|
|
22
23
|
"wrangler": "4.162.0",
|