This repository has been archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
78 lines (59 loc) · 2.38 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
const gulp = require('gulp');
const globby = require('globby');
const path = require('path');
const fs = require('fs');
const index = require('create-index');
const shelljs = require('shelljs');
// gulp.task('compile', () => {
// shelljs.exec('yarn run build');
// });
gulp.task('create-index', (done) => {
console.log('Creating indexing files ...');
globby(['engine/**/', '!engine/'], {}).then((matches) => {
matches.map((dir) => {
globby([dir + '*.ts'], {}).then((files) => {
generateExports(files, dir, false);
});
})
});
globby(['engine/**/', '!engine/'], {}).then((matches) => {
generateExports(matches, 'engine', true);
});
});
// gulp.task('publish', ['create-index', 'compile'], () => {
// console.log(`Patching new version ...`);
// shelljs.exec('npm version patch --force');
// console.log(`Writing publish package.json ...`);
// const package = fs.readFileSync('./package.json');
// const packageConfig = JSON.parse(package);
// const distPackageConfig = {};
// distPackageConfig.name = packageConfig.name;
// distPackageConfig.version = packageConfig.version;
// distPackageConfig.author = packageConfig.author;
// distPackageConfig.license = packageConfig.license;
// distPackageConfig.repository = packageConfig.repository;
// distPackageConfig.dependencies = packageConfig.dependencies;
// distPackageConfig.main = './engine/index.js';
// fs.writeFileSync('dist/package.json', JSON.stringify(distPackageConfig, null, 2));
// shelljs.exec('cp README.md dist/');
// shelljs.exec('cd dist && npm publish');
// });
function generateExports(files, saveDir, isDir = false) {
let exportData = '';
files.map((file) => {
let parsedData = path.parse(file);
let filename = '';
if (isDir) {
let dir = parsedData.dir.replace(saveDir + '/', '') || dir;
dir = dir.replace(saveDir, '') || '';
filename = path.join(dir, parsedData.name) + parsedData.ext;
} else {
filename = parsedData.name;
}
if (parsedData.base !== 'index.ts') {
exportData += `export * from './${filename}';\n`;
}
})
let fullData = `//@ Auto-Generated indexing files for avg.engine\n\n${exportData}`;
fs.writeFileSync(path.join(saveDir, 'index.ts'), fullData);
}