Skip to content

Commit

Permalink
Merge pull request #770 from mansona/add-node-source
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Sep 18, 2020
2 parents 9ac76eb + 6f929b5 commit 75f436c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
44 changes: 44 additions & 0 deletions packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-env node */
const recast = require('recast');
const { readFileSync, writeFileSync } = require('fs');

module.exports = {
description: '',
normalizeEntityName() {
// no-op
},

afterInstall() {
let targetsFile = './config/targets.js'

if(this.project.isEmberCLIAddon()) {
targetsFile = './tests/dummy/config/targets.js';
}

const targetsAst = recast.parse(readFileSync(targetsFile));

recast.visit(targetsAst, {
visitAssignmentExpression (path) {
let node = path.node;

if (node.left.object.name === 'module' && node.left.property.name === 'exports') {
let nodeProperty = node.right.properties.find(property => property.key.name === 'node');

if(!nodeProperty) {
let builders = recast.types.builders;
nodeProperty = builders.property(
'init',
builders.identifier('node'),
builders.literal('current')
);
node.right.properties.push(nodeProperty);
}
}

this.traverse(path);
}
});

writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code);
}
};
1 change: 1 addition & 0 deletions packages/ember-cli-fastboot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"fs-extra": "^7.0.0",
"json-stable-stringify": "^1.0.1",
"md5-hex": "^2.0.0",
"recast": "^0.19.1",
"silent-error": "^1.1.0"
},
"devDependencies": {
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11772,7 +11772,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.0.tgz#c59341c9723f414c452975564c7c00a68d58acd2"
integrity sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==

[email protected]:
[email protected], parse5@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178"
integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==
Expand All @@ -11784,11 +11784,6 @@ parse5@^3.0.3:
dependencies:
"@types/node" "*"

parse5@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178"
integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==

[email protected]:
version "0.0.5"
resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d"
Expand Down Expand Up @@ -12467,6 +12462,16 @@ recast@^0.18.1:
private "^0.1.8"
source-map "~0.6.1"

recast@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.19.1.tgz#555f3612a5a10c9f44b9a923875c51ff775de6c8"
integrity sha512-8FCjrBxjeEU2O6I+2hyHyBFH1siJbMBLwIRvVr1T3FD2cL754sOaJDsJ/8h3xYltasbJ8jqWRIhMuDGBSiSbjw==
dependencies:
ast-types "0.13.3"
esprima "~4.0.0"
private "^0.1.8"
source-map "~0.6.1"

rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
Expand Down

0 comments on commit 75f436c

Please sign in to comment.