Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"webpackOptions": {
"entry": "ok",
"output": {
"filename": "[name].js"
"filename": "'[name].js'"
},
"context": "path.join(__dirname, \"src\")",
"plugins": [
Expand Down
44 changes: 31 additions & 13 deletions lib/ast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@
const utils = require("../utils/ast-utils");

module.exports = function astTransform(j, ast, value, action, key) {
const node = utils.findRootNodesByName(j, ast, key);
if(node.size() != 0) {
// push to existing key
} else {
// get module.exports prop
const root = ast.find(j.ObjectExpression).filter( p => {
return utils.safeTraverse(p, ['parentPath','value','left', 'object', 'name']) === 'module' && utils.safeTraverse(p,['parentPath', 'value', 'left', 'property', 'name']) === 'exports';
}).filter(p => p.value.properties);
const node = utils.findRootNodesByName(j, ast, key);
if (node.size() !== 0) {
// push to existing key
} else {
// get module.exports prop
const root = ast
.find(j.ObjectExpression)
.filter(p => {
return (
utils.safeTraverse(p, [
"parentPath",
"value",
"left",
"object",
"name"
]) === "module" &&
utils.safeTraverse(p, [
"parentPath",
"value",
"left",
"property",
"name"
]) === "exports"
);
})
.filter(p => p.value.properties);

return root.forEach(p => {
utils.addProperty(j, p, key, value);
});
}
}
return root.forEach(p => {
utils.addProperty(j, p, key, value);
});
}
};
3 changes: 2 additions & 1 deletion lib/generate-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const yeoman = require("yeoman-environment");
const PluginGenerator = require("../generators/plugin-generator").PluginGenerator;
const PluginGenerator = require("../generators/plugin-generator")
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be destructured :)

const { PluginGenerator } = require("../generators/plugin-generator")

Copy link
Member Author

Choose a reason for hiding this comment

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

Im not done

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah and in the meantime we give feedback while you develop :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, just don't want you to do extra work 🙌🤙

.PluginGenerator;

/**
* Runs a yeoman generator to create a new webpack plugin project
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/init-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ module.exports = class InitGenerator extends Generator {
Confirm("prodConfirm", "Are you going to use this in production?")
]);
})
.then(prodConfirmAnswer => this.isProd = prodConfirmAnswer["prodConfirm"])
.then(
prodConfirmAnswer => (this.isProd = prodConfirmAnswer["prodConfirm"])
)
.then(() => {
return this.prompt([
Confirm("babelConfirm", "Will you be using ES2015?")
Expand Down Expand Up @@ -383,7 +385,7 @@ module.exports = class InitGenerator extends Generator {
done();
});
}
/*
/*
installPlugins() {
const asyncNamePrompt = this.async();
const defaultName = this.isProd ? "prod" : "config";
Expand Down
4 changes: 2 additions & 2 deletions lib/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const propTypes = require("../utils/prop-types");
*/

function mapOptionsToTransform(config) {
return Object.keys(config.webpackOptions).filter(k => propTypes.has(k))
return Object.keys(config.webpackOptions).filter(k => propTypes.has(k));
}

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports = function runTransform(webpackProperties, action) {
const transformAction = action || null;

return pEachSeries(transformations, f => {
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
})
.then(_ => {
let configurationName;
Expand Down
8 changes: 7 additions & 1 deletion lib/init/transformations/top-scope/top-scope.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

const defineTest = require("../../../utils/defineTest");

defineTest(__dirname, "top-scope", "top-scope-0", ["const test = 'me';"], "init");
defineTest(
__dirname,
"top-scope",
"top-scope-0",
["const test = 'me';"],
"init"
);
defineTest(
__dirname,
"top-scope",
Expand Down
Loading