Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support local paths #1052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
57 changes: 34 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.exports = async function emberCliUpdate({
let blueprint;
let packageUrl;

debugger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔪

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get this branch working locally :-
I've abandoned this for now, but to anyone else who needs local paths: feel free to take all this (or do better than I did :D )

if (_blueprint) {
let blueprintArgs = normalizeBlueprintArgs({
packageName,
Expand All @@ -72,38 +73,48 @@ module.exports = async function emberCliUpdate({

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

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, blueprintName);
if (existingBlueprint) {
blueprint = existingBlueprint;
} else {
blueprint = loadSafeBlueprint({
packageName,
name: blueprintName,
location: parsedPackage.location
if (blueprintArgs.localLocation) {
blueprint = await loadDefaultBlueprintFromDisk({
cwd: blueprintArgs.localLocation,
version: from
});
} else {
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;
}

if (isDefaultBlueprint(blueprint)) {
blueprint = await loadDefaultBlueprintFromDisk({
cwd,
version: from
let existingBlueprint = findBlueprint(emberCliUpdateJson, packageName, blueprintName);
if (existingBlueprint) {
blueprint = existingBlueprint;
} else {
blueprint = loadSafeBlueprint({
packageName,
name: blueprintName,
location: parsedPackage.location
});

if (isDefaultBlueprint(blueprint)) {
blueprint = await loadDefaultBlueprintFromDisk({
cwd,
version: from
});
}
}

}

if (from) {
Expand Down
21 changes: 19 additions & 2 deletions src/normalize-blueprint-args.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
'use strict';

const path = require('path');
const fs = require('fs');

function normalizeBlueprintArgs({
packageName,
blueprintName
}) {
let localLocation;

if (!packageName) {
packageName = blueprintName;
let potentialLocalPath = path.join(
process.cwd(),
blueprintName,
'package.json'
);

if (fs.existsSync(potentialLocalPath)) {
packageName = require(potentialLocalPath).name;
localLocation = potentialLocalPath;
} else {
packageName = blueprintName;
}
}

return {
packageName,
blueprintName
blueprintName,
localLocation
};
}

Expand Down
10 changes: 9 additions & 1 deletion src/parse-blueprint-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ function toPosixAbsolutePath(path) {

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

if (localLocation) {
return {
name: packageName,
location: localLocation,
};
}

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