ember-template-recast
Advanced tools
Comparing version 3.2.3 to 3.2.4
@@ -0,1 +1,17 @@ | ||
## v3.2.4 (2019-10-16) | ||
#### :bug: Bug Fix | ||
* [#147](https://github.com/ember-template-lint/ember-template-recast/pull/147) Fix `ember-template-recast` bin script file selection for Windows users ([@rwjblue](https://github.com/rwjblue)) | ||
#### :house: Internal | ||
* [#143](https://github.com/ember-template-lint/ember-template-recast/pull/143) Add Windows and macOS CI testing. ([@rwjblue](https://github.com/rwjblue)) | ||
* [#146](https://github.com/ember-template-lint/ember-template-recast/pull/146) Refactor runner to leverage async/await. ([@rwjblue](https://github.com/rwjblue)) | ||
* [#145](https://github.com/ember-template-lint/ember-template-recast/pull/145) Use `execa` instead of `child_process.spawn` in tests. ([@rwjblue](https://github.com/rwjblue)) | ||
* [#144](https://github.com/ember-template-lint/ember-template-recast/pull/144) Remove TravisCI setup. ([@rwjblue](https://github.com/rwjblue)) | ||
* [#142](https://github.com/ember-template-lint/ember-template-recast/pull/142) Add GitHub Actions CI. ([@rwjblue](https://github.com/rwjblue)) | ||
* [#141](https://github.com/ember-template-lint/ember-template-recast/pull/141) Add tests ensuring line endings are preserved properly. ([@rwjblue](https://github.com/rwjblue)) | ||
#### Committers: 1 | ||
- Robert Jackson ([@rwjblue](https://github.com/rwjblue)) | ||
## v3.2.3 (2019-10-15) | ||
@@ -2,0 +18,0 @@ |
{ | ||
"name": "ember-template-recast", | ||
"version": "3.2.3", | ||
"version": "3.2.4", | ||
"description": "Non-destructive template transformer.", | ||
@@ -37,2 +37,3 @@ "keywords": [ | ||
"ora": "^4.0.2", | ||
"slash": "^3.0.0", | ||
"tmp": "^0.1.0", | ||
@@ -48,2 +49,3 @@ "workerpool": "^5.0.1" | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"execa": "^3.1.0", | ||
"lerna-changelog": "^0.8.2", | ||
@@ -50,0 +52,0 @@ "prettier": "^1.18.2", |
const http = require('http'); | ||
const https = require('https'); | ||
const { writeFile } = require('fs'); | ||
const { resolve, extname, join } = require('path'); | ||
const { writeFileSync } = require('fs'); | ||
const { resolve } = require('path'); | ||
const colors = require('colors/safe'); | ||
const slash = require('slash'); | ||
const globby = require('globby'); | ||
@@ -109,19 +110,23 @@ const ora = require('ora'); | ||
module.exports = function run(transformFile, filePaths, options) { | ||
module.exports = async function run(transformFile, filePaths, options) { | ||
const logger = options.silent ? silentLogger : verboseLogger; | ||
const stats = new StatsCollector(logger); | ||
return Promise.all([loadTransform(transformFile), getAllFiles(filePaths)]) | ||
.then(([transformPath, files]) => spawnWorkers(transformPath, files, options, stats, logger)) | ||
.then(() => { | ||
logger.stopSpinner({ | ||
symbol: '🎉', | ||
text: 'Complete!', | ||
}); | ||
stats.print(); | ||
}) | ||
.catch(err => { | ||
logger.stopSpinner(); | ||
handleError(err, logger); | ||
try { | ||
const [transformPath, files] = await Promise.all([ | ||
loadTransform(transformFile), | ||
getAllFiles(filePaths), | ||
]); | ||
await spawnWorkers(transformPath, files, options, stats, logger); | ||
logger.stopSpinner({ | ||
symbol: '🎉', | ||
text: 'Complete!', | ||
}); | ||
stats.print(); | ||
} catch (err) { | ||
logger.stopSpinner(); | ||
handleError(err, logger); | ||
} | ||
}; | ||
@@ -134,3 +139,3 @@ | ||
*/ | ||
function loadTransform(transformFile) { | ||
async function loadTransform(transformFile) { | ||
const isRemote = transformFile.startsWith('http'); | ||
@@ -142,10 +147,8 @@ | ||
return new Promise((resolve, reject) => { | ||
downloadFile(transformFile).then(contents => { | ||
const filePath = tmp.fileSync(); | ||
writeFile(filePath.name, contents, 'utf8', err => { | ||
err ? reject(err) : resolve(filePath.name); | ||
}); | ||
}); | ||
}); | ||
const contents = await downloadFile(transformFile); | ||
const filePath = tmp.fileSync(); | ||
writeFileSync(filePath.name, contents, 'utf8'); | ||
return filePath.name; | ||
} | ||
@@ -176,19 +179,20 @@ | ||
*/ | ||
function getAllFiles(paths) { | ||
const patterns = paths.map(path => { | ||
const ext = extname(path); | ||
if (ext === '') { | ||
path = join(path, '**', '*.{hbs,handlebars}'); | ||
} | ||
return path; | ||
async function getAllFiles(paths) { | ||
const files = await globby(paths, { | ||
// must specify a properly escaped `cwd` because globby infers from | ||
// process.cwd() directly and without correcting back to posix paths | ||
// asserts if the individual file path isn't "in" the cwd | ||
// https://github.com/sindresorhus/globby/pull/137 | ||
cwd: slash(process.cwd()), | ||
expandDirectories: { | ||
extensions: ['hbs', 'handlebars'], | ||
}, | ||
absolute: true, | ||
gitignore: true, | ||
}); | ||
if (files.length < 1) { | ||
throw new NoFilesError(); | ||
} | ||
return globby(patterns, { absolute: true, gitignore: true }).then(files => { | ||
if (files.length < 1) { | ||
throw new NoFilesError(); | ||
} | ||
return files; | ||
}); | ||
return files; | ||
} | ||
@@ -206,3 +210,3 @@ | ||
*/ | ||
function spawnWorkers(transformPath, files, { cpus, dry }, stats, logger) { | ||
async function spawnWorkers(transformPath, files, { cpus, dry }, stats, logger) { | ||
const processCount = Math.min(files.length, cpus); | ||
@@ -218,15 +222,14 @@ | ||
let i = 0; | ||
const worker = queue.async.asyncify(file => { | ||
return pool.exec('run', [transformPath, file, { dry }]).then(message => { | ||
stats.update(message); | ||
logger.updateSpinner(`Processed ${i++} files`); | ||
}); | ||
const worker = queue.async.asyncify(async file => { | ||
const message = await pool.exec('run', [transformPath, file, { dry }]); | ||
stats.update(message); | ||
logger.updateSpinner(`Processed ${i++} files`); | ||
}); | ||
return queue(worker, files, cpus) | ||
.catch(err => { | ||
pool.terminate(); | ||
return Promise.reject(err); | ||
}) | ||
.then(() => pool.terminate()); | ||
try { | ||
await queue(worker, files, cpus); | ||
} finally { | ||
pool.terminate(); | ||
} | ||
} | ||
@@ -233,0 +236,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59714
9
12
+ Addedslash@^3.0.0