Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions design/assets/fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ for (const find of ["command -v spacesheep", "npx -y -p spacesheep@latest -c 'co
if (bin) { cli = [bin]; break; }
} catch {}
}
// Every deploy names this skill, so the space counts as made with it on the skill's page (the first note per space
// counts; a CLI or server without the field publishes as before).
const MADE_WITH = ["--skill", "@spacesheep/design"];
const run = (args, opts = {}) => execFileSync(cli[0], [...cli.slice(1), ...args], { encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 60000, killSignal: "SIGKILL", ...opts });
const runAsync = (args) => new Promise((ok) => {
const t = allowed(90000);
Expand Down Expand Up @@ -373,7 +376,7 @@ function deploy(message) {
if (!t) return { ok: false, lines: [`not called: ${lost}`] };
let page = null;
try { page = fs.readFileSync("work/index.html"); } catch {}
const r = spawnSync(cli[0], [...cli.slice(1), "deploy", "work", "--space", space, "-m", message], { encoding: "utf8", timeout: t, killSignal: "SIGKILL" });
const r = spawnSync(cli[0], [...cli.slice(1), "deploy", "work", "--space", space, "-m", message, ...MADE_WITH], { encoding: "utf8", timeout: t, killSignal: "SIGKILL" });
const said = `${r.stdout || ""}\n${r.stderr || ""}`.split("\n").map((l) => l.trim()).filter(Boolean).filter((l) => !/^spacesheep /.test(l));
if (r.error && r.error.code === "ETIMEDOUT") {
const s = `${Math.round(t / 1000)} s`, v = landed(message, before, page);
Expand Down Expand Up @@ -618,7 +621,7 @@ if (cmd === "start") {
mkdir("work");
const base = baseHtml(), title = plain("title", argv[2]) || "Design";
if (!work() || !setWork(firstPage(title, base))) process.exit(2);
const out = run(["deploy", "work", "--title", title, "--json"]);
const out = run(["deploy", "work", "--title", title, ...MADE_WITH, "--json"]);
const j = JSON.parse(out.slice(out.indexOf("{")));
space = (j.space || {}).id;
if (!UUID.test(space || "")) { console.error("start: the new space's id isn't in the answer"); process.exit(1); }
Expand Down Expand Up @@ -1039,7 +1042,7 @@ if (cmd === "copy") {
mkdir(dir);
if (!write(`${dir}/index.html`, out)) process.exit(2);
let j;
try { const r = run(["deploy", dir, "--title", name, "--json"]); j = JSON.parse(r.slice(r.indexOf("{"))); }
try { const r = run(["deploy", dir, "--title", name, ...MADE_WITH, "--json"]); j = JSON.parse(r.slice(r.indexOf("{"))); }
catch (e) { console.error(`copy: the new space wasn't made: ${String(e.stderr || e.message || e).trim().split("\n").pop()}`); process.exit(1); }
console.log(`copy: ${name} alone in a new space, private: ${(j.space || {}).url || (j.space || {}).id}; this space is as it was`);
process.exit(0);
Expand Down
13 changes: 12 additions & 1 deletion test/fold.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ test("stop with a message saves, and that save takes the work card down: no empt
assert.ok(!sent().some((b) => b.status === ""), "no empty status");
});

test("every deploy names the skill, so the space counts as made with it: the new space and each save (a copy: below)", () => {
const { fold, calls } = setup();
assert.equal(fold(["start", "--new", "Poster"]).status, 0);
assert.equal(fold(["save", "Frame", "Drawing three directions"]).status, 0);
assert.equal(fold(["wait"]).status, 0);
assert.equal(fold(["stop", "Three poster looks"]).status, 0);
const deploys = calls().filter((a) => a[0] === "deploy");
assert.equal(deploys.length, 3, JSON.stringify(deploys));
for (const d of deploys) assert.equal(d[d.indexOf("--skill") + 1], "@spacesheep/design", JSON.stringify(d));
});

test("start says the next step, and push names the starter's placeholders after their sections without touching the rest", () => {
const { folder, fold, sent } = setup();
const r = fold(["start", "--new", "Poster"]);
Expand Down Expand Up @@ -1002,7 +1013,7 @@ test("copy puts one direction alone, its views with it, in a new space named aft
const r = fold(["copy", "second"]);
assert.equal(r.status, 0, r.stderr);
assert.match(r.stdout, /^copy: Second alone in a new space, private: https:\/\/stage\.test\/s; this space is as it was$/m);
assert.deepEqual(calls().slice(n), [["deploy", "draw/_copy/second", "--title", "Second", "--json"]], "one deploy, of the copy, as a new space");
assert.deepEqual(calls().slice(n), [["deploy", "draw/_copy/second", "--title", "Second", "--skill", "@spacesheep/design", "--json"]], "one deploy, of the copy, as a new space, naming the skill");
assert.equal(fs.readFileSync(file, "utf8"), before, "work/index.html as it was");
const copy = fs.readFileSync(path.join(folder, "draw", "_copy", "second", "index.html"), "utf8");
assert.deepEqual([...copy.matchAll(/<section class="direction"[^>]*data-ss-id="([a-z-]+)"/g)].map((m) => m[1]), ["direction-second", "second-phone"]);
Expand Down