-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add missing tool in contribution guidelines * First cut of NPM distribution * Include 386 arch builds. Switch to a specific file list instead of just copying anything that matches the platform. * docs and changelog * Moved package.json into the top level so it's easier to include the readme and license * Some defensive techniques, the bin reference is now always there and simply replaced by postinstall * Switched from postinstall to JS wrapper around the binary
- Loading branch information
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: Added | ||
body: 'Changie is now available as an NPM package: https://www.npmjs.com/package/changie' | ||
time: 2023-10-25T21:41:01.142107+11:00 | ||
custom: | ||
Issue: "561" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,7 @@ docs/content/config/_index.md | |
|
||
# goreleaser builds | ||
dist/ | ||
|
||
# NPM publishing | ||
npm/dist/ | ||
changie-*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env node | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const { spawn } = require('node:child_process') | ||
|
||
// Platform distributed through NPM, this should mirror the package.json file list | ||
const executables = { | ||
'darwin-arm64': true, | ||
'darwin-x64': true, | ||
'linux-arm64': true, | ||
'linux-x64': true, | ||
'win32-ia32': true, | ||
'win32-x64': true | ||
}; | ||
|
||
const DIST = path.join(__dirname, 'dist'); | ||
const target = `${process.platform}-${process.arch}` | ||
|
||
const runChangie = (filename) => { | ||
const ext = process.platform === 'win32' ? '.exe' : ''; | ||
const executable = path.join(DIST, filename + ext); | ||
const stat = fs.statSync(executable) | ||
if (stat.isFile()) { | ||
const child = spawn(executable, process.argv.slice(2)); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
child.on('close', (code) => { | ||
process.exit(code); | ||
}); | ||
} else { | ||
throw new Error(`Unable to find changie ${executable} in NPM package`) | ||
} | ||
} | ||
|
||
if (executables[target]) { | ||
runChangie(target); | ||
} else { | ||
throw new Error(`Unsupported platform for Changie: ${target}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env node | ||
import * as fs from 'node:fs/promises'; | ||
import * as path from 'node:path'; | ||
|
||
import { execSync } from 'node:child_process'; | ||
|
||
// Mapping from to goarch to Node's `process.arch` | ||
var ARCH_MAPPING = { | ||
'386': 'ia32', | ||
'amd64': 'x64', | ||
'arm64': 'arm64', | ||
}; | ||
|
||
// Mapping between goos and Node's `process.platform` | ||
var PLATFORM_MAPPING = { | ||
'darwin': 'darwin', | ||
'linux': 'linux', | ||
'windows': 'win32' | ||
}; | ||
|
||
const NPM = 'npm'; | ||
const NPM_DIST = path.join(NPM, 'dist'); | ||
const RELEASES = path.join('dist', 'artifacts.json'); | ||
|
||
// read the goreleaser JSON and filter down to just the binaries | ||
const json = JSON.parse(await fs.readFile(RELEASES)); | ||
const binaries = json.filter(r => r.type === 'Binary'); | ||
|
||
// clean up any previous runs | ||
const output = execSync(`git clean -fdX ${NPM}`); | ||
console.log(output.toString()) | ||
|
||
// make the dist folder | ||
await fs.mkdir(NPM_DIST, { recursive: true }) | ||
|
||
// copy each binary into the place the NPM distribution expects it to be | ||
await binaries.forEach(async (release) => { | ||
const os = PLATFORM_MAPPING[release.goos]; | ||
const arch = ARCH_MAPPING[release.goarch]; | ||
|
||
// use NodeJS constants for the filename, e.g. win32-x64.exe | ||
const distfile = `${os}-${arch}${release.extra.Ext}`; | ||
|
||
// copy files even if we don't use them, `package.json` uses a filtered list | ||
const target = path.join(NPM_DIST, distfile); | ||
await fs.copyFile(release.path, target); | ||
console.log('copied ', release.path, 'to', target); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "changie", | ||
"version": "1.14.0", | ||
"author": "miniscruff", | ||
"description": "Automated changelog tool for preparing releases with lots of customization options", | ||
"bin": { | ||
"changie": "npm/changie.js" | ||
}, | ||
"scripts": { | ||
"prepack": "ls `node -e 'console.log((require(\"./package.json\").files||[]).join(\" \"))'`>/dev/null" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/miniscruff/changie.git" | ||
}, | ||
"keywords": [ | ||
"changelog" | ||
], | ||
"files": [ | ||
"npm/dist/darwin-arm64", | ||
"npm/dist/darwin-x64", | ||
"npm/dist/linux-arm64", | ||
"npm/dist/linux-x64", | ||
"npm/dist/win32-ia32.exe", | ||
"npm/dist/win32-x64.exe", | ||
"npm/changie.js", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/miniscruff/changie/issues" | ||
}, | ||
"homepage": "https://github.com/miniscruff/changie#readme" | ||
} |