Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions src/check-for-blueprint-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,44 @@ const getTagVersion = require('boilerplate-update/src/get-tag-version');
const { defaultTo } = require('./constants');
const utils = require('./utils');

/**
*
* @param {Object} options
* @param {string} options.cwd
* @param {string} options.blueprintName
* @returns {Promise<string>}
*/
async function getLatestVersion({ cwd, blueprint }) {
if (blueprint.location) {
let parsedPackage = await parseBlueprintPackage({
cwd,
packageName: blueprint.location || blueprint.packageName
});

let downloadedPackage = await downloadPackage(
blueprint.packageName,
parsedPackage.url,
defaultTo
);

return downloadedPackage.version;
}

let versions = await utils.getVersions(blueprint.packageName);
let latestVersion = await getTagVersion({
range: defaultTo,
versions,
packageName: blueprint.packageName
});

return latestVersion;
}

async function checkForBlueprintUpdates({ cwd, blueprints }) {
return await Promise.all(
blueprints.map(async blueprint => {
let currentVersion = blueprint.version;
let latestVersion;

if (!blueprint.location) {
let versions = await utils.getVersions(blueprint.packageName);

latestVersion = await getTagVersion({
range: defaultTo,
versions,
packageName: blueprint.packageName
});
} else {
let parsedPackage = await parseBlueprintPackage({
cwd,
packageName: blueprint.location || blueprint.packageName
});

let downloadedPackage = await downloadPackage(
blueprint.packageName,
parsedPackage.url,
defaultTo
);

latestVersion = downloadedPackage.version;
}
let latestVersion = await getLatestVersion({ cwd, blueprint });

return {
blueprint,
Expand Down
44 changes: 29 additions & 15 deletions src/choose-blueprint-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const checkForBlueprintUpdates = require('./check-for-blueprint-updates');
const inquirer = require('inquirer');
const loadSafeBlueprint = require('./load-safe-blueprint');
const { defaultTo } = require('./constants');
const semver = require('semver');

/**
* Format the string that is displayed when user is prompted for a blueprint
Expand Down Expand Up @@ -34,10 +35,10 @@ async function chooseBlueprint({ choicesByName, message }) {
*
* @param {string} cwd - Used in `checkForBlueprintUpdates` in order to generate url or path to it if on local disk
* @param {object} emberCliUpdateJson - Use the `blueprints` property from this
* @param {boolean} reset - Optional
* @param {boolean} compare - Optional
* @param {boolean} codemods - Optional
* @param {string} to - Optional (could be undefined).
* @param {boolean} [reset]
* @param {boolean} [compare]
* @param {boolean} [codemods]
* @param {string} [to] - Optional (could be undefined).
* @returns {Promise<{blueprint: (*|{}), areAllUpToDate, to: string}>}
*/
async function chooseBlueprintUpdates({
Expand All @@ -50,28 +51,28 @@ async function chooseBlueprintUpdates({
}) {
let existingBlueprint;
let areAllUpToDate;

let { blueprints } = emberCliUpdateJson;

if (reset || compare || codemods) {
let choicesByName = blueprints.reduce((choices, blueprint) => {
let name = blueprint.packageName;

choices[name] = {
blueprint,
choice: {
name
}
};

return choices;
}, {});

let message;
let message = 'Which blueprint would you like to run codemods for?';

if (reset) {
message = 'Which blueprint would you like to reset?';
} else if (compare) {
message = 'Which blueprint would you like to compare?';
} else {
message = 'Which blueprint would you like to run codemods for?';
}

existingBlueprint = (
Expand All @@ -90,22 +91,35 @@ async function chooseBlueprintUpdates({
blueprintUpdate => blueprintUpdate.isUpToDate
);

if (areAllUpToDate) {
console.log(`${blueprintUpdates.map(formatBlueprintLine).join(`
`)}

All blueprints are up-to-date!`);
if (!to && areAllUpToDate) {
console.log(
`${blueprintUpdates.map(formatBlueprintLine).join('\n')}\n\nAll blueprints are up-to-date!`
);
} else {
areAllUpToDate = false;

for (let update of blueprintUpdates) {
if (
update.blueprint.isBaseBlueprint &&
!!to &&
semver.gt(to, update.latestVersion)
) {
update.isUpToDate = false;
update.latestVersion = to;
}
}

let choicesByName = blueprintUpdates.reduce(
(choices, blueprintUpdate) => {
let name = formatBlueprintLine(blueprintUpdate);

choices[name] = {
blueprintUpdate,
choice: {
name,
disabled: blueprintUpdate.isUpToDate
name
}
};

return choices;
},
{}
Expand Down
5 changes: 5 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ module.exports.defaultAddonBlueprintName = 'addon';

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

module.exports.defaultAppPackageName =
'@ember-tooling/classic-build-app-blueprint';
module.exports.defaultAddonPackageName =
'@ember-tooling/classic-build-addon-blueprint';

module.exports.defaultTo = '*';
6 changes: 5 additions & 1 deletion src/get-base-blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ const isDefaultBlueprint = require('./is-default-blueprint');
*/
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;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/get-project-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ module.exports = async function getProjectOptions(
}

let projectType = getProjectType(checkForDep, keywords);

let options = [projectType];

let cwd = process.cwd();

let isYarn = await hasYarn(cwd);

if (isYarn) {
Expand Down
46 changes: 44 additions & 2 deletions src/get-start-and-end-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,46 @@ const overwriteBlueprintFiles = require('./overwrite-blueprint-files');
const debug = require('./debug');
const npm = require('boilerplate-update/src/npm');
const mutatePackageJson = require('boilerplate-update/src/mutate-package-json');
const { glimmerPackageName } = require('./constants');
const {
glimmerPackageName,
defaultAddonPackageName,
defaultAppPackageName
} = require('./constants');
const hasYarn = require('./has-yarn');

const nodeModulesIgnore = `

/node_modules/
`;

/**
* @typedef {Object} StartAndEndCommandsResult
* @property {string} projectName
* @property {string} packageName - Always 'ember-cli'
* @property {string} commandName - Always 'ember'
* @property {Function} createProjectFromCache - Function to create project from cache
* @property {Function} createProjectFromRemote - Function to create project from remote
* @property {Object} startOptions - Start configuration options
* @property {Object} startOptions.baseBlueprint - Base blueprint for start
* @property {Object} startOptions.blueprint - Blueprint for start
* @property {string} startOptions.packageRange - Package range for start
* @property {Object} endOptions - End configuration options
* @property {Object} endOptions.baseBlueprint - Base blueprint for end
* @property {Object} endOptions.blueprint - Blueprint for end
* @property {string} endOptions.packageRange - Package range for end
*/

/**
* Creates start and end commands configuration for ember-cli-update process
*
* @param {Object} params - Configuration parameters
* @param {Object} params.packageJson - The package.json object of the project
* @param {Object} [params.baseBlueprint] - Base blueprint configuration object
* @param {Object} [params.startBlueprint] - Starting blueprint configuration object
* @param {Object} params.endBlueprint - Target blueprint configuration object
* @param {Object} [params.emberCliUpdateJson] - ember-cli-update.json configuration object
* @returns {StartAndEndCommandsResult} Configuration object with project details and command options
*/
module.exports = function getStartAndEndCommands({
packageJson,
baseBlueprint,
Expand Down Expand Up @@ -95,13 +127,23 @@ async function isDefaultAddonBlueprint(blueprint) {
let isCustomBlueprint = !isDefaultBlueprint(blueprint);

let isDefaultAddonBlueprint;
if (blueprint.packageName === defaultAppPackageName) {
return false;
}

if (blueprint.packageName === defaultAddonPackageName) {
return true;
}

if (isCustomBlueprint) {
let keywords;

if (blueprint.path) {
keywords = utils.require(path.join(blueprint.path, 'package')).keywords;
} else {
keywords = await npm.json('v', blueprint.packageName, 'keywords');
let packageInfo = await npm.json('v', blueprint.packageName);

keywords = packageInfo.keywords;
}

isDefaultAddonBlueprint = !(
Expand Down
Loading
Loading