-
Notifications
You must be signed in to change notification settings - Fork 46
/
gulpfile.js
104 lines (92 loc) · 2.87 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const del = require('del');
const finc = require('gulp-file-include');
// https://stackoverflow.com/questions/29511491,
// https://gist.github.com/rmckeel/b4e60922f5098ced9c50bdd96731b34a
const spawn = require('child_process').spawn;
const ms = require('merge-stream');
const packageJson = require('./package.json');
const watchDelay = (packageJson.devSettings ? packageJson.devSettings.watchDelay : undefined) || 1000;
gulp.task('br', function (done) {
// console.log('asdfsdf', path.normalize(`${process.cwd()}/`));
// console.log(process.argv[4]);
// console.log(process.cwd());
console.log('process.argv', process.argv);
const snippet = `${path.normalize(process.argv[4])}/`;
const config = JSON.parse(fs.readFileSync(path.join(snippet, 'config.json')));
console.log(snippet);
del.sync('./dist/');
let src = [`${snippet}**/*.js`, `${snippet}**/*.ts`, `${snippet}**/*.html`, `${snippet}appsscript.json`];
let claspConfig = '';
if (!config.type) throw new Error('USER CONFIG ERROR: type requeried');
if (config.type === 'single') claspConfig = `${snippet}.clasp.json`;
else claspConfig = `settings/${config.type}/.clasp.json`;
if (config.src) src = src.concat(config.src);
const dist = gulp
.src(src)
.pipe(
finc({
prefix: '__file',
basepath: '@root',
})
)
.pipe(gulp.dest('./dist'), { base: snippet });
const clcfn = gulp.src(claspConfig).pipe(gulp.dest('./'));
return ms(dist, clcfn);
});
gulp.task('clasp', function (cb) {
cb = cb || console.log;
// const cmd = spawn('./node_modules/.bin/clasp', ['push'], {
const cmd = spawn('npx', ['clasp', 'push'], {
stdio: 'inherit',
});
cmd.on('close', function (code) {
console.log('clasp exited with code ' + code);
cb(code);
});
});
gulp.task('develop', gulp.series('br', 'clasp'));
gulp.task('copy-sheet', function () {
console.log(arg);
// if (arg.name)
return gulp
.src('./templates/sheet_snippet/**/*.*', {
base: './templates/sheet_snippet',
})
.pipe(gulp.dest(`./snippets/sheets/_auto_${arg.name || new Date().getTime()}`));
});
gulp.task(
'watch',
gulp.series('br', 'clasp', function watch() {
gulp.watch(
['./{snippets,extra,shims,drafts,.preliminary}/**/*.{js,gs,json,html}'],
{ delay: watchDelay },
gulp.series('br', 'clasp')
);
})
);
// fetch command line arguments
const arg = ((argList) => {
const arg = {};
let a;
let opt;
let thisOpt;
let curOpt;
for (a = 0; a < argList.length; a++) {
thisOpt = argList[a].trim();
opt = thisOpt.replace(/^-+/, '');
if (opt === thisOpt) {
// argument value
if (curOpt) arg[curOpt] = opt;
curOpt = null;
} else {
// argument name
curOpt = opt;
arg[curOpt] = true;
}
}
return arg;
})(process.argv);