-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
85 lines (74 loc) · 2.53 KB
/
gulpfile.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// tslint:disable:no-imports-matching
import * as del from 'del'; // rm -rf
import * as path from 'path';
// tslint:disable:no-var-requires
const prettier = require('gulp-prettier');
const clean = require('gulp-clean');
import camelcase from 'camelcase';
import * as gulp from 'gulp';
import * as filter from 'gulp-filter';
import * as rename from 'gulp-rename';
import * as template from 'gulp-template';
import gulpTsLint from 'gulp-tslint';
import * as lodash from 'lodash';
import * as tslint from 'tslint';
import * as yargs from 'yargs';
// map of all paths
const paths = {
componentTemplate: path.join(__dirname, 'templates', 'component/**/*.**')
};
const getName = () => yargs.argv.name || yargs.argv.n;
const getRoot = () => yargs.argv.root || yargs.argv.r;
const getCWD = (): string => process.env.INIT_CWD || '';
const getDestinationPath = () => {
const cwd = getCWD();
const name = getName();
const destPath = path.join(cwd, name);
return destPath;
};
gulp.task('clean', () =>
gulp.src(getDestinationPath() + '/**/*.*', { read: false }).pipe(clean())
);
gulp.task(
'component',
gulp.series('clean', () => {
const tsFilter = filter('**/*.ts', { restore: true });
const program = tslint.Linter.createProgram('./tsconfig.json');
const cwd = getCWD();
const name = getName();
const rootModule = getRoot() || 'llpoc';
const appPrefix = 'llpoc';
const destPath = getDestinationPath();
return (
gulp
.src(paths.componentTemplate)
.pipe(
template(
{
appPrefix: appPrefix,
rootModule: rootModule,
lowerName: camelcase(name),
upperName: camelcase(name, { pascalCase: true }),
kebabName: name
},
{}
)
)
.pipe(
rename(dest => {
dest.basename = dest.basename!.replace('temp', name);
})
)
// .pipe(tsFilter)
// .pipe(
// gulpTsLint({
// configuration: './tslint.json',
// fix: true,
// program: program
// })
// )
// .pipe(prettier())
.pipe(gulp.dest(destPath))
);
})
);