Skip to content

Commit 37664b3

Browse files
committed
feat(core): add babel configuration file
1 parent 2d47112 commit 37664b3

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/config/dependencies.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
export default {
99
devDependencies: {
1010
'@babel/core': '^7.0.0-beta.47',
11+
'@babel/plugin-proposal-object-rest-spread': '^7.0.0-beta.47',
12+
'@babel/preset-env': '^7.0.0-beta.47',
1113
'babel-eslint': '^8.2.3',
1214
'babel-loader': '^8.0.0-beta.3',
1315
'eslint': '^4.19.1',

src/tasks/config.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import { existsAsync } from '../util/functions';
1616

1717
// Custom messages
1818
const STRINGS = {
19-
CONFIG_EXISTS: 'ESLint config file already exists',
20-
COPYING_CONFIG: 'Copying ESLint config file to',
19+
CONFIG_EXISTS: 'Config file already exists',
20+
COPYING_CONFIG: 'Copying config files',
2121
};
2222

2323

2424
// Custom error messages
2525
const ERRORS = {
26-
COPY_FAILED: 'Copying ESLint config file failed',
26+
COPY_FAILED: 'Copying config file failed',
2727
};
2828

2929

@@ -33,27 +33,37 @@ const ERRORS = {
3333
* @param pluginProvider Plugin utilities provider
3434
*/
3535
async function taskFn(done: any, { logger, paths, gulp }: any = {}): Promise<any> {
36-
const configFilename = '.eslintrc';
36+
const configFilenames: string[] = [
37+
'.eslintrc',
38+
'.babelrc',
39+
];
40+
3741
const templateDir: string = path.join(paths.cwd, '/node_modules/@frontvue/plugin-js/template');
3842
const dest: string = path.join(paths.cwd);
3943

4044
// Perform a directory check to avoid overwriting existing files
41-
let isCopied: boolean = false;
45+
let areCopied: boolean[] = [];
4246
try {
43-
isCopied = await existsAsync(path.join(dest, configFilename));
47+
for (const file of configFilenames) {
48+
areCopied = [...areCopied, await existsAsync(path.join(dest, file))];
49+
}
4450
} catch (error) {
4551
return Promise.reject(new Error(`${ERRORS.COPY_FAILED} ${error.message}`));
4652
}
4753

4854
// If the config file are already copied, or folder already exists, exit
49-
if (isCopied) {
55+
if (areCopied.every(item => item)) {
5056
logger.debug(STRINGS.CONFIG_EXISTS);
5157
return Promise.resolve();
5258
}
5359

54-
logger.debug(`${STRINGS.COPYING_CONFIG} ${chalk.cyan.bold(path.join(dest, configFilename))}`);
60+
const configSourcePaths = configFilenames.map(filename => path.join(templateDir, filename));
61+
62+
logger.debug(
63+
`${STRINGS.COPYING_CONFIG} ${chalk.cyan.bold(configFilenames.join(', '))} to ${chalk.cyan.bold(dest)}`,
64+
);
5565
return new Promise((resolve, reject) => {
56-
gulp.src(path.join(templateDir, configFilename), { dot: true })
66+
gulp.src(configSourcePaths, { dot: true })
5767
// Initialize gulp-plumber to prevent process termination in case of error
5868
.pipe(plumber({ errorHandler: error => logger.fatal(error.message) }))
5969
.on('error', (error: any) => {

template/.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
],
5+
"plugins": [
6+
"@babel/plugin-proposal-object-rest-spread"
7+
]
8+
}

0 commit comments

Comments
 (0)