gitsona 0.1.0 → 0.1.2
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/cli.js +2 -4
- package/dist/publish.js +74 -2
- package/dist/version.js +1 -1
- package/package.json +5 -1
package/dist/cli.js
CHANGED
|
@@ -7,12 +7,11 @@ import { analyze } from "./analyze.js";
|
|
|
7
7
|
import { collect } from "./collect.js";
|
|
8
8
|
import { GitHub, GitHubError, resolveToken } from "./github.js";
|
|
9
9
|
import { previewHtml } from "./preview.js";
|
|
10
|
-
import { commitAndPush, createProfileRepo, ensureCheckout, hasGh, repoExists, writeWorkflow } from "./publish.js";
|
|
10
|
+
import { ASSETS, commitAndPush, createProfileRepo, DRAWN, ensureCheckout, hasGh, repoExists, writeWorkflow, } from "./publish.js";
|
|
11
11
|
import { mergeReadme, readmeBlock } from "./readme.js";
|
|
12
12
|
import { DEFAULT_TYPESET, fontFileProblem, TYPESET_NAMES, TYPESETS, withDisplayFont, } from "./render/fonts.js";
|
|
13
13
|
import { fetchAvatars, render, SECTIONS } from "./render/index.js";
|
|
14
14
|
import { VERSION } from "./version.js";
|
|
15
|
-
const ASSETS = "gitsona";
|
|
16
15
|
const HELP = `gitsona ${VERSION}
|
|
17
16
|
Draw a GitHub profile README from what you actually do on GitHub.
|
|
18
17
|
|
|
@@ -165,8 +164,7 @@ async function main(argv) {
|
|
|
165
164
|
writeFileSync(join(out, ASSETS, name), svg);
|
|
166
165
|
// Images from an earlier run that this run no longer draws (a project that left the cards).
|
|
167
166
|
// Only gitsona's own file names are touched, so anything else kept in the folder stays.
|
|
168
|
-
const
|
|
169
|
-
const stale = readdirSync(join(out, ASSETS), { withFileTypes: true }).filter((e) => e.isFile() && ours.test(e.name) && !rendered.files.has(e.name));
|
|
167
|
+
const stale = readdirSync(join(out, ASSETS), { withFileTypes: true }).filter((e) => e.isFile() && DRAWN.test(e.name) && !rendered.files.has(e.name));
|
|
170
168
|
for (const e of stale)
|
|
171
169
|
rmSync(join(out, ASSETS, e.name), { force: true });
|
|
172
170
|
const readmePath = join(out, "README.md");
|
package/dist/publish.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { END, START } from "./readme.js";
|
|
4
5
|
import { VERSION } from "./version.js";
|
|
6
|
+
/** Folder gitsona draws its images into, next to README.md. */
|
|
7
|
+
export const ASSETS = "gitsona";
|
|
8
|
+
/** Image names gitsona itself writes into ASSETS; anything else in the folder is someone else's. */
|
|
9
|
+
export const DRAWN = /^(hero|traits|rhythm|strata|upstream|project-[a-z0-9._-]+)-(dark|light)\.svg$/;
|
|
5
10
|
function run(cmd, args, cwd) {
|
|
6
11
|
const r = spawnSync(cmd, args, { cwd, encoding: "utf8" });
|
|
7
12
|
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
@@ -28,13 +33,80 @@ export function createProfileRepo(login) {
|
|
|
28
33
|
export function ensureCheckout(login, dir) {
|
|
29
34
|
if (existsSync(join(dir, ".git")))
|
|
30
35
|
return;
|
|
36
|
+
// `gitsona --preview` then `gitsona --push` leaves an earlier draw in the default folder. It is
|
|
37
|
+
// redrawn right after the clone, so it can be replaced, but only once the clone has worked.
|
|
38
|
+
if (isEarlierDraw(dir)) {
|
|
39
|
+
// Clone next to dir, then swap contents in. dir itself stays, since it may be the working directory.
|
|
40
|
+
const tmp = mkdtempSync(join(dirname(dir), ".gitsona-clone-"));
|
|
41
|
+
try {
|
|
42
|
+
clone(login, tmp);
|
|
43
|
+
for (const e of readdirSync(dir))
|
|
44
|
+
rmSync(join(dir, e), { recursive: true, force: true });
|
|
45
|
+
for (const e of readdirSync(tmp))
|
|
46
|
+
renameSync(join(tmp, e), join(dir, e));
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
31
53
|
if (existsSync(dir) && readdirSync(dir).length > 0) {
|
|
32
54
|
throw new Error(`${dir} exists and is not a git checkout. Pick an empty --out directory, or run gitsona inside your ${login}/${login} clone.`);
|
|
33
55
|
}
|
|
56
|
+
clone(login, dir);
|
|
57
|
+
}
|
|
58
|
+
function clone(login, dir) {
|
|
34
59
|
const r = run("gh", ["repo", "clone", `${login}/${login}`, dir]);
|
|
35
60
|
if (!r.ok)
|
|
36
61
|
throw new Error(`gh repo clone failed: ${r.out}`);
|
|
37
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* True when dir holds nothing but files a previous gitsona run wrote: a README.md with no text outside
|
|
65
|
+
* the gitsona markers, drawn images, the preview page, profile.json and the workflow.
|
|
66
|
+
*/
|
|
67
|
+
export function isEarlierDraw(dir) {
|
|
68
|
+
try {
|
|
69
|
+
return holdsOnlyADraw(dir);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function holdsOnlyADraw(dir) {
|
|
76
|
+
// lstat, so a symlink never counts as one of gitsona's files or folders.
|
|
77
|
+
const isFile = (p) => lstatSync(p).isFile();
|
|
78
|
+
const isDir = (p) => lstatSync(p).isDirectory();
|
|
79
|
+
if (!existsSync(dir) || !isDir(dir))
|
|
80
|
+
return false;
|
|
81
|
+
const top = readdirSync(dir);
|
|
82
|
+
if (!top.length)
|
|
83
|
+
return false;
|
|
84
|
+
const files = new Set(["README.md", "gitsona-preview.html", ".DS_Store"]);
|
|
85
|
+
const dirs = new Set([ASSETS, ".github"]);
|
|
86
|
+
if (!top.every((e) => (files.has(e) && isFile(join(dir, e))) || (dirs.has(e) && isDir(join(dir, e)))))
|
|
87
|
+
return false;
|
|
88
|
+
if (top.includes("README.md")) {
|
|
89
|
+
const text = readFileSync(join(dir, "README.md"), "utf8");
|
|
90
|
+
const s = text.indexOf(START);
|
|
91
|
+
const e = text.indexOf(END);
|
|
92
|
+
if (s < 0 || e < s || (text.slice(0, s) + text.slice(e + END.length)).trim())
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (top.includes(ASSETS)) {
|
|
96
|
+
const own = (n) => DRAWN.test(n) || n === "profile.json" || n === ".DS_Store";
|
|
97
|
+
if (!readdirSync(join(dir, ASSETS)).every((n) => own(n) && isFile(join(dir, ASSETS, n))))
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (top.includes(".github")) {
|
|
101
|
+
const gh = readdirSync(join(dir, ".github"));
|
|
102
|
+
if (gh.length !== 1 || gh[0] !== "workflows" || !isDir(join(dir, ".github", "workflows")))
|
|
103
|
+
return false;
|
|
104
|
+
const wf = readdirSync(join(dir, ".github", "workflows"));
|
|
105
|
+
if (wf.length !== 1 || wf[0] !== "gitsona.yml" || !isFile(join(dir, ".github", "workflows", "gitsona.yml")))
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
38
110
|
export function commitAndPush(dir, paths, message) {
|
|
39
111
|
const add = run("git", ["add", "--", ...paths], dir);
|
|
40
112
|
if (!add.ok)
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Kept equal to package.json by test/version.test.ts; the release workflow runs that test before publishing. */
|
|
2
|
-
export const VERSION = "0.1.
|
|
2
|
+
export const VERSION = "0.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitsona",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "One command to turn your real GitHub activity into a profile README that looks designed and says something true about you.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"generator"
|
|
35
35
|
],
|
|
36
36
|
"license": "MIT",
|
|
37
|
+
"homepage": "https://github.com/kanywst/gitsona#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/kanywst/gitsona/issues"
|
|
40
|
+
},
|
|
37
41
|
"repository": {
|
|
38
42
|
"type": "git",
|
|
39
43
|
"url": "git+https://github.com/kanywst/gitsona.git"
|