Skip to content

Commit

Permalink
drop support for node < v12.17
Browse files Browse the repository at this point in the history
rewrite project as ESM
  • Loading branch information
75lb committed Sep 7, 2021
1 parent b44c8fe commit e184b07
Show file tree
Hide file tree
Showing 15 changed files with 916 additions and 524 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12, 14, 16]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test:ci
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node
const ansi = require('ansi-escape-sequences')
const commandLineArgs = require('command-line-args')
const hbjs = require('../')
const cliOptions = require('../lib/cli-options')
const util = require('util')
import ansi from 'ansi-escape-sequences'
import commandLineArgs from 'command-line-args'
import * as hbjs from 'handbrake-js'
import cliOptions from '../lib/cli-options.js'
import util from 'util'

const handbrakeOptions = commandLineArgs(cliOptions)._all

Expand Down
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import Handbrake from './lib/Handbrake.js'
import util from 'util'
import cp from 'child_process'
import toSpawnArgs from 'object-to-spawn-args'
import { HandbrakeCLIPath } from './lib/config.js'
import cliOptions from './lib/cli-options.js'

/**
* Handbrake for node.js.
* @module handbrake-js
Expand Down Expand Up @@ -30,7 +37,6 @@
* ```
*/
function spawn (options, mocks) {
const Handbrake = require('./lib/Handbrake')
const handbrake = new Handbrake(mocks)

/* defer so the caller can attach event listers on the returned Handbrake instance first */
Expand Down Expand Up @@ -67,13 +73,9 @@ function spawn (options, mocks) {
* @alias module:handbrake-js.exec
*/
function exec (options, done) {
const util = require('util')
const cp = require('child_process')
const toSpawnArgs = require('object-to-spawn-args')
const config = require('./lib/config')
const cmd = util.format(
'"%s" %s',
config.HandbrakeCLIPath,
HandbrakeCLIPath,
toSpawnArgs(options, { quote: true }).join(' ')
)
cp.exec(cmd, done)
Expand Down Expand Up @@ -109,7 +111,4 @@ async function run (options) {
})
}

exports.spawn = spawn
exports.exec = exec
exports.run = run
exports.cliOptions = require('./lib/cli-options')
export { cliOptions, spawn, exec, run }
19 changes: 9 additions & 10 deletions lib/Handbrake.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const EventEmitter = require('events').EventEmitter
import { EventEmitter } from 'events'
import { HandbrakeCLIPath } from './config.js'
import path from 'path'
import * as progress from './progress.js'
import toSpawnArgs from 'object-to-spawn-args'
import childProcess from 'child_process'

/**
* @class
Expand Down Expand Up @@ -32,11 +37,10 @@ class Handbrake extends EventEmitter {
this.options = null

/* path to the HandbrakeCLI executable downloaded by the install script */
const config = require('./config')
this.HandbrakeCLIPath = config.HandbrakeCLIPath
this.HandbrakeCLIPath = HandbrakeCLIPath

/* for test scripts */
this.cp = (mocks && mocks.cp) || require('child_process')
this.cp = (mocks && mocks.cp) || childProcess
this.HandbrakeCLIPath = (mocks && mocks.HandbrakeCLIPath) || this.HandbrakeCLIPath
}

Expand All @@ -57,10 +61,6 @@ class Handbrake extends EventEmitter {

/* ensure user has had chance to attach event listeners before calling */
_run () {
const path = require('path')
const progress = require('./progress')
const toSpawnArgs = require('object-to-spawn-args')

let err = new Error()

if (this.options.input !== undefined && this.options.output !== undefined) {
Expand All @@ -79,7 +79,6 @@ class Handbrake extends EventEmitter {
})
this._emitStart()
const handle = this.cp.spawn(this.HandbrakeCLIPath, spawnArgs)

handle.stdout.setEncoding('utf-8')

let buffer = ''
Expand Down Expand Up @@ -295,4 +294,4 @@ Handbrake.prototype.eError = {
* @see http://nodejs.org/api/events.html
*/

module.exports = Handbrake
export default Handbrake
2 changes: 1 addition & 1 deletion lib/cli-options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
export default [
{ name: 'help', type: Boolean, alias: 'h', group: 'general' },
{ name: 'version', type: Boolean, group: 'general' },
{ name: 'verbose', type: Boolean, alias: 'v', group: 'general' },
Expand Down
6 changes: 4 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require('path')
import path from 'path'
import currentModulePaths from 'current-module-paths'
const { __dirname } = currentModulePaths(import.meta.url)

/* path to the HandbrakeCLI executable downloaded by the install script */
let HandbrakeCLIPath = null
Expand All @@ -15,4 +17,4 @@ switch (process.platform) {
break
}

exports.HandbrakeCLIPath = HandbrakeCLIPath
export { HandbrakeCLIPath }
12 changes: 6 additions & 6 deletions lib/progress.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
let last = null

const short = {
pattern: /\rEncoding: task (\d) of (\d), (.+) %/,
parse: function (progressString) {
const match = progressString.match(this.pattern)
if (match) {
const data = exports.last = {
const data = last = {
taskNumber: +match[1],
taskCount: +match[2],
percentComplete: +match[3],
Expand All @@ -22,7 +24,7 @@ const long = {
parse: function (progressString) {
const match = progressString.match(this.pattern)
if (match) {
const data = exports.last = {
const data = last = {
taskNumber: +match[1],
taskCount: +match[2],
percentComplete: +match[3],
Expand All @@ -41,7 +43,7 @@ const muxing = {
parse: function (progressString) {
const match = progressString.match(this.pattern)
if (match) {
const data = exports.last = {
const data = last = {
taskNumber: 0,
taskCount: 0,
percentComplete: 0,
Expand All @@ -55,6 +57,4 @@ const muxing = {
}
}

exports.short = short
exports.long = long
exports.muxing = muxing
export { long, short, muxing, last }
Loading

0 comments on commit e184b07

Please sign in to comment.