-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbuild.js
More file actions
36 lines (27 loc) · 1.49 KB
/
Copy pathbuild.js
File metadata and controls
36 lines (27 loc) · 1.49 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
'use strict';
const { transformFileSync } = require('@babel/core');
const { minify } = require('terser');
const { writeFileSync, rmSync, mkdirSync, copyFileSync, readFileSync } = require('fs');
const pkg = require('./package.json');
async function build() {
const year = new Date().getFullYear();
const banner = `/*! checkboxes.js v${pkg.version} | (c) 2013-${year} Rubens Mariuzzo | http://github.com/rmariuzzo/checkboxes.js/LICENSE */`;
rmSync('dist', { recursive: true, force: true });
mkdirSync('dist');
const { code } = transformFileSync('src/jquery.checkboxes.js');
writeFileSync(`dist/jquery.checkboxes-${pkg.version}.js`, `${banner}\n${code}`);
const { code: minCode } = await minify(code, { format: { preamble: banner } });
writeFileSync(`dist/jquery.checkboxes-${pkg.version}.min.js`, minCode);
console.log(`Built dist/jquery.checkboxes-${pkg.version}.js`);
console.log(`Built dist/jquery.checkboxes-${pkg.version}.min.js`);
copyFileSync(`dist/jquery.checkboxes-${pkg.version}.min.js`, 'docs/bundle/checkboxes.js/jquery.checkboxes.min.js');
console.log(`Updated docs/bundle/checkboxes.js/jquery.checkboxes.min.js`);
const html = readFileSync('docs/index.html', 'utf-8');
const updatedHtml = html.replace(/Download v[\d.]+/g, `Download v${pkg.version}`);
writeFileSync('docs/index.html', updatedHtml);
console.log(`Updated docs/index.html → Download v${pkg.version}`);
}
build().catch((err) => {
console.error(err);
process.exit(1);
});