Skip to content

Commit 1305e76

Browse files
committed
Ensure the correct new app blueprint is installed
1 parent 758510a commit 1305e76

9 files changed

+198
-71
lines changed

src/check-for-blueprint-updates.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,44 @@ const getTagVersion = require('boilerplate-update/src/get-tag-version');
66
const { defaultTo } = require('./constants');
77
const utils = require('./utils');
88

9+
/**
10+
*
11+
* @param {Object} options
12+
* @param {string} options.cwd
13+
* @param {string} options.blueprintName
14+
* @returns {Promise<string>}
15+
*/
16+
async function getLatestVersion({ cwd, blueprint }) {
17+
if (blueprint.location) {
18+
let parsedPackage = await parseBlueprintPackage({
19+
cwd,
20+
packageName: blueprint.location || blueprint.packageName
21+
});
22+
23+
let downloadedPackage = await downloadPackage(
24+
blueprint.packageName,
25+
parsedPackage.url,
26+
defaultTo
27+
);
28+
29+
return downloadedPackage.version;
30+
}
31+
32+
let versions = await utils.getVersions(blueprint.packageName);
33+
let latestVersion = await getTagVersion({
34+
range: defaultTo,
35+
versions,
36+
packageName: blueprint.packageName
37+
});
38+
39+
return latestVersion;
40+
}
41+
942
async function checkForBlueprintUpdates({ cwd, blueprints }) {
1043
return await Promise.all(
1144
blueprints.map(async blueprint => {
1245
let currentVersion = blueprint.version;
13-
let latestVersion;
14-
15-
if (!blueprint.location) {
16-
let versions = await utils.getVersions(blueprint.packageName);
17-
18-
latestVersion = await getTagVersion({
19-
range: defaultTo,
20-
versions,
21-
packageName: blueprint.packageName
22-
});
23-
} else {
24-
let parsedPackage = await parseBlueprintPackage({
25-
cwd,
26-
packageName: blueprint.location || blueprint.packageName
27-
});
28-
29-
let downloadedPackage = await downloadPackage(
30-
blueprint.packageName,
31-
parsedPackage.url,
32-
defaultTo
33-
);
34-
35-
latestVersion = downloadedPackage.version;
36-
}
46+
let latestVersion = await getLatestVersion({ cwd, blueprint });
3747

3848
return {
3949
blueprint,

src/choose-blueprint-updates.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const checkForBlueprintUpdates = require('./check-for-blueprint-updates');
44
const inquirer = require('inquirer');
55
const loadSafeBlueprint = require('./load-safe-blueprint');
66
const { defaultTo } = require('./constants');
7+
const semver = require('semver');
78

89
/**
910
* Format the string that is displayed when user is prompted for a blueprint
@@ -34,10 +35,10 @@ async function chooseBlueprint({ choicesByName, message }) {
3435
*
3536
* @param {string} cwd - Used in `checkForBlueprintUpdates` in order to generate url or path to it if on local disk
3637
* @param {object} emberCliUpdateJson - Use the `blueprints` property from this
37-
* @param {boolean} reset - Optional
38-
* @param {boolean} compare - Optional
39-
* @param {boolean} codemods - Optional
40-
* @param {string} to - Optional (could be undefined).
38+
* @param {boolean} [reset]
39+
* @param {boolean} [compare]
40+
* @param {boolean} [codemods]
41+
* @param {string} [to] - Optional (could be undefined).
4142
* @returns {Promise<{blueprint: (*|{}), areAllUpToDate, to: string}>}
4243
*/
4344
async function chooseBlueprintUpdates({
@@ -50,28 +51,28 @@ async function chooseBlueprintUpdates({
5051
}) {
5152
let existingBlueprint;
5253
let areAllUpToDate;
53-
5454
let { blueprints } = emberCliUpdateJson;
5555

5656
if (reset || compare || codemods) {
5757
let choicesByName = blueprints.reduce((choices, blueprint) => {
5858
let name = blueprint.packageName;
59+
5960
choices[name] = {
6061
blueprint,
6162
choice: {
6263
name
6364
}
6465
};
66+
6567
return choices;
6668
}, {});
6769

68-
let message;
70+
let message = 'Which blueprint would you like to run codemods for?';
71+
6972
if (reset) {
7073
message = 'Which blueprint would you like to reset?';
7174
} else if (compare) {
7275
message = 'Which blueprint would you like to compare?';
73-
} else {
74-
message = 'Which blueprint would you like to run codemods for?';
7576
}
7677

7778
existingBlueprint = (
@@ -90,22 +91,35 @@ async function chooseBlueprintUpdates({
9091
blueprintUpdate => blueprintUpdate.isUpToDate
9192
);
9293

93-
if (areAllUpToDate) {
94-
console.log(`${blueprintUpdates.map(formatBlueprintLine).join(`
95-
`)}
96-
97-
All blueprints are up-to-date!`);
94+
if (!to && areAllUpToDate) {
95+
console.log(
96+
`${blueprintUpdates.map(formatBlueprintLine).join('\n')}\n\nAll blueprints are up-to-date!`
97+
);
9898
} else {
99+
areAllUpToDate = false;
100+
101+
for (let update of blueprintUpdates) {
102+
if (
103+
update.blueprint.isBaseBlueprint &&
104+
!!to &&
105+
semver.gt(to, update.latestVersion)
106+
) {
107+
update.isUpToDate = false;
108+
update.latestVersion = to;
109+
}
110+
}
111+
99112
let choicesByName = blueprintUpdates.reduce(
100113
(choices, blueprintUpdate) => {
101114
let name = formatBlueprintLine(blueprintUpdate);
115+
102116
choices[name] = {
103117
blueprintUpdate,
104118
choice: {
105-
name,
106-
disabled: blueprintUpdate.isUpToDate
119+
name
107120
}
108121
};
122+
109123
return choices;
110124
},
111125
{}

src/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ module.exports.defaultAddonBlueprintName = 'addon';
66

77
module.exports.glimmerPackageName = '@glimmer/blueprint';
88

9+
module.exports.defaultAppPackageName =
10+
'@ember-tooling/classic-build-app-blueprint';
11+
module.exports.defaultAddonPackageName =
12+
'@ember-tooling/classic-build-addon-blueprint';
13+
914
module.exports.defaultTo = '*';

src/get-base-blueprint.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,29 @@ const isDefaultBlueprint = require('./is-default-blueprint');
1717
*/
1818
async function getBaseBlueprint({ cwd, blueprints, blueprint }) {
1919
let baseBlueprint;
20-
2120
let isCustomBlueprint = !isDefaultBlueprint(blueprint);
2221

2322
if (isCustomBlueprint && !blueprint.isBaseBlueprint) {
2423
baseBlueprint = blueprints.find(b => b.isBaseBlueprint);
24+
2525
if (baseBlueprint) {
2626
baseBlueprint = loadSafeBlueprint(baseBlueprint);
27+
2728
let isCustomBlueprint = !isDefaultBlueprint(baseBlueprint);
29+
2830
if (isCustomBlueprint) {
2931
if (baseBlueprint.location) {
3032
let parsedPackage = await parseBlueprintPackage({
3133
cwd,
3234
packageName: baseBlueprint.location
3335
});
36+
3437
let downloadedPackage = await downloadPackage(
3538
baseBlueprint.packageName,
3639
parsedPackage.url,
3740
baseBlueprint.version
3841
);
42+
3943
baseBlueprint.path = downloadedPackage.path;
4044
}
4145
}

src/get-project-options.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ module.exports = async function getProjectOptions(
5757
}
5858

5959
let projectType = getProjectType(checkForDep, keywords);
60-
6160
let options = [projectType];
62-
6361
let cwd = process.cwd();
64-
6562
let isYarn = await hasYarn(cwd);
6663

6764
if (isYarn) {

src/get-start-and-end-commands.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,46 @@ const overwriteBlueprintFiles = require('./overwrite-blueprint-files');
1111
const debug = require('./debug');
1212
const npm = require('boilerplate-update/src/npm');
1313
const mutatePackageJson = require('boilerplate-update/src/mutate-package-json');
14-
const { glimmerPackageName } = require('./constants');
14+
const {
15+
glimmerPackageName,
16+
defaultAddonPackageName,
17+
defaultAppPackageName
18+
} = require('./constants');
1519
const hasYarn = require('./has-yarn');
1620

1721
const nodeModulesIgnore = `
1822
1923
/node_modules/
2024
`;
2125

26+
/**
27+
* @typedef {Object} StartAndEndCommandsResult
28+
* @property {string} projectName
29+
* @property {string} packageName - Always 'ember-cli'
30+
* @property {string} commandName - Always 'ember'
31+
* @property {Function} createProjectFromCache - Function to create project from cache
32+
* @property {Function} createProjectFromRemote - Function to create project from remote
33+
* @property {Object} startOptions - Start configuration options
34+
* @property {Object} startOptions.baseBlueprint - Base blueprint for start
35+
* @property {Object} startOptions.blueprint - Blueprint for start
36+
* @property {string} startOptions.packageRange - Package range for start
37+
* @property {Object} endOptions - End configuration options
38+
* @property {Object} endOptions.baseBlueprint - Base blueprint for end
39+
* @property {Object} endOptions.blueprint - Blueprint for end
40+
* @property {string} endOptions.packageRange - Package range for end
41+
*/
42+
43+
/**
44+
* Creates start and end commands configuration for ember-cli-update process
45+
*
46+
* @param {Object} params - Configuration parameters
47+
* @param {Object} params.packageJson - The package.json object of the project
48+
* @param {Object} [params.baseBlueprint] - Base blueprint configuration object
49+
* @param {Object} [params.startBlueprint] - Starting blueprint configuration object
50+
* @param {Object} params.endBlueprint - Target blueprint configuration object
51+
* @param {Object} [params.emberCliUpdateJson] - ember-cli-update.json configuration object
52+
* @returns {StartAndEndCommandsResult} Configuration object with project details and command options
53+
*/
2254
module.exports = function getStartAndEndCommands({
2355
packageJson,
2456
baseBlueprint,
@@ -95,13 +127,23 @@ async function isDefaultAddonBlueprint(blueprint) {
95127
let isCustomBlueprint = !isDefaultBlueprint(blueprint);
96128

97129
let isDefaultAddonBlueprint;
130+
if (blueprint.packageName === defaultAppPackageName) {
131+
return false;
132+
}
133+
134+
if (blueprint.packageName === defaultAddonPackageName) {
135+
return true;
136+
}
98137

99138
if (isCustomBlueprint) {
100139
let keywords;
140+
101141
if (blueprint.path) {
102142
keywords = utils.require(path.join(blueprint.path, 'package')).keywords;
103143
} else {
104-
keywords = await npm.json('v', blueprint.packageName, 'keywords');
144+
let packageInfo = await npm.json('v', blueprint.packageName);
145+
146+
keywords = packageInfo.keywords;
105147
}
106148

107149
isDefaultAddonBlueprint = !(

0 commit comments

Comments
 (0)