Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Jun 15, 2022
1 parent 8cdf19c commit 29c628f
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 26 deletions.
9 changes: 9 additions & 0 deletions bin/postpublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { removeSync, pathExistsSync, moveSync } = require('fs-extra')

if (pathExistsSync('./package.json')) {
removeSync('./package.json')
}

if (pathExistsSync('./package.backup.json')) {
moveSync('./package.backup.json', './package.json')
}
36 changes: 36 additions & 0 deletions bin/prepublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { writeFileSync, copySync, pathExistsSync } = require('fs-extra')
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv

let pkg = require('../package.json')

const development = argv.dev
const production = argv.prod

if (!development && !production) {
throw new Error('Unknown environment.')
}

let version = '0.1.' + ~~(Date.now() / 1000)
let name = '@aaron-dev/torchlight-cli'

if (production) {
// Populated by GitHub actions
version = process.env.PACKAGE_VERSION
name = '@torchlight-api/torchlight-cli'
}

if (pathExistsSync('./package.backup.json')) {
throw new Error('package.backup.json already exists, not overwriting.')
}

copySync('./package.json', './package.backup.json')

pkg = {
...pkg,
name,
version: version
}

writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
15 changes: 15 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

if [ "$1" != "dev" ] && [ "$1" != "prod" ]; then
echo "The first argument must be 'dev' or 'prod'."
exit
fi

set -x

yarn run build
node ./bin/prepublish.js --"$1"
npm publish --access public
node ./bin/postpublish.js --"$1"
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torchlight from './src/torchlight'
import Block from './src/block'
import torchlight from './src/torchlight.js'
import Block from './src/block.js'

export {
torchlight,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@torchlight-api/torchlight-cli",
"version": "0.1.4",
"description": "A CLI for Torchlight - the syntax highlighting API",
"main": "index.js",
"type": "module",
"exports": "./index.js",
"scripts": {
"test": "standard --env jest && jest",
"build": "babel src --out-dir lib --copy-files \"--ignore\" \"src/stubs/**/*\""
Expand Down
2 changes: 1 addition & 1 deletion src/bin/torchlight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env node
import { makeProgram } from '../cli'
import { makeProgram } from '../cli.js'

makeProgram().parse()
4 changes: 2 additions & 2 deletions src/block.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import md5 from 'md5'
import guid from './support/guid'
import torchlight from './torchlight'
import guid from './support/guid.js'
import torchlight from './torchlight.js'

export default function Block (opts = {}) {
opts = {
Expand Down
10 changes: 5 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { program } from 'commander'
import torchlight from './torchlight'
import highlight from './commands/highlight'
import init from './commands/init'
import cacheClear from './commands/cache/clear'
import { makeConfig, makeCache } from './config'
import torchlight from './torchlight.js'
import highlight from './commands/highlight.js'
import init from './commands/init.js'
import cacheClear from './commands/cache/clear.js'
import { makeConfig, makeCache } from './config.js'

/**
* Configure the commander CLI application.
Expand Down
8 changes: 4 additions & 4 deletions src/commands/highlight.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path'
import torchlight from '../torchlight'
import Block from '../block'
import torchlight from '../torchlight.js'
import Block from '../block.js'
import cheerio from 'cheerio'
import chokidar from 'chokidar'
import log from '../support/log'
import log from '../support/log.js'
import fs from 'fs-extra'
import { bus, FILE_WATCHING_COMPLETE } from '../support/bus'
import { bus, FILE_WATCHING_COMPLETE } from '../support/bus.js'

export default function (torchlight, options) {
options = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra'
import path from 'path'
import inquirer from 'inquirer'
import log from '../support/log'
import log from '../support/log.js'

function write (location) {
const source = path.resolve(path.join(__dirname, '../stubs/config.js'))
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra'
import path from 'path'
import FileCache from './cache/file'
import MemoryCache from './cache/memory'
import FileCache from './cache/file.js'
import MemoryCache from './cache/memory.js'

/**
* @param {string|object} config
Expand Down
4 changes: 2 additions & 2 deletions src/torchlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import axios from 'axios'
import md5 from 'md5'
import get from 'lodash.get'
import chunk from 'lodash.chunk'
import log from './support/log'
import MemoryCache from './cache/memory'
import log from './support/log.js'
import MemoryCache from './cache/memory.js'

/**
* @constructor
Expand Down
6 changes: 3 additions & 3 deletions tests/highlight.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torchlight from '../src/torchlight';
import {mockApi, fixture} from './support/helpers';
import log from '../src/support/log';
import torchlight from '../src/torchlight.js';
import {mockApi, fixture} from './support/helpers.js';
import log from '../src/support/log.js';

process.env.TORCHLIGHT_TOKEN = 'test'

Expand Down
6 changes: 3 additions & 3 deletions tests/support/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bus, FILE_WATCHING_COMPLETE } from '../../src/support/bus'
import { testCli } from '../../src/cli'
import { readFileSync } from 'fs-extra'
import torchlight from '../../src/torchlight'
import { bus, FILE_WATCHING_COMPLETE } from '../../src/support/bus.js'
import { testCli } from '../../src/cli.js'
import torchlight from '../../src/torchlight.js'

function fixture (file, callback, options = {}) {
options = {
Expand Down

0 comments on commit 29c628f

Please sign in to comment.