@rnv/engine-core
Version:
ReNative Engine Core
163 lines • 8.47 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var path_1 = tslib_1.__importDefault(require("path"));
var core_1 = require("@rnv/core");
var getContext_1 = require("../../getContext");
exports.default = (0, core_1.createTask)({
description: 'Create new app config',
fn: function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var sourcePath, c, sourceAppConfigDirPath, tacDirs, appConfigChoicesObj_1, appConfigChoices_1, acDirs, tacDirs, sourceAppConfig, destPath, appConfigId, confName, confObjPath, confObj, appConfigTitle, confTitle, bundleId, confId;
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, core_1.logTask)('taskAppCreate');
return [4 /*yield*/, (0, core_1.configureRuntimeDefaults)()];
case 1:
_c.sent();
c = (0, getContext_1.getContext)();
if (!c.program.opts().sourceAppConfigID) return [3 /*break*/, 2];
sourceAppConfigDirPath = path_1.default.join(c.paths.project.appConfigsDir, c.program.opts().sourceAppConfigID);
if ((0, core_1.fsExistsSync)(sourceAppConfigDirPath)) {
sourcePath = sourceAppConfigDirPath;
}
return [3 /*break*/, 5];
case 2:
if (!c.program.opts().ci) return [3 /*break*/, 3];
if (c.paths.template.appConfigsDir) {
if ((0, core_1.fsExistsSync)(c.paths.template.appConfigsDir)) {
tacDirs = (0, core_1.fsReaddirSync)(c.paths.template.appConfigsDir);
tacDirs.forEach(function (v) {
if (v !== 'base') {
var pth = path_1.default.join(c.paths.template.appConfigsDir, v);
if ((0, core_1.fsLstatSync)(pth).isDirectory()) {
sourcePath = pth;
}
}
});
}
}
return [3 /*break*/, 5];
case 3:
appConfigChoicesObj_1 = {};
appConfigChoices_1 = [];
acDirs = (0, core_1.fsReaddirSync)(c.paths.project.appConfigsDir);
acDirs.forEach(function (v) {
if (v !== 'base') {
var pth = path_1.default.join(c.paths.project.appConfigsDir, v);
if ((0, core_1.fsLstatSync)(pth).isDirectory()) {
var key = "project>".concat(v);
appConfigChoices_1.push(key);
appConfigChoicesObj_1[key] = {
path: pth,
};
}
}
});
// Template Configs
if (c.paths.template.appConfigsDir) {
tacDirs = (0, core_1.fsReaddirSync)(c.paths.template.appConfigsDir);
tacDirs.forEach(function (v) {
if (v !== 'base') {
var pth = path_1.default.join(c.paths.template.appConfigsDir, v);
if ((0, core_1.fsLstatSync)(pth).isDirectory()) {
var key = "template>".concat(v);
appConfigChoices_1.push(key);
appConfigChoicesObj_1[key] = {
path: pth,
};
}
}
});
}
return [4 /*yield*/, (0, core_1.inquirerPrompt)({
name: 'sourceAppConfig',
type: 'list',
choices: appConfigChoices_1,
message: 'Which App config to use as copy source?',
})];
case 4:
sourceAppConfig = (_c.sent()).sourceAppConfig;
sourcePath = appConfigChoicesObj_1[sourceAppConfig].path;
_c.label = 5;
case 5:
if (!c.program.opts().appConfigID) return [3 /*break*/, 6];
appConfigId = c.program.opts().appConfigID.toLowerCase();
destPath = path_1.default.join(c.paths.project.appConfigsDir, appConfigId);
return [3 /*break*/, 8];
case 6: return [4 /*yield*/, (0, core_1.inquirerPrompt)({
name: 'confName',
type: 'input',
message: 'Type name of app config (lowercase)',
})];
case 7:
confName = (_c.sent()).confName;
appConfigId = confName.toLowerCase();
destPath = path_1.default.join(c.paths.project.appConfigsDir, appConfigId);
_c.label = 8;
case 8:
(0, core_1.logInfo)('Copying new app config...');
if (!sourcePath) return [3 /*break*/, 10];
return [4 /*yield*/, (0, core_1.copyFolderContentsRecursive)(sourcePath, destPath)];
case 9:
_c.sent();
_c.label = 10;
case 10:
(0, core_1.logInfo)('Copying new app config...DONE');
confObjPath = path_1.default.join(destPath, 'renative.json');
confObj = (0, core_1.readObjectSync)(confObjPath) || {};
confObj.id = appConfigId;
confObj.common = confObj.common || {};
if (!c.program.opts().title) return [3 /*break*/, 11];
appConfigTitle = c.program.opts().title;
return [3 /*break*/, 14];
case 11:
if (!c.program.opts().ci) return [3 /*break*/, 12];
return [3 /*break*/, 14];
case 12: return [4 /*yield*/, (0, core_1.inquirerPrompt)({
name: 'confTitle',
type: 'input',
default: ((_a = confObj.common) === null || _a === void 0 ? void 0 : _a.title) || '',
message: 'Type the title of the app',
})];
case 13:
confTitle = (_c.sent()).confTitle;
appConfigTitle = confTitle;
_c.label = 14;
case 14:
confObj.common.title = appConfigTitle || confObj.common.title;
if (!c.program.opts().id) return [3 /*break*/, 15];
bundleId = c.program.opts().id;
return [3 /*break*/, 18];
case 15:
if (!c.program.opts().ci) return [3 /*break*/, 16];
return [3 /*break*/, 18];
case 16: return [4 /*yield*/, (0, core_1.inquirerPrompt)({
name: 'confId',
type: 'input',
default: ((_b = confObj.common) === null || _b === void 0 ? void 0 : _b.id) || '',
message: 'Type the id of the app (bundle identifier)',
})];
case 17:
confId = (_c.sent()).confId;
bundleId = confId;
_c.label = 18;
case 18:
confObj.common.id = bundleId || confObj.common.id;
(0, core_1.writeFileSync)(confObjPath, confObj);
return [2 /*return*/, true];
}
});
}); },
options: [
{
key: 'sourceAppConfigID',
isValueType: true,
isRequired: true,
description: 'name of source appConfig folder to copy from',
},
],
task: core_1.RnvTaskName.appCreate,
});
//# sourceMappingURL=taskAppCreate.js.map
;