Create TS typings and bundle with native modules for Node.js; directly publish Ruby and Node.js from workflows
This commit is contained in:
parent
23ccc0d6bc
commit
f484b18b0c
|
@ -6,7 +6,7 @@ on:
|
|||
- 'v*'
|
||||
|
||||
jobs:
|
||||
nodejs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
|
@ -26,10 +26,6 @@ jobs:
|
|||
id: version
|
||||
shell: bash
|
||||
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
|
||||
- name: Get file name
|
||||
id: file
|
||||
shell: bash
|
||||
run: echo ::set-output name=FILE::${{ steps.version.outputs.VERSION }}-${{ matrix.ARCH }}-node${{ matrix.node }}.node
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
|
@ -43,12 +39,37 @@ jobs:
|
|||
- name: Build native module
|
||||
working-directory: ./nodejs
|
||||
run: |
|
||||
npm install -g neon-cli
|
||||
neon build --release
|
||||
npm install
|
||||
node node_modules/neon-cli/bin/cli.js build --release
|
||||
- uses: chrislennon/action-aws-cli@v1.1
|
||||
- name: Upload to S3
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_REGION: us-west-2
|
||||
run: aws s3 cp ./nodejs/native/index.node s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/${{ steps.file.outputs.FILE }}
|
||||
run: aws s3 cp ./nodejs/native/index.node s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/nodejs/${{ steps.version.outputs.VERSION }}/${{ matrix.ARCH }}-node${{ matrix.node }}.node
|
||||
package:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Get version
|
||||
id: version
|
||||
shell: bash
|
||||
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
node-version: 13.x
|
||||
- uses: chrislennon/action-aws-cli@v1.1
|
||||
- name: Download built modules
|
||||
run: |
|
||||
- name: Pack and publish package
|
||||
working-directory: ./nodejs
|
||||
run: |
|
||||
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > "$HOME/.npmrc"
|
||||
rm -rf dist
|
||||
npm install
|
||||
node node_modules/typescript/bin/tsc
|
||||
aws s3 mv s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/nodejs/${{ steps.version.outputs.VERSION }}/ ./dist/. --recursive
|
||||
npm publish
|
||||
|
|
|
@ -74,13 +74,11 @@ jobs:
|
|||
mv "$f.nativelib" "$f"
|
||||
fi
|
||||
done
|
||||
- name: Package gem
|
||||
- name: Package and publish gem
|
||||
working-directory: ./ruby
|
||||
run: gem build hyperbuild.gemspec
|
||||
- uses: chrislennon/action-aws-cli@v1.1
|
||||
- name: Upload to S3
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_REGION: us-west-2
|
||||
run: aws s3 cp ./ruby/hyperbuild-${{ steps.version.outputs.VERSION }}.gem s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/${{ steps.version.outputs.VERSION }}.gem
|
||||
run: |
|
||||
gem build hyperbuild.gemspec
|
||||
echo '---' > "$HOME/.gem/credentials"
|
||||
echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" >> "$HOME/.gem/credentials"
|
||||
chmod 0600 "$HOME/.gem/credentials"
|
||||
gem push hyperbuild-${{ steps.version.outputs.VERSION }}.gem
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
native/target
|
||||
native/index.node
|
||||
native/artifacts.json
|
||||
native/Cargo.lock
|
||||
/dist/*
|
||||
/native/target
|
||||
/native/index.node
|
||||
/native/artifacts.json
|
||||
/native/Cargo.lock
|
||||
node_modules/
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
const childProcess = require('child_process');
|
||||
const fs = require('fs');
|
||||
const pack = require('./package');
|
||||
const path = require('path');
|
||||
const request = require('request');
|
||||
|
||||
console.log(`Installing Node.js hyperbuild ${pack.version}...`);
|
||||
|
||||
const build = () => {
|
||||
console.log(`Building from source...`);
|
||||
const {status, signal, error} = childProcess.spawnSync(`neon`, [`build`, `--release`], {
|
||||
stdio: ['ignore', 'inherit', 'inherit'],
|
||||
encoding: 'utf8',
|
||||
});
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
if (signal) {
|
||||
throw new Error(`Build exited with signal ${signal}`);
|
||||
}
|
||||
if (status !== 0) {
|
||||
throw new Error(`Build exited with status ${status}`);
|
||||
}
|
||||
};
|
||||
|
||||
const binaryPath = path.join(__dirname, "native", "index.node");
|
||||
const binaryName = [
|
||||
pack.version,
|
||||
'-',
|
||||
[process.platform, {
|
||||
darwin: 'macos',
|
||||
linux: 'linux',
|
||||
win32: 'windows',
|
||||
}],
|
||||
'-',
|
||||
[process.arch, {
|
||||
x64: 'x86_64',
|
||||
}],
|
||||
'-node',
|
||||
[process.versions.modules, {
|
||||
// Sourced from https://nodejs.org/en/download/releases/.
|
||||
57: 8,
|
||||
59: 9,
|
||||
64: 10,
|
||||
67: 11,
|
||||
72: 12,
|
||||
79: 13,
|
||||
}],
|
||||
'.node',
|
||||
].map(p => typeof p == 'string'
|
||||
? p
|
||||
: p[1][p[0]]
|
||||
).join('');
|
||||
const binaryUrl = `https://wilsonl.in/hyperbuild/bin/${binaryName}`;
|
||||
|
||||
if (process.env.HYPERBUILD_NODEJS_SKIP_BIN_DOWNLOAD) {
|
||||
console.log(`Skipping download of prebuilt native module binary`);
|
||||
build();
|
||||
} else {
|
||||
console.log(`Fetching ${binaryUrl}...`);
|
||||
request(binaryUrl)
|
||||
.on('response', res => {
|
||||
if (res.statusCode !== 200) {
|
||||
console.error(`Failed to download prebuilt native module with status ${res.statusCode}`);
|
||||
build();
|
||||
}
|
||||
})
|
||||
.on('error', err => {
|
||||
console.error(err);
|
||||
console.error(`Could not download prebuilt native module`);
|
||||
build();
|
||||
})
|
||||
.pipe(fs.createWriteStream(binaryPath));
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
const hyperbuild = require('../native');
|
||||
|
||||
module.exports = {
|
||||
minify: code => {
|
||||
const buf = Buffer.from(code);
|
||||
const len = hyperbuild.minify(buf);
|
||||
return buf.slice(0, len).toString();
|
||||
},
|
||||
minify_in_place: buf => {
|
||||
const len = hyperbuild.minify(buf);
|
||||
// This does not do a copy.
|
||||
return buf.slice(0, len);
|
||||
},
|
||||
};
|
|
@ -2,7 +2,10 @@
|
|||
"name": "hyperbuild",
|
||||
"version": "0.0.25",
|
||||
"description": "Fast one-pass in-place HTML minifier written in Rust with context-aware whitespace handling",
|
||||
"main": "lib/index.js",
|
||||
"main": "dist/index.js",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wilsonzlin/hyperbuild.git"
|
||||
|
@ -20,14 +23,10 @@
|
|||
"url": "https://github.com/wilsonzlin/hyperbuild/issues"
|
||||
},
|
||||
"homepage": "https://github.com/wilsonzlin/hyperbuild#readme",
|
||||
"dependencies": {
|
||||
"devDependencies": {
|
||||
"@types/node": "^13.1.8",
|
||||
"neon-cli": "^0.3.3",
|
||||
"request": "^2.88.0"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node install.js",
|
||||
"prepack": "cp ../README.md .",
|
||||
"postpack": "rm README.md"
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
"keywords": [
|
||||
"build",
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
const binaryName = [
|
||||
[process.platform, {
|
||||
darwin: 'macos',
|
||||
linux: 'linux',
|
||||
win32: 'windows',
|
||||
}],
|
||||
'-',
|
||||
[process.arch, {
|
||||
x64: 'x86_64',
|
||||
}],
|
||||
'-node',
|
||||
[process.versions.modules, {
|
||||
// Sourced from https://nodejs.org/en/download/releases/.
|
||||
57: 8,
|
||||
59: 9,
|
||||
64: 10,
|
||||
67: 11,
|
||||
72: 12,
|
||||
79: 13,
|
||||
}],
|
||||
'.node',
|
||||
].map(p => typeof p == 'string'
|
||||
? p
|
||||
: p[1][p[0] as string]
|
||||
).join('');
|
||||
|
||||
const hyperbuild = require(`./${binaryName}`);
|
||||
|
||||
export const minify = (code: string): string => {
|
||||
const buf = Buffer.from(code);
|
||||
const len = hyperbuild.minify(buf);
|
||||
return buf.slice(0, len).toString();
|
||||
};
|
||||
|
||||
export const minifyInPlace = (buf: Buffer): Buffer => {
|
||||
const len = hyperbuild.minify(buf);
|
||||
// This does not do a copy.
|
||||
return buf.slice(0, len);
|
||||
};
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"allowJs": false,
|
||||
"alwaysStrict": true,
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"es5",
|
||||
"es6",
|
||||
"es7",
|
||||
"es2017"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedParameters": true,
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"target": "es6"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue