Skip to content

Commit

Permalink
support picking a blueprint inside a package
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Apr 4, 2020
1 parent cddc7c6 commit 5531fdf
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 57 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -75,6 +75,10 @@ ember-cli-update --run-codemods
```
--help Show help [boolean]
--version Show version number [boolean]
--package-name Provide a package that can contain many blueprints
("@glimmer/blueprint",
"git+https://git@github.com/tildeio/libkit.git",
"../blueprint") [string]
--blueprint, -b Provide a custom blueprint for use in the update
("@glimmer/blueprint",
"git+https://git@github.com/tildeio/libkit.git",
Expand Down
1 change: 1 addition & 0 deletions bin/commands/codemods.js
Expand Up @@ -8,6 +8,7 @@ module.exports.command = 'codemods';
module.exports.describe = args['run-codemods'].description;

module.exports.builder = {
packageName: args['package-name'],
blueprint: args['blueprint'],
'source-json': args['codemods-json'],
list: args['list-codemods']
Expand Down
1 change: 1 addition & 0 deletions bin/commands/compare.js
Expand Up @@ -8,6 +8,7 @@ module.exports.command = 'compare';
module.exports.describe = args['compare-only'].description;

module.exports.builder = {
packageName: args['package-name'],
blueprint: args['blueprint'],
to: args['to']
};
Expand Down
1 change: 1 addition & 0 deletions bin/commands/reset.js
Expand Up @@ -8,6 +8,7 @@ module.exports.command = 'reset';
module.exports.describe = 'reset a blueprint';

module.exports.builder = {
packageName: args['package-name'],
blueprint: args['blueprint'],
to: args['to']
};
Expand Down
1 change: 1 addition & 0 deletions bin/commands/save.js
Expand Up @@ -8,6 +8,7 @@ module.exports.command = 'save';
module.exports.describe = 'save old blueprint state';

module.exports.builder = {
packageName: args['package-name'],
blueprint: args['blueprint'],
from: args['from'],
outputRepo: args['output-repo'],
Expand Down
1 change: 1 addition & 0 deletions bin/commands/stats.js
Expand Up @@ -8,6 +8,7 @@ module.exports.command = 'stats';
module.exports.describe = 'list blueprint version updates';

module.exports.builder = {
packageName: args['package-name'],
blueprint: args['blueprint']
};

Expand Down
4 changes: 4 additions & 0 deletions src/args.js
@@ -1,6 +1,10 @@
'use strict';

module.exports = {
'package-name': {
type: 'string',
description: 'Provide a package that can contain many blueprints ("@glimmer/blueprint", "git+https://git@github.com/tildeio/libkit.git", "../blueprint")'
},
'blueprint': {
alias: ['b'],
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion src/check-for-blueprint-updates.js
Expand Up @@ -25,7 +25,7 @@ async function checkForBlueprintUpdates({
} else {
let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: blueprint.location || blueprint.packageName
packageName: blueprint.location || blueprint.packageName
});

let downloadedPackage = await downloadPackage(blueprint.packageName, parsedPackage.url, defaultTo);
Expand Down
5 changes: 5 additions & 0 deletions src/command.js
Expand Up @@ -13,6 +13,11 @@ module.exports = {
works: 'insideProject',

availableOptions: [
{
name: 'package-name',
description: args['package-name'].description,
type: String
},
{
name: 'blueprint',
aliases: args['blueprint'].alias,
Expand Down
4 changes: 3 additions & 1 deletion src/compare.js
Expand Up @@ -12,6 +12,7 @@ const loadDefaultBlueprintFromDisk = require('./load-default-blueprint-from-disk

module.exports = async function compare({
cwd = process.cwd(),
packageName,
blueprint: _blueprint,
to = defaultTo
} = {}) {
Expand All @@ -34,6 +35,7 @@ module.exports = async function compare({
} = await getBlueprintFromArgs({
cwd,
emberCliUpdateJson,
packageName,
blueprint: _blueprint,
to
});
Expand All @@ -57,7 +59,7 @@ module.exports = async function compare({

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: blueprint.location || blueprint.packageName
packageName: blueprint.location || blueprint.packageName
});
let url = parsedPackage.url;

Expand Down
2 changes: 1 addition & 1 deletion src/get-base-blueprint.js
Expand Up @@ -23,7 +23,7 @@ async function getBaseBlueprint({
if (baseBlueprint.location) {
let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: baseBlueprint.location
packageName: baseBlueprint.location
});
let downloadedPackage = await downloadPackage(
baseBlueprint.packageName,
Expand Down
20 changes: 16 additions & 4 deletions src/get-blueprint-from-args.js
Expand Up @@ -4,16 +4,23 @@ const parseBlueprintPackage = require('./parse-blueprint-package');
const resolvePackage = require('./resolve-package');
const findBlueprint = require('./find-blueprint');
const { defaultTo } = require('./constants');
const normalizeBlueprintArgs = require('./normalize-blueprint-args');

async function getBlueprintFromArgs({
cwd,
emberCliUpdateJson,
packageName,
blueprint,
to = defaultTo
}) {
let blueprintArgs = normalizeBlueprintArgs({
packageName,
blueprintName: blueprint
});

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint
packageName: blueprintArgs.packageName
});
let url = parsedPackage.url;

Expand All @@ -23,10 +30,15 @@ async function getBlueprintFromArgs({
range: to
});

let packageName = packageInfo.name;
let name = packageInfo.name;
packageName = packageInfo.name;
let blueprintName;
if (blueprintArgs.blueprintName !== blueprintArgs.packageName) {
blueprintName = blueprintArgs.blueprintName;
} else {
blueprintName = packageName;
}

let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, name);
let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, blueprintName);
if (!existingBlueprint) {
throw `blueprint "${blueprint}" was not found`;
}
Expand Down
23 changes: 18 additions & 5 deletions src/index.js
Expand Up @@ -23,6 +23,7 @@ const chooseBlueprintUpdates = require('./choose-blueprint-updates');
const getBlueprintFilePath = require('./get-blueprint-file-path');
const resolvePackage = require('./resolve-package');
const { defaultTo } = require('./constants');
const normalizeBlueprintArgs = require('./normalize-blueprint-args');

async function _resolvePackage(blueprint, url, range) {
if (blueprint.version && !url) {
Expand All @@ -47,6 +48,7 @@ async function _resolvePackage(blueprint, url, range) {

module.exports = async function emberCliUpdate({
cwd = process.cwd(),
packageName,
blueprint: _blueprint,
from,
to,
Expand All @@ -65,25 +67,36 @@ module.exports = async function emberCliUpdate({
let packageUrl;

if (_blueprint) {
let blueprintArgs = normalizeBlueprintArgs({
packageName,
blueprintName: _blueprint
});

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: _blueprint
packageName: blueprintArgs.packageName
});
packageUrl = parsedPackage.url;

let packageName = parsedPackage.name;
packageName = parsedPackage.name;
if (!packageName) {
let downloadedPackage = await downloadPackage(null, packageUrl, defaultTo);
packageName = downloadedPackage.name;
}
let blueprintName;
if (blueprintArgs.blueprintName !== blueprintArgs.packageName) {
blueprintName = blueprintArgs.blueprintName;
} else {
blueprintName = packageName;
}

let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, packageName);
let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, blueprintName);
if (existingBlueprint) {
blueprint = existingBlueprint;
} else {
blueprint = loadSafeBlueprint({
packageName,
name: packageName,
name: blueprintName,
location: parsedPackage.location
});
}
Expand Down Expand Up @@ -119,7 +132,7 @@ module.exports = async function emberCliUpdate({
if (blueprint.location && !packageUrl) {
let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: blueprint.location
packageName: blueprint.location
});
packageUrl = parsedPackage.url;
}
Expand Down
28 changes: 19 additions & 9 deletions src/init.js
Expand Up @@ -14,9 +14,11 @@ const getBaseBlueprint = require('./get-base-blueprint');
const getBlueprintFilePath = require('./get-blueprint-file-path');
const resolvePackage = require('./resolve-package');
const { defaultTo } = require('./constants');
const normalizeBlueprintArgs = require('./normalize-blueprint-args');

module.exports = async function init({
cwd = process.cwd(),
packageName,
blueprint: _blueprint,
to = defaultTo,
resolveConflicts,
Expand All @@ -29,23 +31,31 @@ module.exports = async function init({
// We must rely on a lookup before the run.
let emberCliUpdateJsonPath = await getBlueprintFilePath(cwd);

let packageName;
let name;
let blueprintName;
let location;
let url;
if (_blueprint) {
let blueprintArgs = normalizeBlueprintArgs({
packageName,
blueprintName: _blueprint
});

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: _blueprint
packageName: blueprintArgs.packageName
});
packageName = parsedPackage.name;
name = parsedPackage.name;
if (blueprintArgs.blueprintName !== blueprintArgs.packageName) {
blueprintName = blueprintArgs.blueprintName;
} else {
blueprintName = packageName;
}
location = parsedPackage.location;
url = parsedPackage.url;
} else {
let defaultBlueprint = await loadDefaultBlueprintFromDisk(cwd);
packageName = defaultBlueprint.packageName;
name = defaultBlueprint.name;
blueprintName = defaultBlueprint.name;
if (!outputRepo) {
outputRepo = defaultBlueprint.outputRepo;
}
Expand All @@ -61,8 +71,8 @@ module.exports = async function init({
});

packageName = packageInfo.name;
if (!name) {
name = packageInfo.name;
if (!blueprintName) {
blueprintName = packageName;
}
let version = packageInfo.version;
let path = packageInfo.path;
Expand All @@ -73,13 +83,13 @@ module.exports = async function init({

let blueprint;

let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, name);
let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, blueprintName);
if (existingBlueprint) {
blueprint = existingBlueprint;
} else {
blueprint = loadSafeBlueprint({
packageName,
name,
name: blueprintName,
location,
options: blueprintOptions
});
Expand Down
2 changes: 1 addition & 1 deletion src/install.js
Expand Up @@ -21,7 +21,7 @@ module.exports = async function install({

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: addon
packageName: addon
});

let {
Expand Down
17 changes: 17 additions & 0 deletions src/normalize-blueprint-args.js
@@ -0,0 +1,17 @@
'use strict';

function normalizeBlueprintArgs({
packageName,
blueprintName
}) {
if (!packageName) {
packageName = blueprintName;
}

return {
packageName,
blueprintName
};
}

module.exports = normalizeBlueprintArgs;
20 changes: 10 additions & 10 deletions src/parse-blueprint-package.js
Expand Up @@ -16,31 +16,31 @@ function toPosixAbsolutePath(path) {

async function parseBlueprintPackage({
cwd = '.',
blueprint
packageName
}) {
let name;
let location;
let url;
let blueprintPath;

if (blueprint.startsWith('.')) {
blueprintPath = path.resolve(cwd, blueprint);
} else if (path.isAbsolute(blueprint) && await fs.pathExists(blueprint)) {
blueprintPath = blueprint;
if (packageName.startsWith('.')) {
blueprintPath = path.resolve(cwd, packageName);
} else if (path.isAbsolute(packageName) && await fs.pathExists(packageName)) {
blueprintPath = packageName;
}

if (blueprintPath) {
let posixBlueprintPath = toPosixAbsolutePath(blueprintPath);
url = `git+file://${posixBlueprintPath}`;
location = blueprint;
location = packageName;
} else {
try {
// This matches Window's paths, so it can't be done first.
new URL(blueprint);
url = blueprint;
location = blueprint;
new URL(packageName);
url = packageName;
location = packageName;
} catch (err) {
name = blueprint;
name = packageName;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/reset.js
Expand Up @@ -16,6 +16,7 @@ const loadDefaultBlueprintFromDisk = require('./load-default-blueprint-from-disk

module.exports = async function reset({
cwd = process.cwd(),
packageName,
blueprint: _blueprint,
to = defaultTo
} = {}) {
Expand All @@ -39,6 +40,7 @@ module.exports = async function reset({
} = await getBlueprintFromArgs({
cwd,
emberCliUpdateJson,
packageName,
blueprint: _blueprint,
to
});
Expand All @@ -62,7 +64,7 @@ module.exports = async function reset({

let parsedPackage = await parseBlueprintPackage({
cwd,
blueprint: blueprint.location || blueprint.packageName
packageName: blueprint.location || blueprint.packageName
});
let url = parsedPackage.url;

Expand Down

0 comments on commit 5531fdf

Please sign in to comment.