-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add default blueprint that adds
node: current
to targets
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |