UNPKG

@lerna/publish

Version:

Publish packages in the current project

106 lines (105 loc) 4.76 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var fixtures_exports = {}; __export(fixtures_exports, { cloneFixtureFactory: () => cloneFixtureFactory, copyFixture: () => copyFixture, initFixtureFactory: () => initFixtureFactory, initNamedFixtureFactory: () => initNamedFixtureFactory }); module.exports = __toCommonJS(fixtures_exports); var import_execa = __toESM(require("execa")); var import_file_url = __toESM(require("file-url")); var import_find_up = __toESM(require("find-up")); var import_fs_extra = require("fs-extra"); var import_path = require("path"); var import_tempy = require("tempy"); var import_git = require("./git"); function cloneFixtureFactory(startDir) { const initFixture = initFixtureFactory(startDir); return (...args) => ( // TODO: refactor to address type issues // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore initFixture(...args).then((cwd) => { const repoDir = (0, import_tempy.directory)(); const repoUrl = (0, import_file_url.default)(repoDir, { resolve: false }); return (0, import_execa.default)("git", ["init", "--bare"], { cwd: repoDir }).then(() => (0, import_execa.default)("git", ["checkout", "-B", "main"], { cwd })).then(() => (0, import_execa.default)("git", ["remote", "add", "origin", repoUrl], { cwd })).then(() => (0, import_execa.default)("git", ["push", "-u", "origin", "main"], { cwd })).then(() => ({ cwd, repository: repoUrl })); }) ); } function findFixture(cwd, fixtureName) { return (0, import_find_up.default)((0, import_path.join)("__fixtures__", fixtureName), { cwd, type: "directory" }).then((fixturePath) => { if (fixturePath === void 0) { throw new Error(`Could not find fixture with name "${fixtureName}"`); } return fixturePath; }); } function copyFixture(targetDir, fixtureName, cwd) { return findFixture(cwd, fixtureName).then((fp) => (0, import_fs_extra.copy)(fp, targetDir)); } function initFixtureFactory(startDir) { return (fixtureName, commitMessage = "Init commit") => { const cwd = (0, import_tempy.directory)(); let chain = Promise.resolve(); chain = chain.then(() => process.chdir(cwd)); chain = chain.then(() => copyFixture(cwd, fixtureName, startDir)); chain = chain.then(() => (0, import_git.gitInit)(cwd, ".")); if (commitMessage) { chain = chain.then(() => (0, import_git.gitAdd)(cwd, "-A")); chain = chain.then(() => (0, import_git.gitCommit)(cwd, commitMessage)); } return chain.then(() => cwd); }; } function initNamedFixtureFactory(startDir) { return (dirName, fixtureName, commitMessage = "Init commit") => { const cwd = (0, import_path.join)((0, import_tempy.directory)(), dirName); let chain = Promise.resolve(); chain = chain.then(() => (0, import_fs_extra.ensureDir)(cwd)); chain = chain.then(() => process.chdir(cwd)); chain = chain.then(() => copyFixture(cwd, fixtureName, startDir)); chain = chain.then(() => (0, import_git.gitInit)(cwd, ".")); if (commitMessage) { chain = chain.then(() => (0, import_git.gitAdd)(cwd, "-A")); chain = chain.then(() => (0, import_git.gitCommit)(cwd, commitMessage)); } return chain.then(() => cwd); }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { cloneFixtureFactory, copyFixture, initFixtureFactory, initNamedFixtureFactory });