@blitzjs/cli
Advanced tools
Comparing version 0.9.1 to 0.9.2-canary.0
@@ -81,3 +81,3 @@ "use strict"; | ||
// run migration | ||
//await runMigrate() | ||
yield exports.runMigrate(); | ||
server_1.log.success('Your database has been reset.'); | ||
@@ -115,3 +115,3 @@ process.exit(0); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const dbPath = connectionString.replace(/^(?:\.\.\/)+/, ''); | ||
const dbPath = connectionString.replace(/^(?:\.\.[\\/])+/, ''); | ||
const unlink = util_1.promisify(fs.unlink); | ||
@@ -188,3 +188,5 @@ try { | ||
if (res.confirm) { | ||
const db = require(path.join(get_project_root_1.projectRoot, 'db')).default; | ||
const prismaClientPath = require.resolve('@prisma/client', { paths: [get_project_root_1.projectRoot] }); | ||
const { PrismaClient } = require(prismaClientPath); | ||
const db = new PrismaClient(); | ||
const dataSource = db.internalDatasources[0]; | ||
@@ -191,0 +193,0 @@ const connectorType = dataSource.connectorType; |
@@ -6,15 +6,144 @@ "use strict"; | ||
const path = tslib_1.__importStar(require("path")); | ||
// eslint-disable-next-line import/no-default-export | ||
const got_1 = tslib_1.__importDefault(require("got")); | ||
const server_1 = require("@blitzjs/server"); | ||
const dedent_1 = require("../utils/dedent"); | ||
const stream_1 = require("stream"); | ||
const util_1 = require("util"); | ||
const tar_1 = tslib_1.__importDefault(require("tar")); | ||
const fs_extra_1 = require("fs-extra"); | ||
const rimraf_1 = tslib_1.__importDefault(require("rimraf")); | ||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); | ||
const os = tslib_1.__importStar(require("os")); | ||
const pipeline = util_1.promisify(stream_1.Stream.pipeline); | ||
function got(url) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return got_1.default(url).catch((e) => Boolean(console.error(e)) || e); | ||
}); | ||
} | ||
function gotJSON(url) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return JSON.parse((yield got(url)).body); | ||
}); | ||
} | ||
function isUrlValid(url) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return (yield got(url).catch((e) => e)).statusCode === 200; | ||
}); | ||
} | ||
function requireJSON(file) { | ||
return JSON.parse(fs_extra_1.readFileSync(file).toString('utf-8')); | ||
} | ||
const GH_ROOT = 'https://github.com/'; | ||
const API_ROOT = 'https://api.github.com/repos/'; | ||
const CODE_ROOT = 'https://codeload.github.com/'; | ||
var InstallerType; | ||
(function (InstallerType) { | ||
InstallerType[InstallerType["Local"] = 0] = "Local"; | ||
InstallerType[InstallerType["Remote"] = 1] = "Remote"; | ||
})(InstallerType = exports.InstallerType || (exports.InstallerType = {})); | ||
class Install extends command_1.Command { | ||
// exposed for testing | ||
normalizeInstallerPath(installerArg) { | ||
const isNavtiveInstaller = /^([\w\-_]*)$/.test(installerArg); | ||
const isUrlInstaller = installerArg.startsWith(GH_ROOT); | ||
const isGitHubShorthandInstaller = /^([\w-_]*)\/([\w-_]*)$/.test(installerArg); | ||
if (isNavtiveInstaller || isUrlInstaller || isGitHubShorthandInstaller) { | ||
let repoUrl; | ||
let subdirectory; | ||
switch (true) { | ||
case isUrlInstaller: | ||
repoUrl = installerArg; | ||
break; | ||
case isNavtiveInstaller: | ||
repoUrl = `${GH_ROOT}blitz-js/blitz`; | ||
subdirectory = `installers/${installerArg}`; | ||
break; | ||
case isGitHubShorthandInstaller: | ||
repoUrl = `${GH_ROOT}${installerArg}`; | ||
break; | ||
default: | ||
throw new Error('should be impossible, the 3 cases are the only way to get into this switch'); | ||
} | ||
return { | ||
path: repoUrl, | ||
subdirectory, | ||
type: InstallerType.Remote, | ||
}; | ||
} | ||
else { | ||
return { | ||
path: installerArg, | ||
type: InstallerType.Local, | ||
}; | ||
} | ||
} | ||
/** | ||
* Clones the repository into a temp directory, returning the path to the new directory | ||
* | ||
* Exposed for unit testing | ||
* | ||
* @param repoFullName username and repository name in the form {{user}}/{{repo}} | ||
* @param defaultBranch the name of the repository's default branch | ||
*/ | ||
cloneRepo(repoFullName, defaultBranch, subdirectory) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const installerDir = path.join(os.tmpdir(), `blitz-installer-${repoFullName.replace('/', '-')}`); | ||
// clean up from previous run in case of error | ||
rimraf_1.default.sync(installerDir); | ||
fs_extra_1.mkdirSync(installerDir); | ||
process.chdir(installerDir); | ||
const repoName = repoFullName.split('/')[1]; | ||
// `tar` top-level filder is `${repoName}-${defaultBranch}`, and then we want to get our installer path | ||
// within that folder | ||
const extractPath = subdirectory ? [`${repoName}-${defaultBranch}/${subdirectory}`] : undefined; | ||
const depth = subdirectory ? subdirectory.split('/').length + 1 : 1; | ||
yield pipeline(got_1.default.stream(`${CODE_ROOT}${repoFullName}/tar.gz/${defaultBranch}`), tar_1.default.extract({ strip: depth }, extractPath)); | ||
return installerDir; | ||
}); | ||
} | ||
runInstallerAtPath(installerPath) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const installer = require(installerPath).default; | ||
const installerArgs = this.argv.slice(1).reduce((acc, arg) => (Object.assign(Object.assign({}, acc), { [arg.split('=')[0].replace(/--/g, '')]: arg.split('=')[1] | ||
? JSON.parse(`"${arg.split('=')[1]}"`) | ||
: true })), {}); | ||
yield installer.run(installerArgs); | ||
}); | ||
} | ||
run() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { args } = this.parse(Install); | ||
const isNavtiveInstaller = /^([\w]*)$/.test(args.installer); | ||
if (isNavtiveInstaller) { | ||
const pkgManager = fs_extra_1.existsSync(path.resolve('yarn.lock')) ? 'yarn' : 'npm'; | ||
const originalCwd = process.cwd(); | ||
const installerInfo = this.normalizeInstallerPath(args.installer); | ||
if (installerInfo.type === InstallerType.Remote) { | ||
const apiUrl = installerInfo.path.replace(GH_ROOT, API_ROOT); | ||
const packageJsonPath = `${apiUrl}/contents/package.json`; | ||
if (!(yield isUrlValid(packageJsonPath))) { | ||
server_1.log.error(dedent_1.dedent `[blitz install] Installer path "${args.installer}" isn't valid. Please provide: | ||
1. The name of a dependency to install (e.g. "tailwind"), | ||
2. The full name of a GitHub repository (e.g. "blitz-js/example-installer"), | ||
3. A full URL to a Github repository (e.g. "https://github.com/blitz-js/example-installer"), or | ||
4. A file path to a locally-written installer.`); | ||
} | ||
else { | ||
const repoInfo = yield gotJSON(apiUrl); | ||
let spinner = server_1.log.spinner(`Cloning GitHub repository for ${args.installer}`).start(); | ||
const installerRepoPath = yield this.cloneRepo(repoInfo.full_name, repoInfo.default_branch, installerInfo.subdirectory); | ||
spinner.stop(); | ||
spinner = server_1.log.spinner('Installing package.json dependencies').start(); | ||
yield new Promise((resolve) => { | ||
const installProcess = cross_spawn_1.default(pkgManager, ['install']); | ||
installProcess.on('exit', resolve); | ||
}); | ||
spinner.stop(); | ||
const installerPackageMain = requireJSON('./package.json').main; | ||
const installerEntry = path.resolve(installerPackageMain); | ||
process.chdir(originalCwd); | ||
yield this.runInstallerAtPath(installerEntry); | ||
rimraf_1.default.sync(installerRepoPath); | ||
} | ||
} | ||
else { | ||
const installerPath = path.resolve(args.installer); | ||
const installer = require(installerPath).default; | ||
const installerArgs = this.argv.reduce((acc, arg) => (Object.assign(Object.assign({}, acc), { [arg.split('=')[0]]: JSON.parse(arg.split('=')[1] || String(true)) })), {}); | ||
yield installer.run(installerArgs); | ||
yield this.runInstallerAtPath(path.resolve(args.installer)); | ||
} | ||
@@ -24,3 +153,3 @@ }); | ||
} | ||
exports.default = Install; | ||
exports.Install = Install; | ||
Install.description = 'Install a third-party package into your Blitz app'; | ||
@@ -27,0 +156,0 @@ Install.aliases = ['i']; |
{ | ||
"name": "@blitzjs/cli", | ||
"description": "Blitz.js CLI", | ||
"version": "0.9.1", | ||
"version": "0.9.2-canary.0", | ||
"license": "MIT", | ||
@@ -30,31 +30,35 @@ "scripts": { | ||
"dependencies": { | ||
"@oclif/command": "^1.5.20", | ||
"@oclif/config": "^1.15.1", | ||
"@oclif/plugin-help": "^2.2.3", | ||
"@oclif/plugin-not-found": "^1.2.3", | ||
"camelcase": "^6.0.0", | ||
"chalk": "^4.0.0", | ||
"chokidar": "^3.3.1", | ||
"cross-spawn": "^7.0.2", | ||
"dotenv": "^8.2.0", | ||
"enquirer": "^2.3.4", | ||
"globby": "^11.0.0", | ||
"got": "^11.0.2", | ||
"has-yarn": "^2.1.0", | ||
"hasbin": "^1.2.3", | ||
"minimist": "^1.2.5", | ||
"pkg-dir": "^4.2.0", | ||
"pluralize": "^8.0.0", | ||
"ts-node": "^8.9.0", | ||
"@oclif/command": "1.5.20", | ||
"@oclif/config": "1.15.1", | ||
"@oclif/plugin-help": "2.2.3", | ||
"@oclif/plugin-not-found": "1.2.3", | ||
"camelcase": "6.0.0", | ||
"chalk": "4.0.0", | ||
"chokidar": "3.3.1", | ||
"cross-spawn": "7.0.2", | ||
"dotenv": "8.2.0", | ||
"enquirer": "2.3.4", | ||
"globby": "11.0.0", | ||
"got": "11.1.3", | ||
"has-yarn": "2.1.0", | ||
"hasbin": "1.2.3", | ||
"minimist": "1.2.5", | ||
"pkg-dir": "4.2.0", | ||
"pluralize": "8.0.0", | ||
"rimraf": "3.0.2", | ||
"tar": "6.0.2", | ||
"ts-node": "8.9.0", | ||
"tsconfig-paths": "3.9.0" | ||
}, | ||
"devDependencies": { | ||
"@blitzjs/generator": "0.9.1", | ||
"@blitzjs/installer": "0.9.1", | ||
"@blitzjs/server": "0.9.1", | ||
"@oclif/dev-cli": "^1.22.2", | ||
"@oclif/test": "^1.2.5", | ||
"@blitzjs/generator": "0.9.2-canary.0", | ||
"@blitzjs/installer": "0.9.2-canary.0", | ||
"@blitzjs/server": "0.9.2-canary.0", | ||
"@oclif/dev-cli": "1.22.2", | ||
"@oclif/test": "1.2.5", | ||
"@prisma/cli": "2.0.0-beta.3", | ||
"@rollup/pluginutils": "^3.0.8", | ||
"@types/pluralize": "^0.0.29", | ||
"@rollup/pluginutils": "3.0.8", | ||
"@types/pluralize": "0.0.29", | ||
"@types/rimraf": "3.0.0", | ||
"@types/tar": "4.0.3", | ||
"nock": "13.0.0-beta.3" | ||
@@ -83,3 +87,3 @@ }, | ||
}, | ||
"gitHead": "ea91de84c01f5045fc71828b63cdab77c0855826" | ||
"gitHead": "114ae77bec73166558817bad87d4a18c98bfd0c0" | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
46992
22
1072
21
11
10
+ Addedrimraf@3.0.2
+ Addedtar@6.0.2
+ Added@oclif/color@0.0.0(transitive)
+ Added@oclif/command@1.5.20(transitive)
+ Added@oclif/config@1.15.1(transitive)
+ Added@oclif/plugin-not-found@1.2.3(transitive)
+ Added@sindresorhus/is@2.1.1(transitive)
+ Addedansi-colors@3.2.4(transitive)
+ Addedansi-escapes@3.2.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcacheable-lookup@4.3.0(transitive)
+ Addedcamelcase@6.0.0(transitive)
+ Addedchalk@4.0.0(transitive)
+ Addedchokidar@3.3.1(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcli-ux@4.9.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-spawn@7.0.2(transitive)
+ Addeddecompress-response@5.0.0(transitive)
+ Addeddotenv@8.2.0(transitive)
+ Addedenquirer@2.3.4(transitive)
+ Addedextract-stack@1.0.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfs-extra@7.0.1(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.1.3(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglobby@11.0.0(transitive)
+ Addedgot@11.1.3(transitive)
+ Addedhas-flag@2.0.0(transitive)
+ Addedindent-string@3.2.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-wsl@1.1.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.5(transitive)
+ Addedminipass@3.3.6(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedreaddirp@3.3.0(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsupports-hyperlinks@1.0.1(transitive)
+ Addedtar@6.0.2(transitive)
+ Addedtreeify@1.1.0(transitive)
+ Addedts-node@8.9.0(transitive)
+ Addedyallist@4.0.0(transitive)
- Removed@oclif/color@0.1.2(transitive)
- Removed@oclif/command@1.8.111.8.36(transitive)
- Removed@oclif/config@1.18.161.18.17(transitive)
- Removed@oclif/help@1.0.15(transitive)
- Removed@oclif/plugin-help@3.2.14(transitive)
- Removed@oclif/plugin-not-found@1.2.6(transitive)
- Removed@sindresorhus/is@4.6.0(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedargparse@1.0.10(transitive)
- Removedcacheable-lookup@5.0.4(transitive)
- Removedcamelcase@6.3.0(transitive)
- Removedchalk@3.0.0(transitive)
- Removedchokidar@3.6.0(transitive)
- Removedcli-progress@3.12.0(transitive)
- Removedcli-ux@5.6.6(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removeddotenv@8.6.0(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedenquirer@2.4.1(transitive)
- Removedextract-stack@2.0.0(transitive)
- Removedfast-levenshtein@3.0.0(transitive)
- Removedfastest-levenshtein@1.0.16(transitive)
- Removedfsevents@2.3.3(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgot@11.8.6(transitive)
- Removedis-docker@2.2.1(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednatural-orderby@2.0.3(transitive)
- Removedobject-treeify@1.1.33(transitive)
- Removedreaddirp@3.6.0(transitive)
- Removedsemver@7.7.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedsupports-color@8.1.1(transitive)
- Removedsupports-hyperlinks@2.3.0(transitive)
- Removedts-node@8.10.2(transitive)
- Removedwidest-line@3.1.0(transitive)
- Removedwrap-ansi@6.2.0(transitive)
Updated@oclif/command@1.5.20
Updated@oclif/config@1.15.1
Updated@oclif/plugin-help@2.2.3
Updatedcamelcase@6.0.0
Updatedchalk@4.0.0
Updatedchokidar@3.3.1
Updatedcross-spawn@7.0.2
Updateddotenv@8.2.0
Updatedenquirer@2.3.4
Updatedglobby@11.0.0
Updatedgot@11.1.3
Updatedhas-yarn@2.1.0
Updatedhasbin@1.2.3
Updatedminimist@1.2.5
Updatedpkg-dir@4.2.0
Updatedpluralize@8.0.0
Updatedts-node@8.9.0