@apphosting/create
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -7,9 +7,14 @@ #! /usr/bin/env node | ||
import ora from "ora"; | ||
console.log(process); | ||
const contextIsNpmCreate = process.env.npm_command === "init"; | ||
// npm/10.1.0 node/v20.9.0 darwin x64 workspaces/false | ||
// pnpm/9.1.0 npm/? node/v20.9.0 darwin x64 | ||
// yarn/1.7.0 npm/? node/v8.9.4 darwin x64 | ||
const npmUserAgent = process.env.npm_config_user_agent | ||
? Object.fromEntries(process.env.npm_config_user_agent.split(" ").map((s) => s.split("/"))) | ||
: {}; | ||
program | ||
.option("--framework <string>") | ||
.option("--package-manager <string>") | ||
.option("--skip-install") | ||
.argument("<directory>", "path to the project's root directory") | ||
.action(async (dir, { framework, packageManager, skipInstall, }) => { | ||
.action(async (dir, { framework, packageManager }) => { | ||
// TODO DRY up the validation and error handling, move to commander parse | ||
@@ -31,8 +36,6 @@ if (framework) { | ||
} | ||
const cloneSpinner = ora("Cloning template...").start(); | ||
// TODO allow different templates | ||
await downloadTemplate(`gh:FirebaseExtended/firebase-framework-tools/starters/${framework}/basic`, { dir, force: true }); | ||
cloneSpinner.succeed(); | ||
// TODO DRY up validation and error message, move to commander parse | ||
let packageManagerVersion = "*"; | ||
if (packageManager) { | ||
[packageManager, packageManagerVersion = "*"] = packageManager.split("@"); | ||
if (!["npm", "yarn", "pnpm"].includes(packageManager)) { | ||
@@ -43,2 +46,13 @@ console.error(`Invalid package manager: ${packageManager}, valid choices are npm, yarn, and pnpm`); | ||
} | ||
else if (contextIsNpmCreate) { | ||
packageManager = "npm"; | ||
} | ||
else if (npmUserAgent.yarn) { | ||
packageManager = "yarn"; | ||
packageManagerVersion = npmUserAgent.yarn; | ||
} | ||
else if (npmUserAgent.pnpm) { | ||
packageManager = "pnpm"; | ||
packageManagerVersion = npmUserAgent.pnpm; | ||
} | ||
else { | ||
@@ -55,4 +69,9 @@ packageManager = await select({ | ||
} | ||
if (packageManager !== "npm") { | ||
await spawn("corepack", ["enable"], { | ||
const cloneSpinner = ora("Cloning template...").start(); | ||
// TODO allow different templates | ||
await downloadTemplate(`gh:FirebaseExtended/firebase-framework-tools/starters/${framework}/basic`, { dir, force: true }); | ||
cloneSpinner.succeed(); | ||
if (packageManager === "npm") { | ||
console.log(`> ${packageManager} install`); | ||
await spawn(packageManager, ["install"], { | ||
shell: true, | ||
@@ -62,3 +81,5 @@ stdio: "inherit", | ||
}); | ||
await spawn("corepack", ["use", `${packageManager}@*`], { | ||
} | ||
else { | ||
await spawn("corepack", ["enable"], { | ||
shell: true, | ||
@@ -68,6 +89,3 @@ stdio: "inherit", | ||
}); | ||
} | ||
if (!skipInstall) { | ||
const installSpinner = ora("Installing dependencies...").start(); | ||
await spawn(packageManager, ["install"], { | ||
await spawn("corepack", ["use", `${packageManager}@${packageManagerVersion}`], { | ||
shell: true, | ||
@@ -77,5 +95,4 @@ stdio: "inherit", | ||
}); | ||
installSpinner.succeed(); | ||
} | ||
}); | ||
program.parse(); |
{ | ||
"name": "@apphosting/create", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"main": "dist/index.js", | ||
@@ -11,3 +11,3 @@ "description": "Experimental addon to the Firebase CLI to add web framework support", | ||
"bin": { | ||
"@apphosting/create": "dist/bin/create.js" | ||
"apphosting-create": "dist/bin/create.js" | ||
}, | ||
@@ -14,0 +14,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4457
95
3