Skip to content

Commit 891413f

Browse files
committed
chore: Compress linux-command.docset. #91
1 parent 5aa2287 commit 891413f

File tree

3 files changed

+343
-2
lines changed

3 files changed

+343
-2
lines changed

build/dash.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const fs = require('fs-extra');
2-
const { resolve: pathResolve } = require('path');
3-
const pkg = require('../package.json');
2+
const { resolve: pathResolve, join: pathJoin } = require('path');
43
const sqlite3 = require('sqlite3');
4+
const archiver = require('archiver');
5+
const pkg = require('../package.json');
56

67
const DATA_DIR = pathResolve(__dirname, '../assets/');
78
const INDEX_JSON_PATH = pathResolve(__dirname, '../dist/data.json');
@@ -97,6 +98,46 @@ async function buildApi(dbPath) {
9798
await createDatabase(arr, dbPath);
9899
}
99100

101+
function compressing() {
102+
new Promise((resolve, reject) => {
103+
const outputPaht = pathJoin(process.cwd(), '.deploy', 'linux-command.docset.zip');
104+
// create a file to stream archive data to.
105+
const output = fs.createWriteStream(outputPaht);
106+
const archive = archiver('zip', {
107+
zlib: { level: 9 } // Sets the compression level.
108+
});
109+
110+
// listen for all archive data to be written
111+
// 'close' event is fired only when a file descriptor is involved
112+
output.on('close', () => {
113+
console.log(archive.pointer() + ' total bytes');
114+
console.log('archiver has been finalized and the output file descriptor has closed.');
115+
resolve();
116+
});
117+
118+
// good practice to catch warnings (ie stat failures and other non-blocking errors)
119+
archive.on('warning', (err) => {
120+
if (err.code === 'ENOENT') {
121+
console.log('warning:::', err)
122+
// log warning
123+
} else {
124+
// throw error
125+
throw err;
126+
}
127+
});
128+
129+
// good practice to catch this error explicitly
130+
archive.on('error', function(err) {
131+
reject(err);
132+
});
133+
134+
// pipe archive data to the file
135+
archive.pipe(output);
136+
archive.directory(pathJoin(process.cwd(), '.deploy', 'linux-command.docset'), false);
137+
archive.finalize();
138+
})
139+
}
140+
100141
async function build() {
101142
console.log(`mkdir -p ${RESOURCES_DIR}`);
102143
await clean();
@@ -107,6 +148,9 @@ async function build() {
107148

108149
console.info('build documents');
109150
await buildApi(DB_PATH);
151+
152+
console.info('compressing zip');
153+
await compressing();
110154
}
111155

112156
build()

0 commit comments

Comments
 (0)