forked from pymedusa/Medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (60 loc) · 1.9 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const workDir = process.cwd();
const pathToFolder = path.join(workDir, 'themes-default');
const execa = require('execa');
const getStream = require('get-stream');
const xo = require('gulp-xo');
const build = done => {
// Place code for your default task here
done();
};
const getFolders = dir => {
return fs.readdirSync(dir)
.filter(function(file) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
};
const lintTheme = theme => {
console.log(`Starting lint of ${theme}`);
console.log(`Working dir: ${process.cwd()}`);
const stream = execa('yarn', [], {cwd: theme}).stdout;
stream.pipe(process.stdout);
return getStream(stream).then(value => {
console.log('child output:', value);
})
.catch(err => {
console.log(`Lint errored for theme ${theme} with error:\n${err.toString()}`);
process.exit(err.code);
});
};
/**
* Run all js files through the xo (eslint) linter.
* FIXME: This apparently doesn't work properly. It is verry slow.
* Running the linter on the subdirectories using execa is much faster.
*/
const lint = () => {
return gulp
.src([
'themes-default/*/static/js/**/*.js',
'!themes-default/*/static/js/lib/**',
'!themes-default/*/static/js/*.min.js',
'!themes-default/*/static/js/vender.js',
'!node_modules/**'
])
.pipe(xo())
.pipe(xo.format())
.pipe(xo.failAfterError());
};
gulp.task('default', ['lint']);
gulp.task('build', build);
gulp.task('lintthemes', () => {
const folders = getFolders(pathToFolder);
return Promise.all(folders.map(folder => {
const fullPath = path.join(pathToFolder, folder);
return lintTheme(fullPath);
}));
});
gulp.task('lint', lint);