@gabortorma/mwm
Version:
Multi-repo Workspace Manager
98 lines (92 loc) • 2.54 kB
JavaScript
'use strict';
const citty = require('citty');
const index = require('../shared/mwm.C9KLt13K.cjs');
const pnpm = require('../shared/mwm.DTKjIVEs.cjs');
require('simple-git');
require('node:path');
require('consola');
require('../shared/mwm.b-NRmH8L.cjs');
require('c12');
require('../shared/mwm.Bc81aV-e.cjs');
require('node:process');
require('@octokit/rest');
require('pkg-types');
require('replace-in-file');
require('change-case');
require('node:child_process');
async function initRepo(args, template, repo) {
await index.generateGitHubRepo(template, repo);
await index.sleep(2e3);
await index.cloneRepo(repo);
if (await index.getAddRemoteTemplate(args.addRemoteTemplate))
await index.addRemoteTemplate(template, repo);
if (await index.getFixReplacements(args.fixReplacements))
await index.fixReplacements(template.getReplacements(repo), repo);
pnpm.pnpmExec(["install", "--fix-lockfile", "--force"], { cwd: repo.path });
pnpm.pnpmExec(["prepare"], { cwd: repo.path });
pnpm.pnpmExec(["lint:fix"], { cwd: repo.path });
await index.commitInitChanges(repo);
await index.pushChanges(repo);
}
const workspaceTemplate = {
path: ".",
owner: "GaborTorma",
repo: "mwm-workspace-template",
branch: "main",
getReplacements() {
return [
index.packageReplacement
];
}
};
const main = citty.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 index.getRepo(args, template);
await initRepo(args, template, repo);
}
});
exports.main = main;