@areslabs/alita
Version:
首个ReactNative转微信小程序引擎
88 lines (67 loc) • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = initProject;
var path = _interopRequireWildcard(require("path"));
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _child_process = _interopRequireDefault(require("child_process"));
var _chalk = _interopRequireDefault(require("chalk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* Copyright (c) Areslabs.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const ALITA_CORE_INIT_TEMP_PATH = function (projectName) {
return path.resolve(process.cwd(), projectName, 'node_modules', '@areslabs', 'alita-core', 'rn-template');
};
const ALITA_CORE_TS_INIT_TEMP_PATH = function (projectName) {
return path.resolve(process.cwd(), projectName, 'node_modules', '@areslabs', 'alita-core', 'rn-typescript-template');
};
function initProject(operands, typescript) {
console.log(_chalk.default.green(` alita init ${typescript ? 'typescript' : ''} ...`));
const initIndex = operands.indexOf('init');
const projectName = operands[initIndex + 1];
if (!projectName) {
console.log(_chalk.default.red('alita初始化 请指定项目名!'));
return;
}
const targetpath = path.resolve(projectName);
const appJSPath = path.resolve(targetpath, 'App.js');
if (_fsExtra.default.existsSync(appJSPath)) {
_fsExtra.default.unlinkSync(appJSPath);
}
const initProPackages = ` @areslabs/router @areslabs/wx-animated `;
const initProDevPackages = ` ${typescript ? '@types/react-native' : ''} @areslabs/alita-weixin-runtime `;
if (_fsExtra.default.existsSync(path.resolve(targetpath, 'yarn.lock'))) {
_child_process.default.execSync(`yarn add ${initProPackages}`, {
cwd: targetpath,
stdio: "ignore"
});
_child_process.default.execSync(`yarn add ${initProDevPackages} --dev`, {
cwd: targetpath,
stdio: "ignore"
});
} else {
_child_process.default.execSync(`npm install --save ${initProPackages}`, {
cwd: targetpath,
stdio: "ignore"
});
_child_process.default.execSync(`npm install --save-dev ${initProDevPackages}`, {
cwd: targetpath,
stdio: "ignore"
});
}
const tempDir = typescript ? ALITA_CORE_TS_INIT_TEMP_PATH(projectName) : ALITA_CORE_INIT_TEMP_PATH(projectName);
_fsExtra.default.copySync(tempDir, targetpath);
console.log(`${_chalk.default.blue(` Run instructions for ${_chalk.default.bold('小程序')}`)}:
• cd ${projectName}
• alita --dev [--dev 指定开发模式]
• 微信开发者工具从 wx-dist 导入项目
`);
}