@tarojs/cli
Version:
cli tool for taro
53 lines • 2.71 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const helper_1 = require("@tarojs/helper");
const path = require("path");
const util_1 = require("../util");
const creator_1 = require("./creator");
class Plugin extends creator_1.default {
constructor(options) {
super();
this.conf = Object.assign(Object.assign({}, options), { projectName: path.basename(options.projectDir), version: this.getCliVersion() });
}
getCliVersion() {
const pkgPath = path.join(this._rootPath, 'package.json');
const pkg = helper_1.fs.readJSONSync(pkgPath);
return pkg.version;
}
create() {
return __awaiter(this, void 0, void 0, function* () {
const { projectDir, template, pluginName } = this.conf;
const templatePath = this.templatePath(template);
if (!helper_1.fs.existsSync(templatePath)) {
console.log(helper_1.chalk.red(`创建插件失败:找不到模板${templatePath}`));
return;
}
const logs = [];
const templateFiles = yield (0, util_1.getAllFilesInFolder)(templatePath);
templateFiles.forEach(file => {
const relativePath = path.relative(templatePath, file);
const destPath = path.join(projectDir, pluginName, relativePath);
this.template(template, relativePath, destPath, this.conf);
const destinationPath = this.destinationPath(destPath);
logs.push(`${helper_1.chalk.green('✔ ')}${helper_1.chalk.grey(`创建文件: ${destinationPath}`)}`);
});
this.fs.commit(() => {
console.log();
logs.forEach(log => console.log(log));
console.log();
console.log(`${helper_1.chalk.green('✔ ')}${helper_1.chalk.grey(`创建插件 ${this.conf.pluginName} 成功!`)}`);
});
});
}
}
exports.default = Plugin;
//# sourceMappingURL=plugin.js.map