Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
module.exports = ['darwin', 'linux', 'win32']
|
||||
@@ -0,0 +1,27 @@
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const platforms = require('./platforms')
|
||||
const updatePackageJson = require('./update-package')
|
||||
|
||||
const { version } = require('../package.json')
|
||||
|
||||
updatePackageJson(path.join(__dirname, '..', 'package.json'), {
|
||||
optionalDependencies: platforms.reduce((acc, cur) => {
|
||||
acc[`@napi-rs/package-template-${cur}`] = `^${version}`
|
||||
return acc
|
||||
}, {}),
|
||||
})
|
||||
|
||||
for (const name of platforms) {
|
||||
const pkgDir = path.join(__dirname, '..', 'npm', name)
|
||||
const filename = `index.${name}.node`
|
||||
const bindingFile = fs.readFileSync(path.join(__dirname, '..', `bindings-${name}`, filename))
|
||||
fs.writeFileSync(path.join(pkgDir, filename), bindingFile)
|
||||
execSync('npm publish', {
|
||||
cwd: pkgDir,
|
||||
env: process.env,
|
||||
stdio: 'inherit',
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = function updatePackageJson(path, partial) {
|
||||
const old = require(path)
|
||||
fs.writeFileSync(path, JSON.stringify({ ...old, ...partial }, null, 2))
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
const { execSync } = require('child_process')
|
||||
const { join } = require('path')
|
||||
|
||||
const { Octokit } = require('@octokit/rest')
|
||||
const chalk = require('chalk')
|
||||
const putasset = require('putasset')
|
||||
|
||||
const platforms = require('./platforms')
|
||||
|
||||
const version =
|
||||
'v' +
|
||||
execSync('git log -1 --pretty=%B', {
|
||||
encoding: 'utf8',
|
||||
}).trim('')
|
||||
|
||||
;(async () => {
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
})
|
||||
await octokit.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name: version,
|
||||
})
|
||||
await Promise.all(
|
||||
platforms.map(async (platform) => {
|
||||
const binary = join(__dirname, '..', `bindings-${platform}`, `index.${platform}.node`)
|
||||
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
|
||||
owner,
|
||||
repo,
|
||||
tag: version,
|
||||
filename: binary,
|
||||
})
|
||||
console.info(`${chalk.green(binary)} upload success`)
|
||||
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
|
||||
}),
|
||||
)
|
||||
})().catch((e) => {
|
||||
console.error(e)
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
const { execSync } = require('child_process')
|
||||
const path = require('path')
|
||||
|
||||
const { version } = require('../package.json')
|
||||
const platforms = require('./platforms')
|
||||
const updatePackageJson = require('./update-package')
|
||||
|
||||
for (const name of platforms) {
|
||||
const pkgDir = path.join(__dirname, '..', 'npm', name)
|
||||
updatePackageJson(path.join(pkgDir, 'package.json'), {
|
||||
version,
|
||||
})
|
||||
}
|
||||
|
||||
execSync('git add .', {
|
||||
stdio: 'inherit',
|
||||
})
|
||||
Reference in New Issue
Block a user