@onereach/orest-input-cli
Version:
The tool for creating, serving, and publishing OREST Inputs
93 lines (77 loc) • 2.06 kB
JavaScript
const Generator = require('yeoman-generator');
const _ = require('lodash');
const path = require('path');
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
const providedDestinationRoot = _.get(this.options, 'destinationRoot', '');
this.isNewInput = !!providedDestinationRoot;
this.destination = path.resolve(providedDestinationRoot);
this.destinationRoot(this.destination);
}
get _testScripts() {
return {
scripts: {
test: 'jest --onlyChanged',
'test:watch': 'jest --watchAll',
'test:coverage': 'jest --coverage',
},
};
}
get _babelDependencies() {
return {
'@babel/core': '7.20.12',
'@babel/preset-env': '7.20.2',
'@babel/plugin-transform-modules-commonjs': '7.21.2',
};
}
get _jestDependencies() {
return {
'@jest/globals': '29.5.0',
'babel-jest': '29.5.0',
jest: '29.5.0',
'jest-environment-jsdom': '29.5.0',
'jest-transform-stub': '2.0.0',
'@onereach/orest-jest-presets': '0.0.2',
};
}
get _vueTestUtilsDependencies() {
return {
'@vue/vue2-jest': '29.2.2',
'@vue/test-utils': '1.3.3',
};
}
writing() {
const pkgJson = {
...this._testScripts,
devDependencies: {
...this._jestDependencies,
...this._babelDependencies,
...this._vueTestUtilsDependencies,
},
};
this.fs.extendJSON(this.destinationPath('package.json'), pkgJson);
this._writingTest();
}
_writingTest() {
this.fs.copy(
this.templatePath('_jest.config.js'),
this.destinationPath('jest.config.js')
);
this.fs.copy(
this.templatePath('_babel.config.js'),
this.destinationPath('babel.config.js')
);
if (this.isNewInput) {
this.fs.copy(
this.templatePath('new-input/**'),
this.destinationPath('test')
);
} else {
this.fs.copy(
this.templatePath('minimal/**'),
this.destinationPath('test')
);
}
}
};