feat: add micro-packed and scure-btc-signer

This commit is contained in:
Zitao Xiong
2023-09-01 19:17:09 +08:00
commit 16c9a18f8f
7 changed files with 216 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
on:
workflow_dispatch:
inputs:
package_version:
description: 'Package version to be published to NPM. Defaults to current version of micro-packed.'
required: false
dist_tag:
description: 'What dist tag should be used for publishing (e.g. `next` vs `latest`). Defaults to `next`.'
required: true
default: next
name: Publish Micro Packed
jobs:
prebuild-node:
name: Publish package to npm
runs-on: ubuntu-latest
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: 16
- uses: actions/checkout@v2
# We're changing micro-packed package.json here and republishing it as a CommonJS module under the name micro-packed-cjs.
- name: Build CommonJS
run: |
yarn install
node build-micro-packed.mjs
# Version is set manually, because sometimes (when we make a mistake) we might need to release
# new versions for the same version of micro-packed-cjs. major.minor should be kept. e.g. micro-packed@12.0.0
# can be occasionally released as micro-packed-cjs 12.0.1 but not 12.1.0.
- name: Set version if provided
if: ${{ github.event.inputs.package_version != null }}
run: >
jq '.version = "${{github.event.inputs.package_version}}"' micro-packed/package.json > micro-packed/temp-package.json
&& rm micro-packed/package.json && mv micro-packed/temp-package.json micro-packed/package.json
- uses: JS-DevTools/npm-publish@v1
with:
package: "./micro-packed/package.json"
token: ${{ secrets.NPM_TOKEN }}
access: "public"
dry-run: false
tag: ${{ github.event.inputs.dist_tag }}

View File

@@ -0,0 +1,47 @@
on:
workflow_dispatch:
inputs:
package_version:
description: 'Package version to be published to NPM. Defaults to current version of scure-btc-signer.'
required: false
dist_tag:
description: 'What dist tag should be used for publishing (e.g. `next` vs `latest`). Defaults to `next`.'
required: true
default: next
name: Publish Scure Btc Signer
jobs:
prebuild-node:
name: Publish package to npm
runs-on: ubuntu-latest
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: 16
- uses: actions/checkout@v2
# We're changing scure-btc-signer package.json here and republishing it as a CommonJS module under the name scure-btc-signer-cjs.
- name: Build CommonJS
run: |
yarn install
node build-scure-btc-signer.mjs
# Version is set manually, because sometimes (when we make a mistake) we might need to release
# new versions for the same version of scure-btc-signer-cjs. major.minor should be kept. e.g. scure-btc-signer@12.0.0
# can be occasionally released as scure-btc-signer-cjs 12.0.1 but not 12.1.0.
- name: Set version if provided
if: ${{ github.event.inputs.package_version != null }}
run: >
jq '.version = "${{github.event.inputs.package_version}}"' scure-btc-signer/package.json > scure-btc-signer/temp-package.json
&& rm scure-btc-signer/package.json && mv scure-btc-signer/temp-package.json scure-btc-signer/package.json
- uses: JS-DevTools/npm-publish@v1
with:
package: "./scure-btc-signer/package.json"
token: ${{ secrets.NPM_TOKEN }}
access: "public"
dry-run: false
tag: ${{ github.event.inputs.dist_tag }}

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
scure-btc-signer
micro-packed
node_modules

47
build-micro-packed.mjs Normal file
View File

@@ -0,0 +1,47 @@
import { execSync } from "child_process";
import { readFileSync, writeFileSync } from "fs";
import stripJsonComments from 'strip-json-comments';
execSync('rm -rf micro-packed', { stdio: 'inherit' });
execSync('git clone --depth 1 https://github.com/paulmillr/micro-packed.git', { stdio: 'inherit' });
{
const packageJson = JSON.parse(readFileSync("micro-packed/package.json"));
packageJson.name = "micro-packed-cjs";
packageJson.homepage = "https://github.com/alexgo-io/npm-cjs.git";
packageJson.repository ={
"type": "git",
"url": "git+https://github.com/alexgo-io/npm-cjs.git"
};
packageJson.type = "commonjs";
console.log("package.json", packageJson);
writeFileSync(
"micro-packed/package.json",
JSON.stringify(packageJson, undefined, "\t")
);
}
{
const jsonText = stripJsonComments(readFileSync("micro-packed/tsconfig.json", "utf-8"), {trailingCommas: true})
const tsconfigJson = JSON.parse(jsonText);
tsconfigJson.compilerOptions.module = "commonjs";
tsconfigJson.compilerOptions.target = "es2020";
tsconfigJson.compilerOptions.esModuleInterop = true;
tsconfigJson.compilerOptions.moduleResolution = "node";
console.log("tsconfig.json", tsconfigJson);
writeFileSync(
"micro-packed/tsconfig.json",
JSON.stringify(tsconfigJson, undefined, "\t")
);
}
execSync('npm install', { cwd: 'micro-packed', stdio: 'inherit' });
execSync('npm run build', { cwd: 'micro-packed', stdio: 'inherit' });
execSync(`node -e "require('./micro-packed')"`, { stdio: 'inherit' });

View File

@@ -0,0 +1,54 @@
import { execSync } from "child_process";
import { readFileSync, writeFileSync } from "fs";
import stripJsonComments from 'strip-json-comments';
execSync('rm -rf scure-btc-signer', { stdio: 'inherit' });
execSync('git clone --depth 1 https://github.com/paulmillr/scure-btc-signer.git', { stdio: 'inherit' });
{
const packageJson = JSON.parse(readFileSync("scure-btc-signer/package.json"));
packageJson.name = "scure-btc-signer-cjs";
packageJson.homepage = "https://github.com/alexgo-io/npm-cjs.git";
packageJson.repository ={
"type": "git",
"url": "git+https://github.com/alexgo-io/npm-cjs.git"
};
packageJson.type = "commonjs";
packageJson.dependencies['micro-packed-cjs'] = "0.0.1";
console.log("package.json", packageJson);
writeFileSync(
"scure-btc-signer/package.json",
JSON.stringify(packageJson, undefined, "\t")
);
}
{
const jsonText = stripJsonComments(readFileSync("scure-btc-signer/tsconfig.json", "utf-8"), {trailingCommas: true})
const tsconfigJson = JSON.parse(jsonText);
tsconfigJson.compilerOptions.module = "commonjs";
tsconfigJson.compilerOptions.target = "es2020";
tsconfigJson.compilerOptions.esModuleInterop = true;
tsconfigJson.compilerOptions.moduleResolution = "node";
console.log("tsconfig.json", tsconfigJson);
writeFileSync(
"scure-btc-signer/tsconfig.json",
JSON.stringify(tsconfigJson, undefined, "\t")
);
}
{
const sourceCoreIndex = readFileSync("scure-btc-signer/index.ts", 'utf-8')
.replaceAll('micro-packed', 'micro-packed-cjs');
writeFileSync('scure-btc-signer/index.ts', sourceCoreIndex);
}
execSync('npm install', { cwd: 'scure-btc-signer', stdio: 'inherit' });
execSync('npm run build', { cwd: 'scure-btc-signer', stdio: 'inherit' });
execSync(`node -e "require('./scure-btc-signer')"`, { stdio: 'inherit' });

10
package.json Normal file
View File

@@ -0,0 +1,10 @@
{
"name": "alex-npm",
"version": "1.0.0",
"main": "index.js",
"author": "zitao xiong <caoer115@gmail.com>",
"license": "MIT",
"dependencies": {
"strip-json-comments": "^5.0.1"
}
}

8
yarn.lock Normal file
View File

@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
strip-json-comments@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-5.0.1.tgz#0d8b7d01b23848ed7dbdf4baaaa31a8250d8cfa0"
integrity sha512-0fk9zBqO67Nq5M/m45qHCJxylV/DhBlIOVExqgOMiCCrzrhU6tCibRXNqE3jwJLftzE9SNuZtYbpzcO+i9FiKw==