Skip to content

Commit 96d16ac

Browse files
author
Kelly Selden
committed
saves config path for later
1 parent 11d4a90 commit 96d16ac

25 files changed

Lines changed: 124 additions & 65 deletions

src/bootstrap.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ const saveBlueprint = require('./save-blueprint');
1010
const loadSafeBlueprint = require('./load-safe-blueprint');
1111
const loadDefaultBlueprint = require('./load-default-blueprint');
1212
const { glimmerPackageName } = require('./constants');
13+
const getBlueprintFilePath = require('./get-blueprint-file-path');
1314

1415
module.exports = async function bootstrap() {
1516
let cwd = process.cwd();
1617

18+
// A custom config location in package.json may be reset/init away,
19+
// so we can no longer look it up on the fly after the run.
20+
// We must rely on a lookup before the run.
21+
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
22+
1723
let packageJson = require(path.join(cwd, 'package'));
1824

1925
let projectOptions = await getProjectOptions(packageJson);
@@ -38,7 +44,7 @@ module.exports = async function bootstrap() {
3844
}
3945

4046
await saveBlueprint({
41-
cwd,
47+
emberCliUpdateJsonPath,
4248
blueprint
4349
});
4450
};

src/index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const isDefaultBlueprint = require('./is-default-blueprint');
2222
const findBlueprint = require('./find-blueprint');
2323
const getBaseBlueprint = require('./get-base-blueprint');
2424
const chooseBlueprintUpdates = require('./choose-blueprint-updates');
25+
const getBlueprintFilePath = require('./get-blueprint-file-path');
2526

2627
const {
2728
'to': { default: toDefault },
@@ -47,7 +48,12 @@ module.exports = async function emberCliUpdate({
4748
}) {
4849
let cwd = process.cwd();
4950

50-
let emberCliUpdateJson = await loadSafeBlueprintFile(cwd);
51+
// A custom config location in package.json may be reset/init away,
52+
// so we can no longer look it up on the fly after the run.
53+
// We must rely on a lookup before the run.
54+
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
55+
56+
let emberCliUpdateJson = await loadSafeBlueprintFile(emberCliUpdateJsonPath);
5157

5258
let blueprint;
5359
let packageUrl;
@@ -248,35 +254,41 @@ All blueprints are up-to-date!`;
248254
})).promise;
249255

250256
if (_blueprint) {
251-
let emberCliUpdateJson = await loadBlueprintFile(cwd);
257+
let emberCliUpdateJson = await loadBlueprintFile(emberCliUpdateJsonPath);
252258

253259
// If you don't have a state file, save the default blueprint,
254260
// even if you are currently working on a custom blueprint.
255261
if (!emberCliUpdateJson || !isCustomBlueprint) {
256262
await saveBlueprint({
257-
cwd,
263+
emberCliUpdateJsonPath,
258264
blueprint: defaultBlueprint
259265
});
260266
}
261267

262268
if (isCustomBlueprint) {
263269
await saveBlueprint({
264-
cwd,
270+
emberCliUpdateJsonPath,
265271
blueprint: endBlueprint
266272
});
267273
}
268274

269275
if (!reset) {
270-
await stageBlueprintFile(cwd);
276+
await stageBlueprintFile({
277+
cwd,
278+
emberCliUpdateJsonPath
279+
});
271280
}
272281
} else if (isPersistedBlueprint) {
273282
await saveBlueprint({
274-
cwd,
283+
emberCliUpdateJsonPath,
275284
blueprint: endBlueprint
276285
});
277286

278287
if (!reset) {
279-
await stageBlueprintFile(cwd);
288+
await stageBlueprintFile({
289+
cwd,
290+
emberCliUpdateJsonPath
291+
});
280292
}
281293
}
282294

src/init.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const findBlueprint = require('./find-blueprint');
1616
const getBaseBlueprint = require('./get-base-blueprint');
1717
const getVersions = require('boilerplate-update/src/get-versions');
1818
const _getTagVersion = require('./get-tag-version');
19+
const getBlueprintFilePath = require('./get-blueprint-file-path');
1920

2021
module.exports = async function init({
2122
blueprint: _blueprint,
@@ -27,6 +28,11 @@ module.exports = async function init({
2728
}) {
2829
let cwd = process.cwd();
2930

31+
// A custom config location in package.json may be reset/init away,
32+
// so we can no longer look it up on the fly after the run.
33+
// We must rely on a lookup before the run.
34+
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
35+
3036
let packageName;
3137
let name;
3238
let location;
@@ -60,7 +66,7 @@ module.exports = async function init({
6066
version = await getTagVersion(to);
6167
}
6268

63-
let emberCliUpdateJson = await loadSafeBlueprintFile(cwd);
69+
let emberCliUpdateJson = await loadSafeBlueprintFile(emberCliUpdateJsonPath);
6470

6571
let blueprint;
6672

@@ -110,17 +116,20 @@ module.exports = async function init({
110116
wasRunAsExecutable
111117
})).promise;
112118

113-
if (!await loadBlueprintFile(cwd)) {
119+
if (!await loadBlueprintFile(emberCliUpdateJsonPath)) {
114120
await bootstrap();
115121
}
116122

117123
await saveBlueprint({
118-
cwd,
124+
emberCliUpdateJsonPath,
119125
blueprint
120126
});
121127

122128
if (!reset) {
123-
await stageBlueprintFile(cwd);
129+
await stageBlueprintFile({
130+
cwd,
131+
emberCliUpdateJsonPath
132+
});
124133
}
125134

126135
return result;

src/install.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const bootstrap = require('./bootstrap');
99
const emberInstallAddon = require('./ember-install-addon');
1010
const getVersions = require('boilerplate-update/src/get-versions');
1111
const _getTagVersion = require('./get-tag-version');
12+
const getBlueprintFilePath = require('./get-blueprint-file-path');
1213

1314
const toDefault = require('./args').to.default;
1415

@@ -17,6 +18,11 @@ module.exports = async function install({
1718
}) {
1819
let cwd = process.cwd();
1920

21+
// A custom config location in package.json may be reset/init away,
22+
// so we can no longer look it up on the fly after the run.
23+
// We must rely on a lookup before the run.
24+
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
25+
2026
let parsedPackage = await parseBlueprintPackage({
2127
cwd,
2228
blueprint: addon
@@ -58,12 +64,12 @@ module.exports = async function install({
5864
version
5965
});
6066

61-
if (!await loadBlueprintFile(cwd)) {
67+
if (!await loadBlueprintFile(emberCliUpdateJsonPath)) {
6268
await bootstrap();
6369
}
6470

6571
await saveBlueprint({
66-
cwd,
72+
emberCliUpdateJsonPath,
6773
blueprint
6874
});
6975
};

src/load-blueprint-file.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
const fs = require('fs-extra');
4-
const getBlueprintFilePath = require('./get-blueprint-file-path');
54

6-
async function loadBlueprintFile(cwd) {
5+
async function loadBlueprintFile(emberCliUpdateJsonPath) {
76
try {
8-
return await fs.readJson(await getBlueprintFilePath(cwd));
7+
let emberCliUpdateJson = await fs.readJson(emberCliUpdateJsonPath);
8+
return emberCliUpdateJson;
99
} catch (err) {}
1010
}
1111

src/load-safe-blueprint-file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const loadBlueprintFile = require('./load-blueprint-file');
44

5-
async function loadSafeBlueprintFile(cwd) {
6-
let emberCliUpdateJson = await loadBlueprintFile(cwd);
5+
async function loadSafeBlueprintFile(emberCliUpdateJsonPath) {
6+
let emberCliUpdateJson = await loadBlueprintFile(emberCliUpdateJsonPath);
77

88
if (!emberCliUpdateJson) {
99
emberCliUpdateJson = {};

src/save-blueprint-file.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
const fs = require('fs-extra');
44
const path = require('path');
5-
const getBlueprintFilePath = require('./get-blueprint-file-path');
65

7-
async function saveBlueprintFile(cwd, emberCliUpdateJson) {
6+
async function saveBlueprintFile(emberCliUpdateJsonPath, emberCliUpdateJson) {
87
emberCliUpdateJson.packages = emberCliUpdateJson.blueprints.reduce((packages, blueprint) => {
98
let _package = packages.find(p => p.name === blueprint.packageName);
109

@@ -30,8 +29,6 @@ async function saveBlueprintFile(cwd, emberCliUpdateJson) {
3029

3130
delete emberCliUpdateJson.blueprints;
3231

33-
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
34-
3532
await fs.ensureDir(path.dirname(emberCliUpdateJsonPath));
3633

3734
await fs.writeJson(emberCliUpdateJsonPath, emberCliUpdateJson, {

src/save-blueprint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ function addBlueprint(emberCliUpdateJson, blueprint) {
88
}
99

1010
async function saveBlueprint({
11-
cwd,
11+
emberCliUpdateJsonPath,
1212
blueprint
1313
}) {
1414
if (!(blueprint && blueprint.version)) {
15-
blueprint = await utils.loadDefaultBlueprintFromDisk(cwd);
15+
blueprint = await utils.loadDefaultBlueprintFromDisk(emberCliUpdateJsonPath);
1616
}
1717

1818
let {
@@ -25,7 +25,7 @@ async function saveBlueprint({
2525
isBaseBlueprint
2626
} = blueprint;
2727

28-
let emberCliUpdateJson = await utils.loadSafeBlueprintFile(cwd);
28+
let emberCliUpdateJson = await utils.loadSafeBlueprintFile(emberCliUpdateJsonPath);
2929

3030
let savedBlueprint = findBlueprint(emberCliUpdateJson, packageName, name);
3131

@@ -58,7 +58,7 @@ async function saveBlueprint({
5858
savedBlueprint.version = version;
5959
}
6060

61-
await utils.saveBlueprintFile(cwd, emberCliUpdateJson);
61+
await utils.saveBlueprintFile(emberCliUpdateJsonPath, emberCliUpdateJson);
6262
}
6363

6464
module.exports = saveBlueprint;

src/save.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const loadSafeBlueprint = require('./load-safe-blueprint');
66
const saveBlueprint = require('./save-blueprint');
77
const loadBlueprintFile = require('./load-blueprint-file');
88
const bootstrap = require('./bootstrap');
9+
const getBlueprintFilePath = require('./get-blueprint-file-path');
910

1011
module.exports = async function save({
1112
blueprint: _blueprint,
@@ -18,6 +19,11 @@ module.exports = async function save({
1819

1920
let cwd = process.cwd();
2021

22+
// A custom config location in package.json may be reset/init away,
23+
// so we can no longer look it up on the fly after the run.
24+
// We must rely on a lookup before the run.
25+
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
26+
2127
let parsedPackage = await parseBlueprintPackage({
2228
cwd,
2329
blueprint: _blueprint
@@ -33,12 +39,12 @@ module.exports = async function save({
3339
options: blueprintOptions
3440
});
3541

36-
if (!await loadBlueprintFile(cwd)) {
42+
if (!await loadBlueprintFile(emberCliUpdateJsonPath)) {
3743
await bootstrap();
3844
}
3945

4046
await saveBlueprint({
41-
cwd,
47+
emberCliUpdateJsonPath,
4248
blueprint
4349
});
4450
};

src/stage-blueprint-file.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use strict';
22

3-
const { getBlueprintRelativeFilePath } = require('./get-blueprint-file-path');
3+
const path = require('path');
44
const run = require('./run');
55

6-
async function stageBlueprintFile(cwd) {
7-
let emberCliUpdateJsonPath = await getBlueprintRelativeFilePath(cwd);
6+
async function stageBlueprintFile({
7+
cwd,
8+
emberCliUpdateJsonPath
9+
}) {
10+
let relative = path.relative(cwd, emberCliUpdateJsonPath);
811

9-
await run(`git add ${emberCliUpdateJsonPath}`);
12+
await run(`git add ${relative}`);
1013
}
1114

1215
module.exports = stageBlueprintFile;

0 commit comments

Comments
 (0)