Skip to content

Instantly share code, notes, and snippets.

@anvilation
Last active August 30, 2021 12:20
Show Gist options
  • Save anvilation/a023885323c3e4c8d88bd87be9df1d70 to your computer and use it in GitHub Desktop.
Save anvilation/a023885323c3e4c8d88bd87be9df1d70 to your computer and use it in GitHub Desktop.
Smart UI CI / CD - Re-written Yeoman Smart UI Module Generator
const chalk = require('chalk');
const superb = require('superb');
const yosay = require('yosay');
const _ = require('../shared/lodash-complete');
const Generator = require('yeoman-generator');
-_.extend(Generator.prototype, require('yeoman-generator/lib/actions/install'));
const promptDefaults = {
"projectName": "driverlane",
"projectDescription": "driverlane e2e test module",
"modulePrefix": "drive"
}
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
this.properties = {};
this.option('secret-sauce', {
'default': false
});
this.option('skip-install', {
desc: 'Skips the "npm install" command after generating the project.',
type: Boolean,
'default': false
});
}
async prompting() {
this.log(yosay(`Welcome to the ${superb.random()} ${chalk.red('CS UI Extension')} generator!`));
let projectName;
if (this.options['secret-sauce']) {
this.properties = promptDefaults
} else {
this.properties = await this.prompt([
{
type: "input",
name: "projectName",
message: 'CS module name:',
default: 'greetings',
filter: function (value) {
projectName = value;
return _.computerize(value);
}
},
{
type: 'input',
name: 'projectDescription',
message: 'CS module description:',
default: 'CS UI greetings extension module'
},
{
type: 'input',
name: 'modulePrefix',
message: 'RequireJS module prefix:',
default: () => {
return _.computerize(projectName).substring(0, 5);
},
filter: (value) => {
return _.computerize(value);
}
}
]);
}
this.projectName = this.properties.projectName;
}
configuring() {
this.config.set(this.properties)
}
writing() {
this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'),
{
projectName: this.properties.projectName,
projectDescription: this.properties.projectDescription
});
// Project Files
this.fs.copy(this.templatePath('jshintrc'), this.destinationPath('.jshintrc'));
this.fs.copy(this.templatePath('jshintrc-html'), this.destinationPath('.jshintrc-html'));
this.fs.copy(this.templatePath('eslintrc'), this.destinationPath('.eslintrc'));
this.fs.copy(this.templatePath('csslintrc'), this.destinationPath('.csslintrc'));
this.fs.copy(this.templatePath('csslintrc-output'), this.destinationPath('.csslintrc-output'));
this.fs.copy(this.templatePath('Gruntfile.js'), this.destinationPath('Gruntfile.js'));
this.fs.copy(this.templatePath('README.md'), this.destinationPath('README.md'));
this.fs.copy(this.templatePath('Gruntfile.js'), this.destinationPath('Gruntfile.js'));
this.fs.copy(this.templatePath('config-editor.js'), this.destinationPath('config-editor.js'));
this.fs.copy(this.templatePath('server.js'), this.destinationPath('server.js'));
// Lib Files
this.fs.copy(this.templatePath('lib'), this.destinationPath('lib'));
// src Files
this.fs.copy(this.templatePath('src/Gruntfile.js'), this.destinationPath('src/Gruntfile.js'));
this.fs.copy(this.templatePath('src/config-build.js'), this.destinationPath('src/config-build.js'));
this.fs.copy(this.templatePath('src/component.js'), this.destinationPath('src/component.js'));
this.fs.copy(this.templatePath('src/bundle-extensions.json'), this.destinationPath(`src/${this.properties.modulePrefix}-extensions.json`));
this.fs.copy(this.templatePath('src/bundles/bundle-all.js'), this.destinationPath(`src/bundles/${this.properties.modulePrefix}-all.js`));
this.fs.copy(this.templatePath('src/test/extensions.spec.js'), this.destinationPath(`src/test/extensions.spec.js`));
// srcModuleFiles
this.fs.copy(this.templatePath('srcmodules/module/module.ini'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName}.ini`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/Configure.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/Configure.os`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/CSUIExtension.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/CSUIExtension.os`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/MODULEGlobals.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/MODULEGlobals.os`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/MODULERequestHandlerGroup.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/MODULERequestHandlerGroup.os`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/MODULERoot.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/MODULERoot.os`));
this.fs.copy(this.templatePath('srcmodules/module/MODULE/MODULEWebModule.os'), this.destinationPath(`srcmodules/${this.projectName}/${this.projectName.toUpperCase()}/MODULEWebModule.os`));
// testFiles
this.fs.copy(this.templatePath('test/Gruntfile.js'), this.destinationPath(`test/Gruntfile.js`));
this.fs.copy(this.templatePath('test/test-common.js'), this.destinationPath(`test/test-common.js`));
this.fs.copy(this.templatePath('test/test-debug.js'), this.destinationPath(`test/test-debug.js`));
this.fs.copy(this.templatePath('test/test-release.js'), this.destinationPath(`test/test-release.js`));
this.fs.copy(this.templatePath('test/karma.common.js'), this.destinationPath(`test/karma.common.js`));
this.fs.copy(this.templatePath('test/karma.debug.js'), this.destinationPath(`test/karma.debug.js`));
this.fs.copy(this.templatePath('test/karma.release.js'), this.destinationPath(`test/karma.release.js`));
}
install() {
if (!this.options['skip-install']) {
return;
}
this.installDependencies({
bower: false,
npm: true
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment