Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM #6

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish NPM

on:
push:
tags:
- v/*

jobs:

publish:

runs-on: ubuntu-latest

permissions:
contents: read

steps:

- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: v20
registry-url: https://registry.npmjs.org/

- uses: denoland/setup-deno@v1
with:
deno-version: v1

- name: Build the pkg
run: deno task build-npm

- name: Publish to npm
run: npm publish --tag=latest --access=public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

3 changes: 3 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"./main": "./src/cli/main.ts",
".": "./src/cli/bin.ts"
},
"tasks": {
"build-npm": "./tools/build-npm.ts"
},
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
Expand Down
25 changes: 25 additions & 0 deletions tmp-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "pkg-fence",
"version": "0.0.0-VERSION",
"description": "tbd",
"license": "AGPL-3.0-or-later",
"repository": {
"url": "https://github.com/imcotton/pkg-fence.git",
"type": "git"
},
"bin": "./dist/cli/bin.js",
"exports": {
"./main": "./dist/cli/main.js"
},
"files": [
"./dist/cli/bin.js",
"./dist/cli/main.js",
"./LICENSE.txt",
"./README.md"
],
"type": "module",
"sideEffects": false,
"engines": {
"node": ">=18"
}
}
85 changes: 85 additions & 0 deletions tools/build-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env -S deno run -A

import * as esbuild from 'https://deno.land/x/[email protected]/mod.js';

import * as fs from 'jsr:@std/fs@~0.229.3';

import pkg from '../deno.json' with { type: 'json' };





{ // package.json

const txt = await Deno.readTextFile('./tmp-package.json');
const content = txt.replace('0.0.0-VERSION', pkg.version);

const output = './package.json';
await Deno.writeTextFile(output, content, { create: true });

}





const outdir = './dist/cli';

await fs.ensureDir(outdir);





{ // the main file

const files = await esbuild.build({

outdir,
entryPoints: [
'./src/cli/main.ts',
],
write: false,
bundle: true,
format: 'esm',
platform: 'node',
target: [ 'node18', 'es2022' ],
supported: {
'node-colon-prefix-import': true,
},

});

for (const { path, text } of files.outputFiles) {

// https://esbuild.github.io/faq/#top-level-var
// const would be fine here
const content = text.replaceAll(/^var /gm, 'const ');

await Deno.writeTextFile(path, content, { create: true });

}

}





{ // the bin file

const txt = await Deno.readTextFile('./src/cli/bin.ts');
const content = txt.replace('main.ts', 'main.js');

const output = `${ outdir }/bin.js`;
await Deno.writeTextFile(output, content, { create: true });

}





await esbuild.stop();