-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
127 lines (104 loc) · 3.86 KB
/
gulpfile.js
File metadata and controls
127 lines (104 loc) · 3.86 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"use strict";
const gulp = require("gulp");
const packagedef = require("./package.json");
const replace = require('gulp-replace');
const path = require("path");
const fs = require("fs");
async function CleanDistFolder() {
console.log("Cleaning dist folder...");
const del = await import('del');
return del.deleteAsync(['./dist/*']);
}
/**
* Build distribution files using webpack config
*/
function BuildWithWebpack(done) {
const { exec } = require('child_process');
console.log("Building distribution files with webpack...");
exec('npx webpack --config ./configs/webpack.config.js', (err, stdout, stderr) => {
if (err) {
console.error(stderr);
return done(err);
}
console.log(stdout);
done();
});
}
//////////////////////////////////////
//// Build documentation site from js content using jsdoc
//// remove previous output
async function CleanDocsFolder() {
console.log("Cleaning docs folder...");
const del = await import('del');
return del.deleteAsync(['./docs/*']);
}
// extract docs and compile to html, adds in readme.md from docs-src
function CompileDocs(done) {
const { exec } = require('child_process');
console.log("Building documentation.");
exec('npx jsdoc -c ./configs/jsdoc.json', (err, stdout, stderr) => {
if (err) {
console.error(stderr);
return done(err);
}
console.log(stdout);
done();
});
}
// static docs files that jsdocs won't put where we want
function CopyDocStatics() {
return gulp.src('./docs-src/configs/**').pipe(gulp.dest('./docs/configs/'));
}
/**
* Helper function to get all files with a specific extension from a directory
*/
function getAllFiles(dir, ext) {
let files = [];
const items = fs.readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory()) {
files = files.concat(getAllFiles(fullPath, ext));
} else if (item.isFile() && path.extname(item.name) === ext) {
files.push(fullPath);
}
}
return files;
}
/**
* Process namespace strings in documentation files (to put dot delimeters back into names)
*/
function ProcessNamespacesAndVersion(cb) {
const namespaces = [
"MeadCo.ScriptX.Print.Licensing",
"MeadCo.ScriptX.Print.HTML",
"MeadCo.ScriptX.Print.PDF",
"MeadCo.ScriptX.Print"
];
console.log("Processing namespace strings in documentation files...");
try {
// Get all HTML files in docs directory
const docFiles = getAllFiles('./docs', '.html');
// Process each namespace in each file
for (const file of docFiles) {
let content = fs.readFileSync(file, 'utf8');
for (const namespace of namespaces) {
const badName = namespace.replace(/\./g, "");
const regex = new RegExp(badName + "(?![a-zA-Z]*\.html|[a-zA-Z]*\")", "gi");
content = content.replace(regex, namespace);
}
content = content.replace(/{@packageversion}/g, packagedef.version);
// Remove the footer element and its content (the generated date etc.)
content = content.replace(/<footer[\s\S]*?<\/footer>/gi, '');
fs.writeFileSync(file, content, 'utf8');
}
console.log('Namespace processing completed');
cb();
} catch (err) {
cb(err);
}
}
exports.Clean = gulp.parallel(CleanDistFolder, CleanDocsFolder);
exports.BuildDocs = gulp.series(CleanDocsFolder, gulp.series(CompileDocs, ProcessNamespacesAndVersion, CopyDocStatics));
exports.BuildDist = gulp.series(CleanDistFolder, BuildWithWebpack);
exports.Dist = gulp.series(exports.Clean, gulp.parallel(gulp.series(CompileDocs, ProcessNamespacesAndVersion, CopyDocStatics), BuildWithWebpack));