-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pooya Parsa <[email protected]> Co-authored-by: uncenter <[email protected]>
- Loading branch information
1 parent
957c995
commit c4bdecb
Showing
6 changed files
with
130 additions
and
21 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Generator } from "../generator"; | ||
import jsdocs from "./jsdocs"; | ||
import pmInstall from "./pm-install"; | ||
|
||
export default { | ||
jsdocs, | ||
"pm-install": pmInstall, | ||
} as Record<string, Generator>; |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { readPackageJSON } from "pkg-types"; | ||
import { codeBlock } from "omark"; | ||
import { defineGenerator } from "../generator"; | ||
|
||
export default defineGenerator({ | ||
name: "pm-install", | ||
async generate({ options, args }) { | ||
const name = args.name || (await inferPackageName(options.dir)); | ||
|
||
if (!name) { | ||
return { | ||
contents: "<!-- package name is unspecified -->", | ||
}; | ||
} | ||
|
||
const pkgInstalls = [ | ||
["npm", "install"], | ||
["yarn", "add"], | ||
["pnpm", "install"], | ||
["bun", "install"], | ||
]; | ||
|
||
// TODO: support noAuto/no-auto | ||
if (args.auto ?? true) { | ||
pkgInstalls.unshift(["npx nypm", "i"]); | ||
} | ||
|
||
return { | ||
contents: codeBlock( | ||
pkgInstalls | ||
.map( | ||
([cmd, install]) => | ||
`# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}`, | ||
) | ||
.join("\n\n"), | ||
"sh", | ||
), | ||
}; | ||
}, | ||
}); | ||
|
||
async function inferPackageName(dir: string) { | ||
const pkgName = await readPackageJSON(dir) | ||
.then((pkg) => pkg?.name) | ||
.catch(() => undefined); | ||
return pkgName || process.env.npm_package_name; | ||
} |