@eljs/create
Version:
Create a project from a remote template.
155 lines (153 loc) • 4.79 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/core/runner.ts
var runner_exports = {};
__export(runner_exports, {
Runner: () => Runner
});
module.exports = __toCommonJS(runner_exports);
var import_default = require("../default");
var import_types = require("../types");
var import_pluggable = require("@eljs/pluggable");
var import_utils = require("@eljs/utils");
var Runner = class extends import_pluggable.Pluggable {
/**
* 配置项
*/
config;
/**
* 执行阶段
*/
stage = import_types.RunnerStageEnum.Uninitialized;
/**
* 项目路径
*/
paths = /* @__PURE__ */ Object.create(null);
/**
* 应用数据
*/
appData = /* @__PURE__ */ Object.create(null);
/**
* 命令行输入
*/
prompts = /* @__PURE__ */ Object.create(null);
/**
* tsConfig 配置
*/
tsConfig = /* @__PURE__ */ Object.create(null);
/**
* jestConfig 配置
*/
jestConfig = /* @__PURE__ */ Object.create(null);
/**
* prettierConfig 配置
*/
prettierConfig = /* @__PURE__ */ Object.create(null);
constructor(options) {
super({
...options,
defaultConfigFiles: ["create.config.ts", "create.config.js"],
presets: [require.resolve("../internal"), ...options.presets || []],
plugins: options.plugins
});
}
async run(target, projectName) {
await this.load();
await this._resolveConfig();
this.paths = await this.applyPlugins("modifyPaths", {
initialValue: {
cwd: this.cwd,
target
},
args: {
cwd: this.cwd
}
});
this.stage = import_types.RunnerStageEnum.CollectAppData;
this.appData = await this.applyPlugins("modifyAppData", {
initialValue: {
scene: "web",
// eslint-disable-next-line @typescript-eslint/no-var-requires
cliVersion: require("../../package.json").version,
pkg: {},
projectName,
packageManager: "pnpm"
},
args: {
cwd: this.cwd
}
});
const questions = await this.applyPlugins("addQuestions", {
initialValue: [],
args: { cwd: this.cwd }
});
this.prompts = await this.applyPlugins("modifyPrompts", {
initialValue: {},
args: { questions }
});
this.stage = import_types.RunnerStageEnum.CollectTsConfig;
this.tsConfig = await this.applyPlugins("modifyTsConfig", {
initialValue: {}
});
this.stage = import_types.RunnerStageEnum.CollectJestConfig;
this.jestConfig = await this.applyPlugins("modifyJestConfig", {
initialValue: {}
});
this.stage = import_types.RunnerStageEnum.CollectPrettierConfig;
this.prettierConfig = await this.applyPlugins("modifyPrettierConfig", {
initialValue: {}
});
this.stage = import_types.RunnerStageEnum.OnStart;
await this.applyPlugins("onStart");
await this.applyPlugins("onBeforeGenerateFiles", {
args: {
prompts: this.prompts,
paths: this.paths
}
});
await this.applyPlugins("onGenerateFiles", {
args: {
prompts: this.prompts,
paths: this.paths
}
});
await this.applyPlugins("onGenerateDone");
}
async _resolveConfig() {
this.config = (0, import_utils.deepMerge)(
{},
import_default.defaultConfig,
this.constructorOptions,
this.userConfig || {}
);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Runner
});