Skip to content

Commit 1988889

Browse files
author
Kelly Selden
committed
resets blueprint when config file
1 parent 96d16ac commit 1988889

10 files changed

Lines changed: 219 additions & 57 deletions

File tree

src/choose-blueprint-updates.js

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,103 @@ function formatBlueprintLine({
1515
return `${name}, current: ${currentVersion}, latest: ${latestVersion}`;
1616
}
1717

18+
async function chooseBlueprint({
19+
choicesByName,
20+
message
21+
}) {
22+
let answer = await inquirer.prompt([{
23+
type: 'list',
24+
message,
25+
name: 'blueprint',
26+
choices: Object.values(choicesByName).map(({ choice }) => choice)
27+
}]);
28+
29+
return choicesByName[answer.blueprint];
30+
}
31+
1832
async function chooseBlueprintUpdates({
1933
cwd,
20-
emberCliUpdateJson
34+
emberCliUpdateJson,
35+
reset
2136
}) {
2237
let to;
23-
let blueprint;
38+
let existingBlueprint;
39+
let blueprintUpdates;
40+
let areAllUpToDate;
2441

2542
let { blueprints } = emberCliUpdateJson;
2643

27-
let blueprintUpdates = await checkForBlueprintUpdates({
28-
cwd,
29-
blueprints
30-
});
31-
32-
let areAllUpToDate = blueprintUpdates.every(blueprintUpdate => blueprintUpdate.isUpToDate);
33-
if (!areAllUpToDate) {
34-
let choicesByName = blueprintUpdates.reduce((choices, blueprintUpdate) => {
35-
let name = formatBlueprintLine(blueprintUpdate);
44+
if (reset) {
45+
let choicesByName = blueprints.reduce((choices, blueprint) => {
46+
let name = blueprint.packageName;
3647
choices[name] = {
37-
blueprintUpdate,
48+
blueprint,
3849
choice: {
39-
name,
40-
disabled: blueprintUpdate.isUpToDate
50+
name
4151
}
4252
};
4353
return choices;
4454
}, {});
4555

46-
let answer = await inquirer.prompt([{
47-
type: 'list',
48-
message: 'Blueprint updates have been found. Which one would you like to update?',
49-
name: 'blueprint',
50-
choices: Object.values(choicesByName).map(({ choice }) => choice)
51-
}]);
52-
53-
let { blueprintUpdate } = choicesByName[answer.blueprint];
54-
55-
let existingBlueprint = findBlueprint(emberCliUpdateJson, blueprintUpdate.packageName, blueprintUpdate.name);
56-
blueprint = loadSafeBlueprint(existingBlueprint);
57-
58-
let latestVersion = `${blueprintUpdate.latestVersion} (latest)`;
59-
60-
answer = await inquirer.prompt([{
61-
type: 'list',
62-
message: 'Do you want the latest version?',
63-
name: 'choice',
64-
choices: [
65-
latestVersion,
66-
'SemVer string'
67-
]
68-
}]);
69-
70-
if (answer.choice === latestVersion) {
71-
to = toDefault;
72-
} else {
73-
answer = await inquirer.prompt([{
74-
type: 'input',
75-
message: 'What version?',
76-
name: 'semver'
56+
existingBlueprint = (await chooseBlueprint({
57+
choicesByName,
58+
message: 'Which blueprint would you like to reset?'
59+
})).blueprint;
60+
} else {
61+
blueprintUpdates = await checkForBlueprintUpdates({
62+
cwd,
63+
blueprints
64+
});
65+
66+
areAllUpToDate = blueprintUpdates.every(blueprintUpdate => blueprintUpdate.isUpToDate);
67+
if (!areAllUpToDate) {
68+
let choicesByName = blueprintUpdates.reduce((choices, blueprintUpdate) => {
69+
let name = formatBlueprintLine(blueprintUpdate);
70+
choices[name] = {
71+
blueprintUpdate,
72+
choice: {
73+
name,
74+
disabled: blueprintUpdate.isUpToDate
75+
}
76+
};
77+
return choices;
78+
}, {});
79+
80+
let { blueprintUpdate } = await chooseBlueprint({
81+
choicesByName,
82+
message: 'Blueprint updates have been found. Which one would you like to update?'
83+
});
84+
85+
existingBlueprint = findBlueprint(emberCliUpdateJson, blueprintUpdate.packageName, blueprintUpdate.name);
86+
87+
let latestVersion = `${blueprintUpdate.latestVersion} (latest)`;
88+
89+
let answer = await inquirer.prompt([{
90+
type: 'list',
91+
message: 'Do you want the latest version?',
92+
name: 'choice',
93+
choices: [
94+
latestVersion,
95+
'SemVer string'
96+
]
7797
}]);
7898

79-
to = answer.semver;
99+
if (answer.choice === latestVersion) {
100+
to = toDefault;
101+
} else {
102+
answer = await inquirer.prompt([{
103+
type: 'input',
104+
message: 'What version?',
105+
name: 'semver'
106+
}]);
107+
108+
to = answer.semver;
109+
}
80110
}
81111
}
82112

113+
let blueprint = loadSafeBlueprint(existingBlueprint);
114+
83115
return {
84116
blueprintUpdates,
85117
areAllUpToDate,

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ module.exports = async function emberCliUpdate({
108108
to: _to
109109
} = await chooseBlueprintUpdates({
110110
cwd,
111-
emberCliUpdateJson
111+
emberCliUpdateJson,
112+
reset
112113
});
113114

114115
if (areAllUpToDate) {
@@ -119,7 +120,9 @@ All blueprints are up-to-date!`;
119120
}
120121

121122
blueprint = _blueprint;
122-
to = _to;
123+
if (!reset) {
124+
to = _to;
125+
}
123126
}
124127
}
125128

test/acceptance/ember-cli-update-test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,55 @@ describe(function() {
311311
assertNoUnstaged(status);
312312
});
313313

314+
it('can reset from multiple blueprint', async function() {
315+
let {
316+
location,
317+
version: to
318+
} = (await loadSafeBlueprintFile('test/fixtures/blueprint/app/local-app/reset/my-app/config/ember-cli-update.json')).blueprints[1];
319+
320+
let {
321+
ps,
322+
promise
323+
} = await merge({
324+
fixturesPath: 'test/fixtures/blueprint/app/local-app/local',
325+
commitMessage: 'my-app',
326+
reset: true,
327+
to,
328+
async beforeMerge() {
329+
await initBlueprint({
330+
fixturesPath: 'test/fixtures/blueprint/app/local',
331+
resolvedFrom: tmpPath,
332+
relativeDir: location
333+
});
334+
}
335+
});
336+
337+
let whichBlueprint = new Promise(resolve => {
338+
function whichBlueprint(data) {
339+
let str = data.toString();
340+
if (str.includes('Which blueprint would you like to reset?')) {
341+
let down = '\u001b[B';
342+
let enter = '\n';
343+
ps.stdin.write(`${down}${enter}`);
344+
ps.stdout.removeListener('data', whichBlueprint);
345+
resolve();
346+
}
347+
}
348+
ps.stdout.on('data', whichBlueprint);
349+
});
350+
await whichBlueprint;
351+
352+
let {
353+
status
354+
} = await promise;
355+
356+
fixtureCompare({
357+
mergeFixtures: 'test/fixtures/blueprint/app/local-app/reset/my-app'
358+
});
359+
360+
assertNoStaged(status);
361+
});
362+
314363
it('can init the default blueprint', async function() {
315364
this.timeout(5 * 60 * 1000);
316365

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123123
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"schemaVersion": 0,
3+
"packages": [
4+
{
5+
"name": "ember-cli-update-git-blueprint-test",
6+
"location": "../legacy-blueprint",
7+
"version": "0.0.1",
8+
"blueprints": [
9+
{
10+
"name": "ember-cli-update-git-blueprint-test",
11+
"isBaseBlueprint": true,
12+
"options": [
13+
"--custom-option=123"
14+
]
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "my-app",
3+
"version": "0.0.0"
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"schemaVersion": 0,
3+
"packages": [
4+
{
5+
"name": "ember-cli-update-npm-blueprint-test",
6+
"version": "0.0.24",
7+
"blueprints": [
8+
{
9+
"name": "ember-cli-update-npm-blueprint-test",
10+
"isBaseBlueprint": true
11+
}
12+
]
13+
},
14+
{
15+
"name": "ember-cli-update-git-blueprint-test",
16+
"location": "../local-blueprint",
17+
"version": "0.0.1",
18+
"blueprints": [
19+
{
20+
"name": "ember-cli-update-git-blueprint-test",
21+
"options": [
22+
"--supplied-option=foo"
23+
]
24+
}
25+
]
26+
}
27+
]
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my-app
2+
ember-cli-update-git-blueprint-test
3+
0.0.1
4+
foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.24

test/integration/index-test.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,6 @@ describe(function() {
200200
commitMessage: 'my-app',
201201
reset: true,
202202
to: '2.11.1'
203-
// test the resetting logic of ember-cli-update.json
204-
// no longer a valid blueprint name
205-
// blueprint: 'ember-cli',
206-
// async afterMerge() {
207-
// expect(path.join(tmpPath, 'config/ember-cli-update.json')).to.be.a.file()
208-
// .and.equal(path.join(cwd, 'test/fixtures/ember-cli-update-json/default/config/ember-cli-update.json'));
209-
210-
// await fs.remove(path.join(tmpPath, 'config/ember-cli-update.json'));
211-
// }
212203
});
213204

214205
fixtureCompare({
@@ -400,6 +391,36 @@ applicable codemods: ember-modules-codemod, ember-qunit-codemod, ember-test-help
400391

401392
assertNoUnstaged(status);
402393
});
394+
395+
it('resets blueprint', async function() {
396+
let {
397+
location,
398+
version: to
399+
} = (await loadSafeBlueprintFile('test/fixtures/blueprint/app/legacy-app/local/my-app/config2/ember-cli-update.json')).blueprints[0];
400+
401+
let {
402+
status
403+
} = await merge({
404+
fixturesPath: 'test/fixtures/blueprint/app/legacy-app/merge',
405+
commitMessage: 'my-app',
406+
reset: true,
407+
to,
408+
blueprint: 'ember-cli-update-git-blueprint-test',
409+
async beforeMerge() {
410+
await initBlueprint({
411+
fixturesPath: 'test/fixtures/blueprint/app/legacy',
412+
resolvedFrom: tmpPath,
413+
relativeDir: location
414+
});
415+
}
416+
});
417+
418+
fixtureCompare({
419+
mergeFixtures: 'test/fixtures/blueprint/app/legacy-app/reset/my-app'
420+
});
421+
422+
assertNoStaged(status);
423+
});
403424
});
404425

405426
describe('ember-cli-update.json', function() {

0 commit comments

Comments
 (0)