Skip to content

Commit

Permalink
enhancements: revise anti pattern for promise
Browse files Browse the repository at this point in the history
Thanks to Sindre Sørhus for this fix. Object references are now making
sure our callbacks are held, and removed the return of the promise and
rather used the object we want to return.
  • Loading branch information
evenstensberg committed May 4, 2017
1 parent 0344e6a commit 663133a
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions lib/creator/yeoman/utils/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const InputValidate = require('webpack-addons').InputValidate;
const validate = require('./validate');

module.exports = (self, answer) => {
let webpackEntryPoint;
let entryIdentifiers;
let entryProperties;

let result;

const validateProperties = (value) => {
const valLength = value.length;
const values = value.split(',');
Expand All @@ -17,48 +20,44 @@ module.exports = (self, answer) => {
return 'You forgot to add one or more property to your entry point!';
}
};
return new Promise( (resolve) => {
let webpackEntryPoint;

if(answer['entryType'] == 'Multiple') {
self.prompt([
if(answer['entryType'] == 'Multiple') {
result = self.prompt([
InputValidate(
'multipleEntries',
'Write the name you want for your modules seperated by comma',
validate
)
]).then( (multipleEntriesAnswer) => {
webpackEntryPoint = {};
entryIdentifiers = multipleEntriesAnswer['multipleEntries'].split(',');
return self.prompt([
InputValidate(
'multipleEntries',
'Write the name you want for your modules seperated by comma',
validate
'objectProperties',
'Write the location of those modules seperated by comma',
validateProperties
)
]).then( (multipleEntriesAnswer) => {
webpackEntryPoint = {};
entryIdentifiers = multipleEntriesAnswer['multipleEntries'].split(',');
self.prompt([
InputValidate(
'objectProperties',
'Write the location of those modules seperated by comma',
validateProperties
)
]).then( (objectPropAnswer) => {
entryProperties = objectPropAnswer['objectProperties'].split(',');
for(let k = 0; k < entryIdentifiers.length; k++) {
if(entryProperties[k].charAt(0) == '(' || entryProperties[k].charAt(0) == '[') {
webpackEntryPoint[entryIdentifiers[k]] = entryProperties[k];
} else {
webpackEntryPoint[entryIdentifiers[k]] = `'${entryProperties[k]}.js'`;
}
]).then( (objectPropAnswer) => {
entryProperties = objectPropAnswer['objectProperties'].split(',');
for(let k = 0; k < entryIdentifiers.length; k++) {
if(entryProperties[k].charAt(0) == '(' || entryProperties[k].charAt(0) == '[') {
webpackEntryPoint[entryIdentifiers[k]] = entryProperties[k];
} else {
webpackEntryPoint[entryIdentifiers[k]] = `'${entryProperties[k]}.js'`;
}
resolve(webpackEntryPoint);
});
});
}
else {
self.prompt([
InputValidate(
'singularEntry',
'Write the location of module you would like to use',
validate
)
]).then( (singularAnswer) => {
resolve(`'${singularAnswer['singularEntry']}.js'`);
return webpackEntryPoint;
}
});
}
});
});
}
else {
result = self.prompt([
InputValidate(
'singularEntry',
'Write the location of module you would like to use',
validate
)
]).then( (singularAnswer) => `'${singularAnswer['singularEntry']}.js'`);
}
return result;
};

0 comments on commit 663133a

Please sign in to comment.