@cuba-platform/front-generator
Version:
CUBA Platform front-end clients generator
75 lines • 3.69 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 });
exports.params = exports.options = exports.generator = void 0;
const base_generator_1 = require("../../../common/base-generator");
const sdk_generator_1 = require("../../sdk/sdk-generator");
const cli_options_1 = require("../../../common/cli-options");
const path = require("path");
const studio_integration_1 = require("../../../common/studio/studio-integration");
class ReactNativeAppGenerator extends base_generator_1.BaseGenerator {
constructor(args, options) {
super(args, options);
this.sourceRoot(path.join(__dirname, 'template'));
}
// noinspection JSUnusedGlobalSymbols - yeoman runs all methods from class
prompting() {
return __awaiter(this, void 0, void 0, function* () {
if (this.options.model) {
this.conflicter.force = true;
this.log('Skipping prompts since model provided');
this.cubaProjectModel = this._readProjectModel();
return;
}
yield this._obtainCubaProjectModel();
});
}
// noinspection JSUnusedGlobalSymbols - yeoman runs all methods from class
prepareModel() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!this.cubaProjectModel || !this.cubaProjectModel.project) {
throw new Error('Model is not provided');
}
const { project } = this.cubaProjectModel;
this.model = { project };
this.model.project.restClientId = (_a = project.restClientId) !== null && _a !== void 0 ? _a : 'client';
this.model.project.restClientSecret = project.restClientSecret ? (0, studio_integration_1.normalizeSecret)(project.restClientSecret) : 'secret';
});
}
// noinspection JSUnusedGlobalSymbols - yeoman runs all methods from class
writing() {
this.log(`Generating to ${this.destinationPath()}`);
if (!this.model) {
throw new Error('Model is not provided');
}
this.fs.copyTpl(this.templatePath() + '/**', this.destinationPath(), this.model, undefined, { globOptions: { dot: true } } // copy all files including hidden (will not copy hidden directories)
);
const sdkDest = 'cuba';
this.log(`Generating SDK model and services in ${sdkDest}`);
const sdkOpts = {
model: this.modelFilePath,
dest: sdkDest
};
const generatorOpts = {
Generator: sdk_generator_1.SdkAllGenerator,
path: require.resolve('../../sdk/sdk-generator')
};
this.composeWith(generatorOpts, sdkOpts);
}
end() {
this.log(`CUBA React Native client has been successfully generated into ${this.destinationRoot()}`);
}
}
exports.generator = ReactNativeAppGenerator;
exports.options = cli_options_1.commonGenerationOptionsConfig;
exports.params = [];
//# sourceMappingURL=index.js.map