@@ -23,6 +23,82 @@ const resolvePackage = require('./resolve-package');
2323const { defaultTo } = require ( './constants' ) ;
2424const normalizeBlueprintArgs = require ( './normalize-blueprint-args' ) ;
2525
26+ /**
27+ * Build an object of configurations based on contents of the package containing the blueprint specified
28+ * by the user
29+ */
30+ async function setupParamPassedBlueprint (
31+ selectedPackageName ,
32+ selectedBlueprintName ,
33+ emberCliUpdateJson ,
34+ fromVersion ,
35+ cwd
36+ ) {
37+ let blueprintArgs = normalizeBlueprintArgs ( {
38+ selectedPackageName,
39+ blueprintName : selectedBlueprintName
40+ } ) ;
41+ let parsedPackage = await parseBlueprintPackage ( {
42+ cwd,
43+ packageName : blueprintArgs . packageName
44+ } ) ;
45+ let blueprint ;
46+ let packageUrl = parsedPackage . url ;
47+ let packageName = parsedPackage . name ;
48+
49+ if ( ! packageName ) {
50+ let downloadedPackage = await downloadPackage ( null , packageUrl , defaultTo ) ;
51+ packageName = downloadedPackage . name ;
52+ }
53+
54+ let blueprintName ;
55+ if ( blueprintArgs . blueprintName !== blueprintArgs . packageName ) {
56+ blueprintName = blueprintArgs . blueprintName ;
57+ } else {
58+ blueprintName = packageName ;
59+ }
60+
61+ let existingBlueprint = findBlueprint ( emberCliUpdateJson , packageName , blueprintName ) ;
62+
63+ if ( existingBlueprint ) {
64+ blueprint = existingBlueprint ;
65+ } else {
66+ blueprint = loadSafeBlueprint ( {
67+ packageName,
68+ name : blueprintName ,
69+ location : parsedPackage . location
70+ } ) ;
71+
72+ if ( isDefaultBlueprint ( blueprint ) ) {
73+ blueprint = await loadDefaultBlueprintFromDisk ( {
74+ cwd,
75+ version : fromVersion
76+ } ) ;
77+ }
78+ }
79+
80+ if ( fromVersion ) {
81+ blueprint . version = fromVersion ;
82+ }
83+
84+ if ( ! blueprint . version ) {
85+ throw new Error ( 'A custom blueprint cannot detect --from. You must supply it.' ) ;
86+ }
87+
88+ return blueprint ;
89+ }
90+
91+ /**
92+ * If `version` attribute exists in the `blueprint` object and URL is empty, skip. Otherwise resolve the details of
93+ * the blueprint
94+ *
95+ * @param {Object } blueprint - Expected to contain `name`, `options` array, `packageName`, `location`, and `version`
96+ * attributes
97+ * @param {String } url - Optional parameter that links to package
98+ * @param {String } range - Version range i.e. 1.0.2
99+ * @returns {Promise<void> }
100+ * @private
101+ */
26102async function _resolvePackage ( blueprint , url , range ) {
27103 if ( blueprint . version && ! url ) {
28104 return ;
@@ -44,6 +120,16 @@ async function _resolvePackage(blueprint, url, range) {
44120 }
45121}
46122
123+ /**
124+ *
125+ * @param cwd
126+ * @param packageName - User passed package name
127+ * @param _blueprint - User passed blueprint name
128+ * @param from
129+ * @param to
130+ * @param resolveConflicts
131+ * @returns {Promise<{promise: Promise<*>, resolveConflictsProcess}|{promise: Promise<void>}> }
132+ */
47133module . exports = async function emberCliUpdate ( {
48134 cwd = process . cwd ( ) ,
49135 packageName,
@@ -65,54 +151,13 @@ module.exports = async function emberCliUpdate({
65151 let packageUrl ;
66152
67153 if ( _blueprint ) {
68- let blueprintArgs = normalizeBlueprintArgs ( {
154+ blueprint = await setupParamPassedBlueprint (
69155 packageName ,
70- blueprintName : _blueprint
71- } ) ;
72-
73- let parsedPackage = await parseBlueprintPackage ( {
74- cwd,
75- packageName : blueprintArgs . packageName
76- } ) ;
77- packageUrl = parsedPackage . url ;
78-
79- packageName = parsedPackage . name ;
80- if ( ! packageName ) {
81- let downloadedPackage = await downloadPackage ( null , packageUrl , defaultTo ) ;
82- packageName = downloadedPackage . name ;
83- }
84- let blueprintName ;
85- if ( blueprintArgs . blueprintName !== blueprintArgs . packageName ) {
86- blueprintName = blueprintArgs . blueprintName ;
87- } else {
88- blueprintName = packageName ;
89- }
90-
91- let existingBlueprint = findBlueprint ( emberCliUpdateJson , packageName , blueprintName ) ;
92- if ( existingBlueprint ) {
93- blueprint = existingBlueprint ;
94- } else {
95- blueprint = loadSafeBlueprint ( {
96- packageName,
97- name : blueprintName ,
98- location : parsedPackage . location
99- } ) ;
100-
101- if ( isDefaultBlueprint ( blueprint ) ) {
102- blueprint = await loadDefaultBlueprintFromDisk ( {
103- cwd,
104- version : from
105- } ) ;
106- }
107- }
108-
109- if ( from ) {
110- blueprint . version = from ;
111- }
112-
113- if ( ! blueprint . version ) {
114- throw new Error ( 'A custom blueprint cannot detect --from. You must supply it.' ) ;
115- }
156+ _blueprint ,
157+ emberCliUpdateJson ,
158+ from ,
159+ cwd
160+ ) ;
116161 } else if ( blueprints . length ) {
117162 let {
118163 areAllUpToDate,
@@ -137,6 +182,7 @@ module.exports = async function emberCliUpdate({
137182 } ) ;
138183 }
139184
185+ // If blueprint is located on disk
140186 if ( blueprint . location && ! packageUrl ) {
141187 let parsedPackage = await parseBlueprintPackage ( {
142188 cwd,
@@ -153,6 +199,9 @@ module.exports = async function emberCliUpdate({
153199 blueprint
154200 } ) ;
155201
202+ // If no base blueprint is found, set the selected one as the base blueprint.
203+ // `glimmer`, `app`, and `addon` blueprints as well as ones whose `isBaseBlueprint` attribute is
204+ // set to true will also have baseBlueprint undefined
156205 if ( ! baseBlueprint ) {
157206 // for non-existing blueprints
158207 blueprint . isBaseBlueprint = true ;
0 commit comments