From 6d11658cb8b21ad6b0a9f81591d7eaa087cc46f8 Mon Sep 17 00:00:00 2001 From: Aaron Francis Date: Wed, 15 Jun 2022 14:54:30 -0500 Subject: [PATCH] Module and deployment work. --- .github/workflows/publish.yml | 20 ++++++++----- .gitignore | 1 + bin/release | 3 +- index.js | 7 ----- package.json | 28 +++++++++++------- rollup.config.js | 54 +++++++++++++++++++++++++++++++++++ src/bin/torchlight.js | 1 - src/index.js | 7 +++++ src/torchlight.js | 4 --- 9 files changed, 95 insertions(+), 30 deletions(-) delete mode 100755 index.js create mode 100644 rollup.config.js create mode 100755 src/index.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b1af6a2..5c7a7cd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 }} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 9615802..3633b17 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ lib node_modules tests/tmp package-lock.json +dist diff --git a/bin/release b/bin/release index 7961fe5..280f1df 100755 --- a/bin/release +++ b/bin/release @@ -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" \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100755 index ca451a0..0000000 --- a/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import torchlight from './src/torchlight.js' -import Block from './src/block.js' - -export { - torchlight, - Block -} diff --git a/package.json b/package.json index 5ec659e..e9dbb2e 100644 --- a/package.json +++ b/package.json @@ -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 (https://torchlight.dev)", "license": "MIT", "dependencies": { @@ -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": { diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..b831a15 --- /dev/null +++ b/rollup.config.js @@ -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 + }] +}] diff --git a/src/bin/torchlight.js b/src/bin/torchlight.js index 2359fe6..7b54d5c 100755 --- a/src/bin/torchlight.js +++ b/src/bin/torchlight.js @@ -1,4 +1,3 @@ -#! /usr/bin/env node import { makeProgram } from '../cli.js' makeProgram().parse() diff --git a/src/index.js b/src/index.js new file mode 100755 index 0000000..ecc1f43 --- /dev/null +++ b/src/index.js @@ -0,0 +1,7 @@ +import torchlight from './torchlight.js' +import Block from './block.js' + +export { + torchlight, + Block +} diff --git a/src/torchlight.js b/src/torchlight.js index 0a9a443..161258b 100644 --- a/src/torchlight.js +++ b/src/torchlight.js @@ -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) {