@gabortorma/mwm
Version:
Multi-repo Workspace Manager
96 lines (91 loc) • 2.65 kB
JavaScript
import { defineCommand } from 'citty';
import { g as generateGitHubRepo, s as sleep, c as cloneRepo, a as getAddRemoteTemplate, b as addRemoteTemplate, d as getFixReplacements, f as fixReplacements, e as commitInitChanges, p as pushChanges, h as packageReplacement, i as getRepo } from '../shared/mwm.DQkHySFI.mjs';
import { p as pnpmExec } from '../shared/mwm.BwrzNYCL.mjs';
import 'simple-git';
import 'node:path';
import 'consola';
import '../shared/mwm.Bxg0O5XR.mjs';
import 'c12';
import '../shared/mwm.CyrEUDRq.mjs';
import 'node:process';
import '@octokit/rest';
import 'pkg-types';
import 'replace-in-file';
import 'change-case';
import 'node:child_process';
async function initRepo(args, template, repo) {
await generateGitHubRepo(template, repo);
await sleep(2e3);
await cloneRepo(repo);
if (await getAddRemoteTemplate(args.addRemoteTemplate))
await addRemoteTemplate(template, repo);
if (await getFixReplacements(args.fixReplacements))
await fixReplacements(template.getReplacements(repo), repo);
pnpmExec(["install", "--fix-lockfile", "--force"], { cwd: repo.path });
pnpmExec(["prepare"], { cwd: repo.path });
pnpmExec(["lint:fix"], { cwd: repo.path });
await commitInitChanges(repo);
await pushChanges(repo);
}
const workspaceTemplate = {
path: ".",
owner: "GaborTorma",
repo: "mwm-workspace-template",
branch: "main",
getReplacements() {
return [
packageReplacement
];
}
};
const main = defineCommand({
meta: {
name: "init",
description: "Initialize new MWM workspace"
},
args: {
owner: {
alias: "organization",
type: "string",
description: "Owner (organization) of the new repo"
},
name: {
type: "string",
description: "Name of the new repo"
},
description: {
alias: "desc",
type: "string",
description: "Description of the new repo"
},
dir: {
type: "string",
description: "Directory to clone the new repo"
},
private: {
type: "boolean",
default: true,
description: "Create a non-private repository"
},
keywords: {
type: "string",
description: "Keywords (comma separated)"
},
addRemoteTemplate: {
alias: "add-remote-template",
type: "boolean",
description: "Add remote template repository"
},
fixReplacements: {
alias: "fix-replacements",
type: "boolean",
description: "Fix replacements"
}
},
async run({ args }) {
const template = workspaceTemplate;
const repo = await getRepo(args, template);
await initRepo(args, template, repo);
}
});
export { main };