Skip to content

Commit

Permalink
Merge pull request #144 from eheikes/upgrade-deps
Browse files Browse the repository at this point in the history
Upgrade "standard" package
  • Loading branch information
eheikes authored Jan 2, 2024
2 parents 189e812 + 5d76561 commit 78e683a
Show file tree
Hide file tree
Showing 18 changed files with 1,382 additions and 3,348 deletions.
4,558 changes: 1,295 additions & 3,263 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"jasmine": "^3.5.0",
"nyc": "^14.1.0",
"proxyquire": "^1.8.0",
"standard": "^12.0.1"
"standard": "^17.1.0"
},
"dependencies": {
"tts-cli": "file:packages/tts-cli"
Expand Down
4 changes: 2 additions & 2 deletions packages/tts-cli/lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const fs = require('fs-extra')
*/
exports.cleanup = ctx => {
const manifestFile = ctx.manifestFile
let manifest = fs.readFileSync(manifestFile, 'utf8')
const manifest = fs.readFileSync(manifestFile, 'utf8')
debug(`Manifest is ${manifest}`)
let regexpState = /^file\s+'(.*)'$/gm
const regexpState = /^file\s+'(.*)'$/gm
let match
while ((match = regexpState.exec(manifest)) !== null) {
debug(`Deleting temporary file ${match[1]}`)
Expand Down
14 changes: 7 additions & 7 deletions packages/tts-cli/lib/combine-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { extensionFor } = require('./file-extensions')
* Combines MP3 or OGG files into one file.
*/
exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
let args = [
const args = [
'-f', 'concat',
'-safe', '0',
'-i', manifestFile,
Expand All @@ -17,7 +17,7 @@ exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
]
return new Promise((resolve, reject) => {
debug('combineEncodedAudio')(`Running ${binary} ${args.join(' ')}`)
let ffmpeg = spawn(binary, args)
const ffmpeg = spawn(binary, args)
let stderr = ''
ffmpeg.stderr.on('data', (data) => {
stderr += `\n${data}`
Expand All @@ -40,17 +40,17 @@ exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
* Concatenates raw PCM audio into one file.
*/
exports.combineRawAudio = (manifestFile, outputFile) => {
let manifest = fs.readFileSync(manifestFile, 'utf8')
const manifest = fs.readFileSync(manifestFile, 'utf8')
debug('combineRawAudio')(`Manifest contains: ${manifest}`)
let regexpState = /^file\s+'(.*)'$/gm
const regexpState = /^file\s+'(.*)'$/gm
debug('combineRawAudio')(`Creating file ${outputFile}`)
fs.createFileSync(outputFile)
debug('combineRawAudio')(`Truncating file ${outputFile}`)
fs.truncateSync(outputFile)
let match
while ((match = regexpState.exec(manifest)) !== null) {
debug('combineRawAudio')(`Reading data from ${match[1]}`)
let dataBuffer = fs.readFileSync(match[1])
const dataBuffer = fs.readFileSync(match[1])
debug('combineRawAudio')(`Appending data to ${outputFile}`)
fs.appendFileSync(outputFile, dataBuffer)
}
Expand All @@ -64,9 +64,9 @@ exports.combineRawAudio = (manifestFile, outputFile) => {
exports.combine = (ctx) => {
const manifestFile = ctx.manifestFile
const opts = ctx.opts
let newFile = tempfile(`.${extensionFor(opts.format, ctx.service)}`)
const newFile = tempfile(`.${extensionFor(opts.format, ctx.service)}`)
debug('combine')(`Combining files into ${newFile}`)
let combiner = opts.format === 'pcm' && ctx.service === 'aws'
const combiner = opts.format === 'pcm' && ctx.service === 'aws'
? exports.combineRawAudio(manifestFile, newFile)
: exports.combineEncodedAudio(opts.ffmpeg, manifestFile, newFile)
return combiner.then(() => {
Expand Down
12 changes: 6 additions & 6 deletions packages/tts-cli/lib/generate-speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const { sanitizeOpts } = require('./sanitize-opts')
exports.buildInfo = (text, instance, task, ctx) => {
return Object.assign({
opts: ctx.opts,
task: task,
task,
tempfile: tempfile(`.${extensionFor(ctx.opts.format, ctx.service)}`),
text: text
text
}, instance.buildPart(text, task, ctx.opts))
}

Expand All @@ -22,9 +22,9 @@ exports.buildInfo = (text, instance, task, ctx) => {
* Returns the text filename.
*/
exports.createManifest = parts => {
let txtFile = tempfile('.txt')
const txtFile = tempfile('.txt')
debug('createManifest')(`Creating ${txtFile} for manifest`)
let contents = parts.map(info => {
const contents = parts.map(info => {
return `file '${info.tempfile}'`
}).join('\n')
debug('createManifest')(`Writing manifest contents:\n${contents}`)
Expand All @@ -36,7 +36,7 @@ exports.createManifest = parts => {
* Calls the API for each text part (throttled). Returns a Promise.
*/
exports.generateAll = (parts, opts, func, task) => {
let count = parts.length
const count = parts.length
task.title = `Convert to audio (0/${count})`
return (new Promise((resolve, reject) => {
debug('generateAll')(`Requesting ${count} audio segments, ${opts.limit} at a time`)
Expand Down Expand Up @@ -106,7 +106,7 @@ exports.generateSpeech = (ctx, task) => {
const instance = provider.create(ctx.opts)

// Compile the text parts and options together in a packet.
let parts = strParts.map(part => exports.buildInfo(part, instance, task, ctx))
const parts = strParts.map(part => exports.buildInfo(part, instance, task, ctx))

return exports.generateAll(parts, ctx.opts, instance.generate.bind(instance), task)
.then(exports.createManifest)
Expand Down
2 changes: 1 addition & 1 deletion packages/tts-cli/lib/providers/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PollyProvider.prototype.buildPart = function () {
PollyProvider.prototype.generate = (info, i, callback) => {
info.task.title = info.task.title.replace(/\d+\//, `${i}/`)

let command = new SynthesizeSpeechCommand({
const command = new SynthesizeSpeechCommand({
Engine: info.opts.engine,
LanguageCode: info.opts.language,
LexiconNames: info.opts.lexicon,
Expand Down
15 changes: 9 additions & 6 deletions packages/tts-cli/lib/providers/gcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const GoogleClient = require('@google-cloud/text-to-speech').TextToSpeechClient
const GoogleProvider = function (opts) {
try {
this.instance = new GoogleClient({
credentials: opts.email || opts.privateKey ? {
client_email: opts.email,
private_key: opts.privateKey
} : undefined,
credentials: opts.email || opts.privateKey
? {
client_email: opts.email,
private_key: opts.privateKey
}
: undefined,
keyFilename: opts.projectFile ? path.resolve(opts.projectFile) : undefined,
projectId: opts.projectId
})
Expand Down Expand Up @@ -43,7 +45,8 @@ GoogleProvider.prototype.generate = (info, i, callback) => {
name: info.opts.voice
},
audioConfig: {
audioEncoding: info.opts.format === 'pcm' ? 'LINEAR16'
audioEncoding: info.opts.format === 'pcm'
? 'LINEAR16'
: info.opts.format === 'ogg' ? 'OGG_OPUS' : 'MP3',
effectsProfileId: info.opts.effect,
pitch: info.opts.pitch,
Expand Down Expand Up @@ -78,6 +81,6 @@ GoogleProvider.prototype.generate = (info, i, callback) => {
* Create a Google Cloud TTS instance.
*/
exports.create = opts => {
debug('create')(`Creating Google Cloud TTS instance`)
debug('create')('Creating Google Cloud TTS instance')
return new GoogleProvider(opts)
}
2 changes: 1 addition & 1 deletion packages/tts-cli/lib/read-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.readText = (ctx) => {
let data = ''
proc.stdin.setEncoding('utf8')
proc.stdin.on('readable', () => {
let chunk = proc.stdin.read()
const chunk = proc.stdin.read()
/* istanbul ignore else: need to add test for this */
if (chunk !== null) { data += chunk }
})
Expand Down
6 changes: 3 additions & 3 deletions packages/tts-cli/lib/sanitize-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ exports.sanitizeOpts = (opts) => {
const sanitizedOpts = Object.assign({}, opts)
sanitizedOpts['access-key'] = sanitizedOpts['access-key'] ? 'XXXXXXXX' : undefined
sanitizedOpts['secret-key'] = sanitizedOpts['secret-key'] ? 'XXXXXXXX' : undefined
sanitizedOpts['accessKey'] = sanitizedOpts['accessKey'] ? 'XXXXXXXX' : undefined
sanitizedOpts['privateKey'] = sanitizedOpts['privateKey'] ? 'XXXXXXXX' : undefined
sanitizedOpts['secretKey'] = sanitizedOpts['secretKey'] ? 'XXXXXXXX' : undefined
sanitizedOpts.accessKey = sanitizedOpts.accessKey ? 'XXXXXXXX' : undefined
sanitizedOpts.privateKey = sanitizedOpts.privateKey ? 'XXXXXXXX' : undefined
sanitizedOpts.secretKey = sanitizedOpts.secretKey ? 'XXXXXXXX' : undefined
return sanitizedOpts
}
18 changes: 9 additions & 9 deletions packages/tts-cli/lib/split-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const textchunk = require('textchunk')
* Chunk text into pieces.
*/
const chunkText = (text, maxCharacterCount) => {
let parts = textchunk.chunk(text, maxCharacterCount)
const parts = textchunk.chunk(text, maxCharacterCount)
debug('chunkText')(`Chunked into ${parts.length} text parts`)
return Promise.resolve(parts)
}
Expand All @@ -22,9 +22,9 @@ const chunkXml = (xml, maxCharacterCount) => {
debug('chunkXml')('Started SAX XML parser')
const attributeString = attrs => {
let str = ''
for (let prop in attrs) {
for (const prop in attrs) {
/* istanbul ignore else: need to add test for this */
if (attrs.hasOwnProperty(prop)) {
if (Object.prototype.hasOwnProperty.call(attrs, prop)) {
str += ` ${prop}="${attrs[prop]}"`
}
}
Expand All @@ -33,16 +33,16 @@ const chunkXml = (xml, maxCharacterCount) => {
return new Promise((resolve, reject) => {
let err = null
let extraTags = '' // self-closing tags
let tags = [] // stack of open tags
let parts = []
const tags = [] // stack of open tags
const parts = []
/* istanbul ignore next */
parser.onerror = e => {
debug('chunkXml')(`Encountered error: ${e}`)
err = e
}
parser.ontext = text => {
debug('chunkXml')(`Found text: ${text.substr(0, 50)}...`) // eslint-disable-line no-magic-numbers
let chunks = textchunk.chunk(text, maxCharacterCount).map((chunk, index) => {
const chunks = textchunk.chunk(text, maxCharacterCount).map((chunk, index) => {
if (index === 0) {
debug('chunkXml')('Adding unused self-closing tags:', extraTags)
chunk = `${extraTags}${chunk}`
Expand All @@ -62,7 +62,7 @@ const chunkXml = (xml, maxCharacterCount) => {
parser.onopentag = tagData => {
debug('chunkXml')(`Found tag: ${JSON.stringify(tagData)}`)
if (tagData.isSelfClosing) {
let attrs = attributeString(tagData.attributes)
const attrs = attributeString(tagData.attributes)
debug('chunkXml')(`Adding "${tagData.name}" to self-closing tags`)
extraTags += `<${tagData.name}${attrs}/>`
} else {
Expand All @@ -78,7 +78,7 @@ const chunkXml = (xml, maxCharacterCount) => {
tags.pop()
} else {
// TODO should error
debug('chunkXml')(`Problem: mismatched tags`)
debug('chunkXml')('Problem: mismatched tags')
}
}
parser.onend = () => {
Expand All @@ -101,7 +101,7 @@ exports.splitText = (ctx) => {
const text = ctx.text
const maxCharacterCount = ctx.maxCharacterCount
const opts = ctx.args || {}
let chunker = opts.type === 'ssml' ? chunkXml : chunkText
const chunker = opts.type === 'ssml' ? chunkXml : chunkText
return chunker(text, maxCharacterCount).then(parts => {
debug('splitText')('Stripping whitespace')
return parts.map(str => {
Expand Down
3 changes: 1 addition & 2 deletions packages/tts-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"yarn.lock"
],
"scripts": {
"lint": "standard --fix --verbose",
"lint": "standard --env jasmine --fix --verbose",
"report-coverage": "codecov",
"test": "cross-env JASMINE_CONFIG_PATH=test/jasmine.json nyc jasmine"
},
Expand Down Expand Up @@ -52,7 +52,6 @@
},
"standard": {
"env": {
"jasmine": true,
"node": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/tts-cli/test/build-info.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('buildInfo()', () => {
expect(output.text).toBe(text)
})

it(`should add in the instance's properties`, () => {
it('should add in the instance\'s properties', () => {
expect(output.foo).toBe(instance.foo)
expect(output.bar).toBe(instance.bar)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/tts-cli/test/check-usage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('checkUsage()', () => {
write = jasmine.createSpy('process.stderr.write')
proc = {
argv: ['node', 'tts.js'],
exit: exit,
exit,
stderr: {
write: write
write
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/tts-cli/test/generate-all.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('generateAll()', () => {

it('should asynchronously call the function for each of the parts', done => {
generateAll(textParts, { limit: testLimit }, iteratorFunction, task).then(() => {
let [parts] = async.eachOfLimit.calls.mostRecent().args
const [parts] = async.eachOfLimit.calls.mostRecent().args
expect(parts).toEqual(textParts)
expect(parts.length).toBe(textParts.length)
expect(iteratorFunction.calls.count()).toBe(textParts.length)
Expand All @@ -27,7 +27,7 @@ describe('generateAll()', () => {

it('should limit the async calls according to the option', done => {
generateAll(textParts, { limit: testLimit }, iteratorFunction, task).then(() => {
let [, limit] = async.eachOfLimit.calls.mostRecent().args
const [, limit] = async.eachOfLimit.calls.mostRecent().args
expect(limit).toBe(testLimit)
}).then(done)
})
Expand Down
14 changes: 7 additions & 7 deletions packages/tts-cli/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.loadLib = (file) => {
spyOn(async, 'eachOfLimit').and.callThrough()

// Stub out the fs(-extra) module with spies.
let fs = jasmine.createSpyObj('fs', [
const fs = jasmine.createSpyObj('fs', [
'appendFileSync',
'createFileSync',
'createWriteStream',
Expand All @@ -27,18 +27,18 @@ exports.loadLib = (file) => {
fs.writeFile.and.callFake((dest, data, opts, callback) => { callback() })

// Stub out a provider.
let providerStub = {
const providerStub = {
create: () => ({
buildPart: () => ({}),
generate: (item, key, callback) => callback(null, null)
})
}

let spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
const spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
if (type === 'close') { callback() }
})
let spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
let spawn = jasmine.createSpy('spawn').and.callFake(() => {
const spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
const spawn = jasmine.createSpy('spawn').and.callFake(() => {
return {
on: spawnOnSpy,
stderr: {
Expand All @@ -48,10 +48,10 @@ exports.loadLib = (file) => {
})

// Load the library module.
let lib = proxyquire(`../lib/${file}`, {
const lib = proxyquire(`../lib/${file}`, {
'./providers/aws': providerStub,
'./providers/gcp': providerStub,
async: async,
async,
child_process: { spawn }, // eslint-disable-line camelcase
'fs-extra': fs
})
Expand Down
Loading

0 comments on commit 78e683a

Please sign in to comment.