Joël Grimberg

Joël Grimberg

// Name: Gitlab
// Menu: Gitlab Boilerplate Repository
// Description: Create a new Gitlab repository
// Shortcut: command option g
// Author: Joël Grimberg
// Twitter: @joelgrimberg
import "@johnlindquist/kit";
import fs from "fs";
const filenamify = await npm("filenamify");
/** @type {typeof import("filenamify")} */
const GITLAB_USER = await env(
"GITLAB_USER",
"please enter your Gitlab username"
);
const GITLAB_AUTH_TOKEN = await env(
"GITLAB_AUTH_TOKEN",
"please enter your Gitlab Auth token"
);
const GITLAB_BOILERPLATE_FOLDER = await env(
"gitlabBoilerplateFolder",
"please enter the location you want to save your boilerplate folder"
);
const NPM_AUTHOR_NAME = await env(
"NPM_AUTHOR_NAME",
"please enter your NPM author name"
);
const boilerplateProject = await arg({
pleaceholder: "please enter the name of your project",
hint: "name of repository",
});
const project = filenamify(boilerplateProject);
const boilerplateDescription = await arg({
placeholder: `project description`,
hint: "a description oneliner",
});
const pwd = `${GITLAB_BOILERPLATE_FOLDER}/${project}`;
//TODO
fs.mkdirSync(pwd);
cd(pwd);
await $`npm init -y -init-author-name='${NPM_AUTHOR_NAME}'`;
await $`git init`;
await $`echo "/node_modules" > .gitignore`;
await $`npm install cypress --save-dev`;
await $`echo '
<h1 align="center"><a href="https://blog.joelgrimberg.dev">🚀 ${project}</a></h1>' > README.md`;
await $`git add .`;
await $`git commit -m 'initial commit'`;
await $`git remote add origin git@gitlab.com:${GITLAB_USER}/${project}.git`;
await $`curl --silent --header "PRIVATE-TOKEN: ${GITLAB_AUTH_TOKEN}" \
-XPOST "https://gitlab.com/api/v4/projects?name=${project}&visibility=private&initialize_with_readme=false" | jq '.id'`;
await $`git push --set-upstream origin main`;
edit(`README.md`, pwd);
browse(`https://gitlab.com/${GITLAB_USER}/${project}`);
import "@johnlindquist/kit";
// Menu: Boilerplate repository
// Description: Create a new github repository
// Shortcut: command option control b
// Author: Joël Grimberg
// Twitter: @joelgrimberg
import fs from "fs";
const open = await npm("open");
const { Octokit } = await npm("@octokit/rest");
const simpleGit = await npm("simple-git");
const boilerplateFolder = await env(
"BOILERPLATE_DIR",
`What's the path to the boilerplate directory on this machine?`
);
const githubAuthToken = await env(
"githubAuthToken",
`Please enter the GitHub token`
);
const octokit = new Octokit({
auth: githubAuthToken,
});
const project = await arg({
placeholder: `What is the name of the project?`,
hint: "repo-name",
ignoreBlur: true,
});
const description = await arg({
placeholder: `What is the description of the project?`,
hint: "description",
ignoreBlur: true,
});
octokit.rest.repos.createForAuthenticatedUser({
name: project,
});
if (!fs.existsSync(boilerplateFolder)) {
fs.mkdirSync(boilerplateFolder);
}
const pwd = `${boilerplateFolder}/${project}`;
fs.mkdirSync(pwd);
const options = {
baseDir: pwd,
binary: "git",
maxConcurrentProcesses: 6,
};
const git = simpleGit(options);
await git
.init()
.addRemote("origin", `git@github.com:joelgrimberg/${project}.git`);
await $`cd ${pwd} && npm init -y -init-author-name='Joël Grimberg <joel@joelgrimberg.nl> (https://blog.joelgrimberg.dev)'`;
await $`cd ${pwd} && npm install cypress --save-dev`;
await $`cd ${pwd} && echo '
<h1 align="center"><a href="https://blog.joelgrimberg.dev">🚀 ${project}</a></h1>' > README.md`;
await $`cd ${pwd} && echo -n "## ${description}" >> README.md`;
await $`echo "node_modules/" > ${pwd}/.gitignore`;
await git.add(".").commit("initial commit");
await $`cd ${pwd} && git push --set-upstream origin main`;
edit(`${pwd}/README.md`, pwd);
browse(`https://github.com/joelgrimberg/${project}`);