@eljs/release
Version:
Release npm package easily.
175 lines (173 loc) • 5.5 kB
JavaScript
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);
// src/runner.ts
var runner_exports = {};
__export(runner_exports, {
Runner: () => Runner
});
module.exports = __toCommonJS(runner_exports);
var import_pluggable = require("@eljs/pluggable");
var import_utils = require("@eljs/utils");
var import_node_os = require("node:os");
var import_node_path = __toESM(require("node:path"));
var import_default = require("./default");
var import_utils2 = require("./utils");
var debug = (0, import_utils.createDebugger)("release:config");
var Runner = class extends import_pluggable.Pluggable {
/**
* 配置项
*/
config;
/**
* 应用数据
*/
appData = /* @__PURE__ */ Object.create(null);
constructor(options = {}) {
const { cwd = process.cwd(), presets = [], plugins = [] } = options;
const projectPkgJsonPath = import_node_path.default.join(cwd, "package.json");
if (!(0, import_utils.isPathExistsSync)(projectPkgJsonPath)) {
throw new import_utils2.AppError(`No package.json was found in ${import_utils.chalk.cyan(cwd)}.`);
}
const projectPkg = (0, import_utils.readJsonSync)(projectPkgJsonPath);
if (!projectPkg.version) {
throw new import_utils2.AppError(
`No version field was found in ${import_utils.chalk.cyan(projectPkgJsonPath)}.`
);
}
super({
...options,
cwd,
defaultConfigFiles: ["release.config.ts", "release.config.js"],
presets: [require.resolve("./internal"), ...presets],
plugins
});
this.appData = {
projectPkgJsonPath,
projectPkg
};
}
async run(releaseTypeOrVersion) {
try {
await this.load();
await this._resolveConfig();
this.appData = await this.applyPlugins("modifyAppData", {
initialValue: {
...this.appData,
// eslint-disable-next-line @typescript-eslint/no-var-requires
cliVersion: require("../package.json").version,
packageManager: "pnpm"
},
args: {
cwd: this.cwd
}
});
await this.applyPlugins("onCheck", {
args: {
releaseTypeOrVersion
}
});
await this.applyPlugins("onStart");
const rawVersion = await this.applyPlugins("getIncrementVersion", {
args: {
releaseTypeOrVersion
}
});
if (rawVersion) {
const version = (0, import_utils2.parseVersion)(rawVersion);
await this.applyPlugins("onBeforeBumpVersion", {
args: {
...version
}
});
await this.applyPlugins("onBumpVersion", {
args: {
...version
}
});
await this.applyPlugins("onAfterBumpVersion", {
args: {
...version
}
});
const changelog = await this.applyPlugins("getChangelog", {
args: {
...version
}
});
await this.applyPlugins("onBeforeRelease", {
args: {
...version,
changelog
}
});
await this.applyPlugins("onRelease", {
args: {
...version,
changelog
}
});
await this.applyPlugins("onAfterRelease", {
args: {
...version,
changelog
}
});
}
} catch (error) {
if (error instanceof import_utils2.AppError) {
import_utils.logger.error(error.message);
} else {
console.log(error);
}
throw error;
}
}
/**
* 发布步骤打印
* @param message 信息
*/
step(message) {
return import_utils.logger.step("Release", `${message}${import_node_os.EOL}`);
}
async _resolveConfig() {
const mergedConfig = (0, import_utils.deepMerge)(
{},
import_default.defaultConfig,
this.constructorOptions,
this.userConfig || {}
);
debug == null ? void 0 : debug(mergedConfig);
this.config = await this.applyPlugins("modifyConfig", {
initialValue: mergedConfig
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Runner
});