Skip to content

Commit

Permalink
chore: Compress linux-command.docset. #91
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 17, 2020
1 parent 5aa2287 commit 891413f
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 2 deletions.
48 changes: 46 additions & 2 deletions build/dash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require('fs-extra');
const { resolve: pathResolve } = require('path');
const pkg = require('../package.json');
const { resolve: pathResolve, join: pathJoin } = require('path');
const sqlite3 = require('sqlite3');
const archiver = require('archiver');
const pkg = require('../package.json');

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

function compressing() {
new Promise((resolve, reject) => {
const outputPaht = pathJoin(process.cwd(), '.deploy', 'linux-command.docset.zip');
// create a file to stream archive data to.
const output = fs.createWriteStream(outputPaht);
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', () => {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
resolve();
});

// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.log('warning:::', err)
// log warning
} else {
// throw error
throw err;
}
});

// good practice to catch this error explicitly
archive.on('error', function(err) {
reject(err);
});

// pipe archive data to the file
archive.pipe(output);
archive.directory(pathJoin(process.cwd(), '.deploy', 'linux-command.docset'), false);
archive.finalize();
})
}

async function build() {
console.log(`mkdir -p ${RESOURCES_DIR}`);
await clean();
Expand All @@ -107,6 +148,9 @@ async function build() {

console.info('build documents');
await buildApi(DB_PATH);

console.info('compressing zip');
await compressing();
}

build()
Expand Down
Loading

0 comments on commit 891413f

Please sign in to comment.