From 36921d10761a51abb54a952fa78167a7e964088f Mon Sep 17 00:00:00 2001 From: NullVoxPopuli Date: Thu, 4 Jun 2020 11:16:23 -0400 Subject: [PATCH] support local paths --- src/index.js | 57 ++++++++++++++++++++------------- src/normalize-blueprint-args.js | 21 ++++++++++-- src/parse-blueprint-package.js | 10 +++++- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/index.js b/src/index.js index 5473ac49e..38540794a 100644 --- a/src/index.js +++ b/src/index.js @@ -64,6 +64,7 @@ module.exports = async function emberCliUpdate({ let blueprint; let packageUrl; + debugger; if (_blueprint) { let blueprintArgs = normalizeBlueprintArgs({ packageName, @@ -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) { diff --git a/src/normalize-blueprint-args.js b/src/normalize-blueprint-args.js index b5336e927..044eedd09 100644 --- a/src/normalize-blueprint-args.js +++ b/src/normalize-blueprint-args.js @@ -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 }; } diff --git a/src/parse-blueprint-package.js b/src/parse-blueprint-package.js index 167d3102f..5017d013b 100644 --- a/src/parse-blueprint-package.js +++ b/src/parse-blueprint-package.js @@ -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)) {