From 1071cd0cc4d169332e1f2a7250905a8f87152197 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 24 Jul 2020 17:04:07 +0100 Subject: [PATCH 1/3] make sure that you a prompted to add `node: current` to targets --- .../blueprints/ember-cli-fastboot/index.js | 29 +++++++++++++++---- packages/ember-cli-fastboot/package.json | 4 ++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js b/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js index db6f60f89..b146642fc 100644 --- a/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js +++ b/packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js @@ -1,6 +1,9 @@ /* eslint-env node */ const recast = require('recast'); const { readFileSync, writeFileSync } = require('fs'); +const { join, dirname } = require('path') +const tmp = require('tmp'); +const mkdirp = require('mkdirp'); module.exports = { description: '', @@ -8,13 +11,25 @@ module.exports = { // no-op }, - afterInstall() { - let targetsFile = './config/targets.js' + filesPath() { + return this._filesPath; + }, + + _targetsFile(project) { + let configPath = 'config'; - if(this.project.isEmberCLIAddon()) { - targetsFile = './tests/dummy/config/targets.js'; + if (project.pkg['ember-addon'] && project.pkg['ember-addon']['configPath']) { + configPath = project.pkg['ember-addon']['configPath']; } + return join(configPath, 'targets.js'); + }, + + install(options) { + this._filesPath = tmp.dirSync().name; + + const targetsFile = this._targetsFile(options.project); + const targetsAst = recast.parse(readFileSync(targetsFile)); recast.visit(targetsAst, { @@ -39,6 +54,10 @@ module.exports = { } }); - writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code); + let newFile = join(this._filesPath, targetsFile); + mkdirp.sync(dirname(newFile)); + writeFileSync(newFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code); + + return this._super.install.apply(this, arguments); } }; diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index f350d5fad..61168284c 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -39,8 +39,10 @@ "fs-extra": "^7.0.0", "json-stable-stringify": "^1.0.1", "md5-hex": "^2.0.0", + "mkdirp": "^1.0.4", "recast": "^0.19.1", - "silent-error": "^1.1.0" + "silent-error": "^1.1.0", + "tmp": "^0.2.1" }, "devDependencies": { "body-parser": "^1.18.3", From 204b6ea23e74f59e26ba1584c0099ea409d0630b Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sat, 25 Jul 2020 23:17:41 +0100 Subject: [PATCH 2/3] WIP: start a test for the blueprint --- packages/ember-cli-fastboot/package.json | 1 + .../test/default-blueprint-test.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 packages/ember-cli-fastboot/test/default-blueprint-test.js diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index 61168284c..ff574faa1 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -30,6 +30,7 @@ "broccoli-plugin": "^1.3.1", "chalk": "^2.4.1", "ember-cli-babel": "^7.1.0", + "ember-cli-blueprint-test-helpers": "^0.19.2", "ember-cli-lodash-subset": "2.0.1", "ember-cli-preprocess-registry": "^3.1.2", "ember-cli-version-checker": "^3.0.0", diff --git a/packages/ember-cli-fastboot/test/default-blueprint-test.js b/packages/ember-cli-fastboot/test/default-blueprint-test.js new file mode 100644 index 000000000..3a50ac6e3 --- /dev/null +++ b/packages/ember-cli-fastboot/test/default-blueprint-test.js @@ -0,0 +1,23 @@ +'use strict'; + +const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); +const setupTestHooks = blueprintHelpers.setupTestHooks; +const emberNew = blueprintHelpers.emberNew; +const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; + +const expect = require('ember-cli-blueprint-test-helpers/chai').expect; + +describe('Acceptance: ember generate and destroy default-blueprint', function() { + setupTestHooks(this); + + it('default-blueprint foo', async function() { + let args = ['ember-cli-fastboot']; + + // pass any additional command line options in the arguments array + await emberNew(); + + const file = await emberGenerateDestroy(args); + + expect(file('config/targets.js')).to.contain(`node: 'current'`); + }); +}); From 74b29f19aeb676ccfd621883f674f0e128984f6d Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 18 Sep 2020 16:29:53 +0100 Subject: [PATCH 3/3] wip more stuff --- packages/ember-cli-fastboot/.eslintrc.js | 13 ++++++++ packages/ember-cli-fastboot/package.json | 2 +- .../test/default-blueprint-test.js | 33 +++++++++++++++---- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/ember-cli-fastboot/.eslintrc.js b/packages/ember-cli-fastboot/.eslintrc.js index 55bb9d083..91fe4fc8f 100644 --- a/packages/ember-cli-fastboot/.eslintrc.js +++ b/packages/ember-cli-fastboot/.eslintrc.js @@ -54,6 +54,19 @@ module.exports = { env: { embertest: true } + }, + + // mocha test files + { + files: ['test/**/*.js'], + env: { + node: true, + mocha: true + }, + plugins: ['node'], + rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { + // add your custom rules and overrides for node files here + }) } ] }; diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index ff574faa1..067ec836a 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -30,7 +30,7 @@ "broccoli-plugin": "^1.3.1", "chalk": "^2.4.1", "ember-cli-babel": "^7.1.0", - "ember-cli-blueprint-test-helpers": "^0.19.2", + "ember-cli-blueprint-test-helpers": "mansona/ember-cli-blueprint-test-helpers#fix-ember-generate-options", "ember-cli-lodash-subset": "2.0.1", "ember-cli-preprocess-registry": "^3.1.2", "ember-cli-version-checker": "^3.0.0", diff --git a/packages/ember-cli-fastboot/test/default-blueprint-test.js b/packages/ember-cli-fastboot/test/default-blueprint-test.js index 3a50ac6e3..391bb3fe5 100644 --- a/packages/ember-cli-fastboot/test/default-blueprint-test.js +++ b/packages/ember-cli-fastboot/test/default-blueprint-test.js @@ -1,23 +1,44 @@ 'use strict'; const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); -const setupTestHooks = blueprintHelpers.setupTestHooks; -const emberNew = blueprintHelpers.emberNew; -const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; + +const { emberGenerate, emberNew, setupTestHooks } = blueprintHelpers; + +const MockUI = require('console-ui/mock'); const expect = require('ember-cli-blueprint-test-helpers/chai').expect; -describe('Acceptance: ember generate and destroy default-blueprint', function() { +describe.only('Acceptance: ember generate and destroy default-blueprint', function() { setupTestHooks(this); it('default-blueprint foo', async function() { let args = ['ember-cli-fastboot']; + // process.stdout.on('data', function(data) { + // console.log('face', data.toString()); + // process.stdin.writeLine('y'); + // // process.stdout.write(data); + // }); + + + // pass any additional command line options in the arguments array await emberNew(); - const file = await emberGenerateDestroy(args); + // let ui = new MockUI(); + + // let interval = setInterval(() => { + // ui.inputStream.write('y\n\r'); + // }, 2000); + + const ember = await emberGenerate(args); + + setTimeout(() => { + ember.inputStream.write('y\n'); + }, 4000) + + // clearInterval(interval); - expect(file('config/targets.js')).to.contain(`node: 'current'`); + // expect(file('config/targets.js')).to.contain(`node: 'current'`); }); });