Skip to content

Commit

Permalink
add cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeVanti committed Nov 1, 2024
1 parent 4447a6c commit 94711e5
Showing 1 changed file with 75 additions and 72 deletions.
147 changes: 75 additions & 72 deletions src/cli/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 com.some.package@1.2.3`
)
.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.");
})
);
}

0 comments on commit 94711e5

Please sign in to comment.