Skip to content

Commit

Permalink
add default blueprint that adds node: current to targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Sep 18, 2020
1 parent 18aa8b2 commit 6f929b5
Showing 1 changed file with 44 additions and 0 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);
}
};

0 comments on commit 6f929b5

Please sign in to comment.