Skip to content

Commit

Permalink
Module and deployment work.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Jun 15, 2022
1 parent 29c628f commit 6d11658
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 30 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ name: Publish to NPM
on:
release:
types: [ created ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: 14
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build
- run: npm publish

- name: Install dependencies
run: npm ci

- name: Inject version
run: echo "PACKAGE_VERSION=$(git describe --tags)" >> $GITHUB_ENV

- name: Publish to NPM
run: npm run release:prod
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ lib
node_modules
tests/tmp
package-lock.json
dist
3 changes: 2 additions & 1 deletion bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ fi

set -x

yarn run build
rm -rf ./dist/
npm run build
node ./bin/prepublish.js --"$1"
npm publish --access public
node ./bin/postpublish.js --"$1"
7 changes: 0 additions & 7 deletions index.js

This file was deleted.

28 changes: 18 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
"name": "@torchlight-api/torchlight-cli",
"version": "0.1.4",
"description": "A CLI for Torchlight - the syntax highlighting API",
"type": "module",
"exports": "./index.js",
"source": "./src/index.js",
"module": "./dist/torchlight-cli.esm.js",
"main": "./dist/torchlight-cli.cjs.js",
"scripts": {
"test": "standard --env jest && jest",
"build": "babel src --out-dir lib --copy-files \"--ignore\" \"src/stubs/**/*\""
"build": "rollup --config rollup.config.js",
"release:dev": "./bin/release dev",
"release:prod": "./bin/release prod"
},
"bin": {
"torchlight": "lib/bin/torchlight.js"
"torchlight": "dist/bin/torchlight.cjs.js"
},
"keywords": [
"syntax",
"highlighting",
"torchlight"
],
"files": [
"/dist/*",
"/src/**/*"
],
"author": "Aaron Francis <[email protected]> (https://torchlight.dev)",
"license": "MIT",
"dependencies": {
Expand All @@ -31,18 +38,19 @@
"md5": "^2.3.0"
},
"devDependencies": {
"@babel/preset-env": "^7.15.0",
"@babel/cli": "^7.14.8",
"@babel/core": "^7.15.0",
"@babel/node": "^7.12.13",
"@babel/preset-env": "^7.18.2",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"babel-jest": "^27.0.6",
"jest": "^27.0.6",
"rollup": "^2.75.6",
"rollup-plugin-terser": "^7.0.2",
"standard": "^16.0.3"
},
"standard": {
"ignore": [
"tests",
"lib"
"dist",
"tests"
]
},
"jest": {
Expand Down
54 changes: 54 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import { terser } from 'rollup-plugin-terser'

const common = {
external: [
/node_modules/
],
plugins: [
resolve(),
babel({
babelHelpers: 'bundled'
})
]
}

const cjs = {
format: 'cjs',
exports: 'named',
sourcemap: true
}

const esm = {
...cjs,
format: 'es'
}

module.exports = [{
...common,
input: 'src/index.js',
output: [{
file: 'dist/torchlight-cli.esm.js',
...esm
}, {
file: 'dist/torchlight-cli.esm.min.js',
plugins: [terser()],
...esm
}, {
file: 'dist/torchlight-cli.cjs.js',
...cjs
}, {
file: 'dist/torchlight-cli.cjs.min.js',
plugins: [terser()],
...cjs
}]
}, {
...common,
input: 'src/bin/torchlight.js',
output: [{
banner: '#! /usr/bin/env node',
file: 'dist/bin/torchlight.cjs.js',
...cjs
}]
}]
1 change: 0 additions & 1 deletion src/bin/torchlight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env node
import { makeProgram } from '../cli.js'

makeProgram().parse()
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import torchlight from './torchlight.js'
import Block from './block.js'

export {
torchlight,
Block
}
4 changes: 0 additions & 4 deletions src/torchlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ Torchlight.prototype.request = function (blocks) {

const token = this.config('token')

if (!token) {
throw new Error('No Torchlight token configured!')
}

// For huge sites, we need to send blocks in chunks so
// that we don't send e.g. 500 blocks in one request.
if (blocks.length > this.chunkSize) {
Expand Down

0 comments on commit 6d11658

Please sign in to comment.