Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ utils._readFileWithPromise = function readFileWithPromise(file) {
return new Promise((resolve, reject) => {
fs.readFile(file, 'utf8', function(err, data) {
if (err) {
reject(err);
return reject(err);
}

resolve(data);
});
});
Expand All @@ -29,11 +28,11 @@ utils._readFileWithPromise = function readFileWithPromise(file) {
* @param {string} pattern - Glob file pattern
* @returns Promise
*/
function globWithPromsie(pattern) {
function globWithPromise(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, function(err, files) {
if (err) {
reject(err);
return reject(err);
}

if (files.length === 0) {
Expand Down Expand Up @@ -153,7 +152,7 @@ utils.sortCategoryBy = function sortCategoryBy(categories, sortOrder) {
utils.readFileGlobs = async function readFileGlobs(patterns, callback) {
patterns = (!Array.isArray(patterns) ? [patterns] : patterns);
let globPromises = await patterns.map(async (pattern) => {
return globWithPromsie(pattern);
return globWithPromise(pattern);
});

return Promise.all(globPromises)
Expand All @@ -162,7 +161,7 @@ utils.readFileGlobs = async function readFileGlobs(patterns, callback) {
// fileList is an array of arrays of files
// e.g. [ [fileOne, fileTwo], [fileThree, fileFour], ...]
let readFilePromises = await fileList.map(async (files) => {
return await utils.readFiles(files)
return await utils.readFiles(files);
});

return Promise.all(readFilePromises);
Expand All @@ -187,24 +186,27 @@ utils.readFileGlobs = async function readFileGlobs(patterns, callback) {
* @param {function} callback - Callback to execute for each read file.
* @returns {Promise}
*/
utils.readFiles = async function readFiles(files, callback) {
if (!files || (Array.isArray(files) && !files.length)) return Promise.resolve();
utils.readFiles = function readFiles(files, callback) {
if (!files || (Array.isArray(files) && !files.length)) return Promise.resolve([]);

files = (!Array.isArray(files) ? [files] : files);
let promises = await Promise.all(files.map(async (file) => {
return Promise.all(files.map(async (file) => {
let data = await utils._readFileWithPromise(file);
return [data, file];
}));

return Promise.all(promises).then(files => {
if (callback) {
files.forEach(function(data) {
callback.apply(null, data);
});
}

return files;
})
}))
.then(async files => {
if (callback) {
const promises = [];
files.forEach(function(data) {
const result = callback.apply(null, data);
if ('object' === typeof result && result.then) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. How are you using the callback function in this case? I'm curious what the returned Promise is doing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, wouldn't it be easier to ask if it was Promise? if (result instanceof Promise)

promises.push(result);
}
});
await Promise.all(promises);
}
return files;
});
}

/**
Expand Down
50 changes: 39 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 50 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
{
"name": "livingcss",
"version": "6.0.3",
"description": "Generate a style guide using comment driven content creation",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=lcov --reporter=text mocha"
"_from": "livingcss",
"_id": "[email protected]",
"_inBundle": false,
"_integrity": "sha512-CqClAsCzLbwePqpFfieEvwNgevgSLCbCcTFvGnlP2ewvVcVa8dmKtdtcYt+DrOjCpoTYgzKnpgyhhfiCDjdZkQ==",
"_location": "/livingcss",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "livingcss",
"name": "livingcss",
"escapedName": "livingcss",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"repository": {
"type": "git",
"url": "https://github.com/straker/livingcss.git"
},
"keywords": [
"style",
"guide",
"generator",
"css"
"_requiredBy": [
"#DEV:/",
"#USER"
],
"author": "Steven Lambert <[email protected]> (http://sklambert.com/)",
"license": "MIT",
"_resolved": "https://registry.npmjs.org/livingcss/-/livingcss-6.0.3.tgz",
"_shasum": "7f2eeb07dd42734029f2962ad1b8751cab252eb2",
"_spec": "livingcss",
"_where": "/Users/matmar10/Projects/Blossom/bootstrap-theme",
"author": {
"name": "Steven Lambert",
"email": "[email protected]",
"url": "http://sklambert.com/"
},
"bugs": {
"url": "https://github.com/straker/livingcss/issues"
},
"homepage": "https://github.com/straker/livingcss",
"bundleDependencies": false,
"dependencies": {
"comment-parser": "^0.5.4",
"glob": "^7.1.3",
Expand All @@ -31,8 +41,11 @@
"mkdirp": "^0.5.1",
"normalize-newline": "^3.0.0"
},
"deprecated": false,
"description": "Generate a style guide using comment driven content creation",
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.3",
"gulp": "^4.0.1",
"gulp-connect": "^5.7.0",
Expand All @@ -49,5 +62,23 @@
"nyc": "^14.1.0",
"proxyquire": "^1.8.0",
"sinon": "^4.2.2"
}
},
"homepage": "https://github.com/straker/livingcss",
"keywords": [
"style",
"guide",
"generator",
"css"
],
"license": "MIT",
"main": "index.js",
"name": "livingcss",
"repository": {
"type": "git",
"url": "git+https://github.com/straker/livingcss.git"
},
"scripts": {
"test": "nyc --reporter=lcov --reporter=text mocha"
},
"version": "6.0.3"
}
Loading