-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgulpfile.js
More file actions
169 lines (145 loc) · 4.54 KB
/
Copy pathgulpfile.js
File metadata and controls
169 lines (145 loc) · 4.54 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* SPDX LGPL-2.1-or-later
* Copyright (C) 2014 The eXist-db Authors
*/
import { src, dest, series, parallel, watch as gulpWatch } from "gulp";
import { createClient, readOptionsFromEnv } from "@existdb/gulp-exist";
import replace from "@existdb/gulp-replace-tmpl";
import rename from "gulp-rename";
import zip from "gulp-zip";
import header from "gulp-header";
import sourcemaps from "gulp-sourcemaps";
import gulpSass from "gulp-sass";
import * as dartSass from "sass";
import cssnano from "gulp-cssnano";
import svgmin from "gulp-svgmin";
import del from "delete";
import { readFileSync } from "node:fs";
const sass = gulpSass(dartSass);
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
const { version, license, app } = packageJson;
const replacements = [app, { version, license }];
const defaultOptions = { basic_auth: { user: "admin", pass: "" } };
const connectionOptions = Object.assign(defaultOptions, readOptionsFromEnv());
let existClient;
try {
existClient = createClient(connectionOptions);
} catch (e) {
// client creation may fail if server is not available; OK for build-only usage
}
const packageFilename = `exist-function-documentation-${version}.xar`;
const paths = {
input: "src/main/xar-resources",
staging: ".build",
output: "dist",
styles: {
input: "src/main/frontend/sass/*",
output: ".build/resources/css",
},
svgs: {
input: "src/main/frontend/svg/*.svg",
output: ".build/resources/images",
},
vendor: {
scripts: [
"node_modules/bootstrap/dist/js/bootstrap.min.*",
"node_modules/@popperjs/core/dist/umd/popper.min.*",
"node_modules/@highlightjs/cdn-assets/highlight.min.js",
"node_modules/@highlightjs/cdn-assets/languages/xquery.min.js",
"node_modules/zero-md/dist/index.min.js",
],
styles: [
"node_modules/bootstrap/dist/css/bootstrap.min.*",
"node_modules/@highlightjs/cdn-assets/styles/atom-one-dark.min.css",
"node_modules/@neos21/bootstrap3-glyphicons/dist/css/*",
],
fonts: ["node_modules/@neos21/bootstrap3-glyphicons/dist/fonts/*"],
},
};
const banner = {
min:
"/*!" +
` ${packageJson.name} v${version}` +
" | (c) " +
new Date().getFullYear() +
` ${packageJson.author}` +
` | ${license} License` +
` | ${packageJson.repository.url}` +
" */\n",
};
function clean(cb) {
del([paths.staging, paths.output], cb);
}
export { clean };
function copyXarResources() {
return src(`${paths.input}/**/*`, { encoding: false }).pipe(
dest(paths.staging),
);
}
function copyProjectFiles() {
return src(["README.md", "LICENSE"], {
allowEmpty: true,
encoding: false,
}).pipe(dest(paths.staging));
}
function templates() {
return src("*.tmpl")
.pipe(replace(replacements, { unprefixed: true }))
.pipe(
rename((path) => {
path.extname = "";
}),
)
.pipe(dest(paths.staging));
}
async function buildStyles() {
const { default: prefix } = await import("gulp-autoprefixer");
return src(paths.styles.input)
.pipe(sourcemaps.init())
.pipe(sass.sync({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(prefix({ cascade: true }))
.pipe(rename({ suffix: ".min" }))
.pipe(cssnano({ discardComments: { removeAll: true } }))
.pipe(header(banner.min))
.pipe(sourcemaps.write("."))
.pipe(dest(paths.styles.output));
}
function buildSvgs() {
return src(paths.svgs.input).pipe(svgmin()).pipe(dest(paths.svgs.output));
}
function copyVendorScripts() {
return src(paths.vendor.scripts).pipe(
dest(`${paths.staging}/resources/scripts`),
);
}
function copyVendorStyles() {
return src(paths.vendor.styles).pipe(dest(`${paths.staging}/resources/css`));
}
function copyVendorFonts() {
return src(paths.vendor.fonts, { encoding: false }).pipe(
dest(`${paths.staging}/resources/fonts`),
);
}
const copyStatic = parallel(copyVendorFonts, copyVendorScripts, copyVendorStyles);
function createXar() {
return src(`${paths.staging}/**/*`, { encoding: false, base: paths.staging })
.pipe(zip(packageFilename))
.pipe(dest(paths.output));
}
function deployXar() {
return src(`${paths.output}/${packageFilename}`, { encoding: false }).pipe(
existClient.install({ packageUri: app.namespace }),
);
}
const build = series(
clean,
parallel(copyXarResources, copyProjectFiles),
parallel(buildStyles, buildSvgs, copyStatic),
templates,
createXar,
);
const install = series(build, deployXar);
export { build, install };
export default series(build, deployXar, function watchTask() {
gulpWatch(`${paths.input}/**/*`, build);
});