Skip to content

Commit 7be5bf5

Browse files
committed
feat: auto create gists
1 parent fd96578 commit 7be5bf5

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

cli.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22
"use strict";
3+
34
const { parse, resolve } = require("path");
5+
const fs = require("fs");
46

57
const sharp = require("sharp");
68
const execa = require("execa");
@@ -10,7 +12,7 @@ const meow = require("meow");
1012
const got = require("got");
1113
const cp = require("cp-file");
1214

13-
const { cloneGistPath, addAll, commitAll, push } = require("./git-util");
15+
const { cloneGistPath, commitAll, push } = require("./git-util");
1416

1517
const CONTAINER_WIDTH = 727;
1618
const CUT_WIDTH = 325;
@@ -147,14 +149,21 @@ const crop = async (path, githubToken) => {
147149
body
148150
});
149151
const data = JSON.parse(res);
150-
console.log(`Gist for ${file} has been created in ${data.html_url}`);
152+
console.log(`Prepared the gist for ${file} in ${data.html_url}`);
151153
await cloneGistPath(data.id);
152154
await cp(file, `${data.id}/${file}`);
153155
const gitPath = resolve(`./${data.id}/.git`);
154-
await addAll(gitPath);
155156
await commitAll(gitPath);
157+
fs.writeFileSync(
158+
`${data.id}/.netrc`,
159+
`machine github.com\nlogin ${
160+
data.owner.login
161+
}\npassword ${githubToken}`
162+
);
156163
await push(gitPath);
157-
console.log(`${isGif ? "GIF" : "Image"} has been added to the gist`);
164+
console.log(
165+
`${isGif ? "GIF" : "Image"} ${file} has been added to the gist`
166+
);
158167
}
159168
} catch (e) {
160169
console.error(e);

git-util.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ const execa = require("execa");
33
exports.cloneGistPath = hash =>
44
execa("git", ["clone", `https://gist.github.com/${hash}.git`]);
55

6-
exports.addAll = gitPath => execa("git", [`--git-dir=${gitPath}`, "add", "."]);
7-
86
exports.commitAll = gitPath =>
9-
execa("git", [`--git-dir=${gitPath}`, "commit", "-am", '"update gist file"']);
7+
execa("git", [`--git-dir=${gitPath}`, "commit", "-am", "update gist file"]);
108

119
exports.push = gitPath => execa("git", [`--git-dir=${gitPath}`, "push"]);

0 commit comments

Comments
 (0)