From f75d1cb0947f6b4fe629104c9369148901c324b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A4=E5=9F=8E=E8=90=BD=E5=AF=9E?= Date: Tue, 30 Aug 2022 16:26:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20zip=20=E5=8F=98=E6=9B=B4=20tgz,=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20dash=20feed=20(#411)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 41 +++++++++++++++----------------- package.json | 2 +- scripts/dash.mjs | 50 +++++++--------------------------------- 3 files changed, 28 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0500ca3ee7f..32e7413ed4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,26 +13,18 @@ jobs: with: node-version: 16 - - run: npm -v - - run: node -v - - run: npm install - - run: npm run build - - run: npm run dash - - - name: Compress linux-command.docset. - run: zip -r -y linux-command.docset.zip . -x "node_modules/*" - working-directory: .deploy/linux-command.docset - - run: cp -rp .deploy/linux-command.docset/linux-command.docset.zip ./ - - - run: rm -rf .deploy/linux-command.docset - - name: Generate Contributors Images uses: jaywcjlove/github-action-contributors@main with: filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\]) avatarSize: 42 - - run: cp CONTRIBUTORS.svg .deploy + - name: Build Linux Command + run: | + npm install + npm run dash + cp CONTRIBUTORS.svg .deploy + rm -rf .deploy/linux-command.docset - name: Create Tag id: create_tag @@ -40,10 +32,14 @@ jobs: with: package-path: ./package.json - - name: get tag version + - name: Get Tag Version id: tag_version uses: jaywcjlove/changelog-generator@v1.5.3 + - name: Update Dash Feed + run: | + echo "${{steps.create_tag.outputs.versionNumber}}https://jaywcjlove.github.io/linux-command/linux-command.docset.tgz" > .deploy/linux-command-docset.xml + - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: @@ -64,7 +60,7 @@ jobs: uses: ncipollo/release-action@v1 if: steps.create_tag.outputs.successful with: - artifacts: 'linux-command.docset.zip' + artifacts: 'linux-command.docset.tgz' token: ${{ secrets.GITHUB_TOKEN }} name: ${{ steps.create_tag.outputs.version }} tag: ${{ steps.create_tag.outputs.version }} @@ -106,18 +102,19 @@ jobs: http://localhost:9665/ ``` - - - run: npm install @jsdevtools/npm-publish -g - - run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json - - - run: rm -rf .deploy/linux-command.docset.zip + - name: Push Npm + run: | + npm install @jsdevtools/npm-publish -g + npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json # Create Docker Image - name: Docker login run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }} - name: Build linux-command image - run: docker image build -t linux-command . + run: | + rm -rf .deploy/linux-command.docset.tgz + docker image build -t linux-command . - name: Tags & Push image(latest) run: | diff --git a/package.json b/package.json index 22bd6056ab8..fba5fe4949c 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,9 @@ "devDependencies": { "@uiw/github-corners": "~1.5.11", "@wcj/dark-mode": "~1.0.14", - "archiver": "~5.3.0", "colors-cli": "~1.0.28", "ejs": "~3.1.6", + "compressing": "^1.6.2", "fs-extra": "~10.1.0", "markdown-to-html-cli": "~3.4.1", "sitemap-generator": "~8.5.1", diff --git a/scripts/dash.mjs b/scripts/dash.mjs index ab6c197d9c5..5c41ec183f5 100644 --- a/scripts/dash.mjs +++ b/scripts/dash.mjs @@ -2,7 +2,8 @@ import fs from 'fs-extra'; import path from 'path'; import { resolve as pathResolve, join as pathJoin } from 'path'; import sqlite3 from 'sqlite3'; -import archiver from 'archiver'; +import {tgz} from 'compressing'; +import { spawn } from 'child_process'; import {fileURLToPath} from 'url'; const __filename = fileURLToPath(import.meta.url); @@ -103,45 +104,6 @@ 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}`); @@ -154,8 +116,12 @@ async function build() { console.info('build documents'); await buildApi(DB_PATH); - console.info('compressing zip'); - await compressing(); + console.info('compressing tgz'); + // https://github.com/node-modules/compressing/issues/42 建议最好休眠15s,等待其余资源复制完毕 + spawn("sleep", ['15']) + const tgzPath = pathJoin(process.cwd(), '.deploy', 'linux-command.docset'); + const outputPath = pathJoin(process.cwd(), '.deploy', 'linux-command.docset.tgz'); + await tgz.compressDir(tgzPath, outputPath); } build()