Skip to content

Commit

Permalink
fix(*): fix case where --out file is in a non-existing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Dec 11, 2019
1 parent 9e0bb0b commit 9caa413
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test": "jasmine test/*.js"
},
"dependencies": {
"mkdirp": "^0.5.1",
"parse5": "^5.1.1"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const parse5 = require('parse5');
const treeAdapter = require('parse5/lib/tree-adapters/default');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');

function findElementByName(d, name) {
if (treeAdapter.isTextNode(d)) return undefined;
Expand Down Expand Up @@ -106,7 +107,12 @@ function parseArgs(cmdParams) {
return {inputFile, outputFile, assets, rootDirs};
}

function main(params, read = fs.readFileSync, write = fs.writeFileSync, timestamp = Date.now) {
function mkdirpWrite(filePath, value) {
mkdirp.sync(path.dirname(filePath));
fs.writeFileSync(filePath, value);
}

function main(params, read = fs.readFileSync, write = mkdirpWrite, timestamp = Date.now) {
const {inputFile, outputFile, assets, rootDirs} = parseArgs(params);

const jsFiles = assets.filter(s => /\.m?js$/i.test(s));
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ minimist-options@^3.0.1:
arrify "^1.0.1"
is-plain-obj "^1.1.0"

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

minimist@^1.1.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
Expand All @@ -603,6 +608,13 @@ minimist@~0.0.1:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=

mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"

modify-values@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022"
Expand Down

0 comments on commit 9caa413

Please sign in to comment.