forked from ember-cli/ember-cli-update
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-base-blueprint.js
More file actions
52 lines (42 loc) · 1.68 KB
/
get-base-blueprint.js
File metadata and controls
52 lines (42 loc) · 1.68 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
'use strict';
const parseBlueprintPackage = require('./parse-blueprint-package');
const downloadPackage = require('./download-package');
const loadSafeBlueprint = require('./load-safe-blueprint');
const isDefaultBlueprint = require('./is-default-blueprint');
/**
* If the passed in `blueprint` is not the base blueprint, find it. A base blueprint is either
* an `addon`, `app`, or `glimmer` blueprint or has the `isBaseBlueprint` boolean set to true.
*
* @param cwd - Used in `parseBlueprintPackage` to read package.json and find a viable version and normalize url
* if it exists
* @param blueprints - Find the base blueprint in this array if the passed blueprint is not one
* @param blueprint - Figure out if this is a base blueprint
* @returns {Promise<*>}
*/
async function getBaseBlueprint({ cwd, blueprints, blueprint }) {
let baseBlueprint;
let isCustomBlueprint = !isDefaultBlueprint(blueprint);
if (isCustomBlueprint && !blueprint.isBaseBlueprint) {
baseBlueprint = blueprints.find(b => b.isBaseBlueprint);
if (baseBlueprint) {
baseBlueprint = loadSafeBlueprint(baseBlueprint);
let isCustomBlueprint = !isDefaultBlueprint(baseBlueprint);
if (isCustomBlueprint) {
if (baseBlueprint.location) {
let parsedPackage = await parseBlueprintPackage({
cwd,
packageName: baseBlueprint.location
});
let downloadedPackage = await downloadPackage(
baseBlueprint.packageName,
parsedPackage.url,
baseBlueprint.version
);
baseBlueprint.path = downloadedPackage.path;
}
}
}
}
return baseBlueprint;
}
module.exports = getBaseBlueprint;