-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4447a6c
commit 94711e5
Showing
1 changed file
with
75 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,9 @@ import { upstreamOpt } from "./opt-upstream"; | |
import { workDirOpt } from "./opt-wd"; | ||
import { mustBePackageSpec } from "./validators"; | ||
|
||
const packageSpecArg = new Argument( | ||
"<pkg>", | ||
const packageSpecsArg = new Argument( | ||
"[<package-spec>...]", | ||
"Reference to the package that should be added" | ||
).argParser(mustBePackageSpec); | ||
|
||
const otherPackageSpecsArg = new Argument( | ||
"[otherPkgs...]", | ||
"References to additional packages that should be added" | ||
).argParser(eachValue(mustBePackageSpec)); | ||
|
||
const addTestableOpt = new Option( | ||
|
@@ -82,83 +77,91 @@ export function makeAddCmd( | |
); | ||
|
||
return new Command("add") | ||
.aliases(["install", "i"]) | ||
.addArgument(packageSpecArg) | ||
.addArgument(otherPackageSpecsArg) | ||
.aliases([ | ||
"ad", | ||
"i", | ||
"in", | ||
"ins", | ||
"inst", | ||
"insta", | ||
"instal", | ||
"isnt", | ||
"isnta", | ||
"isntal", | ||
"isntall", | ||
"install", | ||
]) | ||
.addArgument(packageSpecsArg) | ||
.addOption(addTestableOpt) | ||
.addOption(forceOpt) | ||
.addOption(primaryRegistriesUrlOpt) | ||
.addOption(workDirOpt) | ||
.addOption(systemUserOpt) | ||
.addOption(upstreamOpt) | ||
.summary("add a dependency to the project") | ||
.description( | ||
`add package to manifest json | ||
openupm add <pkg> [otherPkgs...] | ||
openupm add <pkg>@<version> [otherPkgs...]` | ||
`Add a dependency to the project as well as all indirect dependencies. | ||
openupm add com.some.package@latest | ||
openupm add [email protected]` | ||
) | ||
.action( | ||
withErrorLogger( | ||
log, | ||
async function (packageSpec, otherPackageSpecs, options) { | ||
const packageSpecs = [packageSpec].concat(otherPackageSpecs); | ||
|
||
const projectDirectory = options.chdir; | ||
|
||
const editorVersion = await determineEditorVersion(projectDirectory); | ||
withErrorLogger(log, async function (packageSpecs, options) { | ||
const projectDirectory = options.chdir; | ||
|
||
if (typeof editorVersion === "string") | ||
log.warn( | ||
"editor.version", | ||
`${editorVersion} is unknown, the editor version check is disabled` | ||
); | ||
|
||
const homePath = getHomePathFromEnv(process.env); | ||
const upmConfigPath = getUserUpmConfigPathFor( | ||
process.env, | ||
homePath, | ||
options.systemUser | ||
); | ||
const editorVersion = await determineEditorVersion(projectDirectory); | ||
|
||
const sources = await Promise.all( | ||
(options.registry ?? [openupmRegistryUrl]).map((it) => | ||
getRegistryAuth(upmConfigPath, it) | ||
) | ||
if (typeof editorVersion === "string") | ||
log.warn( | ||
"editor.version", | ||
`${editorVersion} is unknown, the editor version check is disabled` | ||
); | ||
|
||
if (options.upstream) sources.push(unityRegistry); | ||
|
||
const addResults = await addDependencies( | ||
projectDirectory, | ||
typeof editorVersion === "string" ? null : editorVersion, | ||
sources, | ||
options.force, | ||
options.test, | ||
packageSpecs | ||
); | ||
|
||
recordEntries(addResults) | ||
.map(([packageName, addResult]) => { | ||
switch (addResult.type) { | ||
case "added": | ||
return `added ${makePackageSpec( | ||
packageName, | ||
addResult.version | ||
)}`; | ||
case "upgraded": | ||
return `modified ${packageName} ${addResult.fromVersion} => ${addResult.toVersion}`; | ||
case "noChange": | ||
return `existed ${makePackageSpec( | ||
packageName, | ||
addResult.version | ||
)}`; | ||
} | ||
}) | ||
.forEach((message) => { | ||
log.notice("", message); | ||
}); | ||
|
||
log.notice("", "please open Unity project to apply changes."); | ||
} | ||
) | ||
const homePath = getHomePathFromEnv(process.env); | ||
const upmConfigPath = getUserUpmConfigPathFor( | ||
process.env, | ||
homePath, | ||
options.systemUser | ||
); | ||
|
||
const sources = await Promise.all( | ||
(options.registry ?? [openupmRegistryUrl]).map((it) => | ||
getRegistryAuth(upmConfigPath, it) | ||
) | ||
); | ||
|
||
if (options.upstream) sources.push(unityRegistry); | ||
|
||
const addResults = await addDependencies( | ||
projectDirectory, | ||
typeof editorVersion === "string" ? null : editorVersion, | ||
sources, | ||
options.force, | ||
options.test, | ||
packageSpecs | ||
); | ||
|
||
recordEntries(addResults) | ||
.map(([packageName, addResult]) => { | ||
switch (addResult.type) { | ||
case "added": | ||
return `added ${makePackageSpec( | ||
packageName, | ||
addResult.version | ||
)}`; | ||
case "upgraded": | ||
return `modified ${packageName} ${addResult.fromVersion} => ${addResult.toVersion}`; | ||
case "noChange": | ||
return `existed ${makePackageSpec( | ||
packageName, | ||
addResult.version | ||
)}`; | ||
} | ||
}) | ||
.forEach((message) => { | ||
log.notice("", message); | ||
}); | ||
|
||
log.notice("", "please open Unity project to apply changes."); | ||
}) | ||
); | ||
} |