UNPKG

generator-pyhipster

Version:

Python (Flask) + Angular/React/Vue in one handy generator

166 lines (150 loc) 5.3 kB
/** * Copyright 2013-2022 the original author or authors from the JHipster project. * * This file is part of the JHipster project, see https://www.jhipster.tech/ * for more information. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const chalk = require('chalk'); const os = require('os'); const shelljs = require('shelljs'); const BaseGenerator = require('../generator-base'); const { INITIALIZING_PRIORITY } = require('../../lib/constants/priorities.cjs').compat; // We use console.log() in this generator because we want to print on stdout not on // stderr unlike yeoman's log() so that user can easily redirect output to a file. /* eslint-disable no-console */ module.exports = class extends BaseGenerator { constructor(args, options, features) { super(args, options, { unique: 'namespace', ...features }); this.option('skipCommit', { desc: 'Skip commit', type: Boolean, hide: true, defaults: true, }); if (this.options.help) return; this.env.options.skipInstall = true; } get [INITIALIZING_PRIORITY]() { return { sayHello() { this.log(chalk.white('Welcome to the PyHipster Information Sub-Generator\n')); }, checkJHipster() { const done = this.async(); console.log('##### **PyHipster Version(s)**'); shelljs.exec('npm list generator-pyhipster', { silent: true }, (err, stdout, stderr) => { if (stdout) { console.log(`\n\`\`\`\n${stdout}\`\`\`\n`); } done(); }); }, displayConfiguration() { const done = this.async(); let result = shelljs.cat('.yo-rc.json'); result = result.replace( /"rememberMeKey": ".*"/g, '"rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByThePyHipsterInfoCommandForObviousSecurityReasons"' ); result = result.replace( /"jwtSecretKey": ".*"/g, '"jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByThePyHipsterInfoCommandForObviousSecurityReasons"' ); console.log('\n##### **PyHipster configuration, a `.yo-rc.json` file generated in the root folder**\n'); console.log(`\n<details>\n<summary>.yo-rc.json file</summary>\n<pre>\n${result}\n</pre>\n</details>\n`); done(); }, displayEntities() { const done = this.async(); console.log('\n##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.pyhipster` directory**\n'); const jdl = this.generateJDLFromEntities(); console.log('<details>\n<summary>JDL entity definitions</summary>\n'); console.log(`<pre>\n${jdl.toString()}\n</pre>\n</details>\n`); done(); }, checkJava() { const done = this.async(); console.log('\n##### **Environment and Tools**\n'); shelljs.exec('java -version', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(stderr); } done(); }); }, checkPython() { const done = this.async(); var pythonCommand = ''; if (os.platform() === 'win32') { pythonCommand = 'python --version'; } else { pythonCommand = 'python3 --version'; } shelljs.exec(pythonCommand, { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(stdout); } done(); }); }, checkGit() { const done = this.async(); shelljs.exec('git version', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(stdout); } done(); }); }, checkNode() { const done = this.async(); shelljs.exec('node -v', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(`node: ${stdout}`); } done(); }); }, checkNpm() { const done = this.async(); shelljs.exec('npm -v', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(`npm: ${stdout}`); } done(); }); }, checkDocker() { const done = this.async(); shelljs.exec('docker -v', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(stdout); } done(); }); }, checkDockerCompose() { const done = this.async(); shelljs.exec('docker-compose -v', { silent: true }, (err, stdout, stderr) => { if (!err) { console.log(stdout); } done(); }); }, }; } }; /* eslint-enable no-console */