Skip to content

Commit

Permalink
First
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Aug 18, 2021
0 parents commit abd43e9
Show file tree
Hide file tree
Showing 16 changed files with 1,394 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
torchlight.config.js
source
built
.idea
node_modules
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torchlight.config.js
source
built
.idea
Empty file added commands/list.js
Empty file.
55 changes: 55 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /usr/bin/env node
const {program} = require('commander')
const torchlight = require('./src/torchlight');

command('_default_')
.alias('highlight')
.description('Highlight <code> blocks in source files')
.option('-i, --input <directory>', 'Input directory')
.option('-o, --output <directory>', 'Output directory')
.option('-g, --globs <pattern>', 'Glob patterns used to search for source files. Separate multiple patterns with commas.')
.option('-x, --ignore <pattern>', 'Glob patterns used to ignore source files. Separate multiple patterns with commas.')
.option('-w, --watch', 'Watch source files for changes')

command('init')
.option('-p, --path <path>', 'Location for the configuration file')
.description('Publish the Torchlight configuration file');

command('cache:clear')
.description('Clear the cache');

// Bootstrap the Torchlight singleton before every command.
program.hook('preAction', thisCommand => {
torchlight.init(thisCommand.opts().config)
})

program.parse()

// A helper function to define commands. It takes
// care of several defaults for every command.
function command(name) {
let cmd = program;
let action = name;

// The default command has no name.
if (name !== '_default_') {
cmd = cmd.command(name);
} else {
action = 'highlight';
}

// Namespaced command convention. The command config:cache
// has a handler at config/cache.js.
action = action.replace(':', '/');

let handler = require(`./src/commands/${action}`);

// Add a little shim around the handler so we can pass the
// torchlight variable in, just for convenience.
cmd.action(function (options) {
return handler(torchlight, options);
})

// Options config path
return cmd.option('-c, --config <file>', 'Path to the Torchlight configuration file.')
}
Loading

0 comments on commit abd43e9

Please sign in to comment.