-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathreset.js
More file actions
122 lines (106 loc) · 3.25 KB
/
reset.js
File metadata and controls
122 lines (106 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
const boilerplateUpdate = require('boilerplate-update');
const getStartAndEndCommands = require('./get-start-and-end-commands');
const parseBlueprintPackage = require('./parse-blueprint-package');
const saveBlueprint = require('./save-blueprint');
const loadSafeBlueprintFile = require('./load-safe-blueprint-file');
const { getBlueprintRelativeFilePath } = require('./get-blueprint-file-path');
const getBaseBlueprint = require('./get-base-blueprint');
const getBlueprintFilePath = require('./get-blueprint-file-path');
const resolvePackage = require('./resolve-package');
const { defaultTo } = require('./constants');
const chooseBlueprintUpdates = require('./choose-blueprint-updates');
const getBlueprintFromArgs = require('./get-blueprint-from-args');
const loadDefaultBlueprintFromDisk = require('./load-default-blueprint-from-disk');
module.exports = async function reset({
cwd = process.cwd(),
packageName,
blueprint: _blueprint,
to = defaultTo
} = {}) {
try {
// A custom config location in package.json may be reset/init away,
// so we can no longer look it up on the fly after the run.
// We must rely on a lookup before the run.
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);
let emberCliUpdateJson = await loadSafeBlueprintFile(emberCliUpdateJsonPath);
let { blueprints } = emberCliUpdateJson;
let blueprint;
let packageInfo;
if (_blueprint) {
let {
packageInfo: _packageInfo,
existingBlueprint
} = await getBlueprintFromArgs({
cwd,
emberCliUpdateJson,
packageName,
blueprint: _blueprint,
to
});
packageInfo = _packageInfo;
blueprint = existingBlueprint;
} else {
if (blueprints.length) {
let {
blueprint: _blueprint
} = await chooseBlueprintUpdates({
cwd,
emberCliUpdateJson,
reset: true
});
blueprint = _blueprint;
} else {
blueprint = await loadDefaultBlueprintFromDisk({ cwd });
}
let parsedPackage = await parseBlueprintPackage({
cwd,
packageName: blueprint.location || blueprint.packageName
});
let url = parsedPackage.url;
packageInfo = await resolvePackage({
name: blueprint.packageName,
url,
range: to
});
}
blueprint.version = packageInfo.version;
blueprint.path = packageInfo.path;
let baseBlueprint;
if (!blueprint.isBaseBlueprint) {
baseBlueprint = await getBaseBlueprint({
cwd,
blueprints,
blueprint
});
}
let {
promise
} = await boilerplateUpdate({
cwd,
endVersion: blueprint.version,
reset: true,
createCustomDiff: true,
customDiffOptions: ({
packageJson
}) => getStartAndEndCommands({
packageJson,
baseBlueprint,
endBlueprint: blueprint
}),
ignoredFiles: [await getBlueprintRelativeFilePath(cwd)]
});
return {
promise: (async() => {
let result = await promise;
await saveBlueprint({
emberCliUpdateJsonPath,
blueprint
});
return result;
})()
};
} catch (err) {
return { promise: Promise.reject(err) };
}
};