Comparing version
@@ -28,2 +28,4 @@ #!/usr/bin/env node | ||
var import_fs = require("fs"); | ||
var import_path = require("path"); | ||
var readline = __toESM(require("readline")); | ||
var host = "https://sf5yrb4fnvqb3mgdcxvmobwr4q0mhyku.lambda-url.us-east-1.on.aws"; | ||
@@ -37,12 +39,15 @@ function exit(code, message) { | ||
async function main() { | ||
const path = process.argv[2]; | ||
if (!path) { | ||
exit(1, "no path, run with: deploy <project> <path>"); | ||
const _path = process.argv[2]; | ||
if (!_path) { | ||
exit(1, "npx frunc <path>"); | ||
} | ||
const absolutePath = path.startsWith("/") ? path : `${process.cwd()}/${path}`; | ||
if (!await isDirectory(absolutePath)) { | ||
exit(1, `${absolutePath} is not a directory`); | ||
let path = (0, import_path.normalize)(_path); | ||
if (!isDirectory(path)) { | ||
path = (0, import_path.dirname)(path); | ||
} | ||
const deployInfoPath = `${absolutePath}/deploy.json`; | ||
const deployInfo = await readJSON(deployInfoPath) || { | ||
const deployInfoDirectory = getParentDirectoryWith(path, (p) => { | ||
return isDirectory(p) && (0, import_fs.existsSync)(`${p}/package.json`); | ||
}) || path; | ||
const deployInfoPath = `${deployInfoDirectory}/.deploy.json`; | ||
const deployInfo = readJSON(deployInfoPath) || { | ||
project: "", | ||
@@ -53,8 +58,6 @@ secret: "" | ||
const projectName = await prompt("Project name: "); | ||
if (!projectName) { | ||
exit(1, "no project name"); | ||
} | ||
if (!projectName) exit(1, "no project name"); | ||
deployInfo.project = projectName; | ||
} | ||
const indexJsPath = `${absolutePath}/index.js`; | ||
const indexJsPath = `${path}/index.js`; | ||
if (!(0, import_fs.existsSync)(indexJsPath)) { | ||
@@ -81,3 +84,5 @@ exit(1, `${indexJsPath} does not exist`); | ||
const url = `${host}/${deployInfo.project}/_deploy`; | ||
console.log("Deploying to", url); | ||
console.log(` | ||
\u{1F4E6} Deploying ${path}...`); | ||
try { | ||
@@ -95,3 +100,11 @@ const response = await fetch(url, { | ||
const deployInfoResponse = await response.json(); | ||
console.log("Deploy info:", deployInfoResponse); | ||
console.log(`\u2705 Deploy successful in ${deployInfoResponse.took}ms...`); | ||
console.log( | ||
"\u{1F680}", | ||
link( | ||
`https://on.aws/${deployBody.project}/${deployInfoResponse.hash}`, | ||
deployInfoResponse.url | ||
) | ||
); | ||
console.log("\n"); | ||
deployInfo.secret = deployInfoResponse.secret; | ||
@@ -107,6 +120,5 @@ await fs.promises.writeFile( | ||
main(); | ||
async function isDirectory(path) { | ||
function isDirectory(path) { | ||
try { | ||
const stats = await fs.promises.stat(path); | ||
return stats.isDirectory(); | ||
return fs.statSync(path).isDirectory(); | ||
} catch (error) { | ||
@@ -116,8 +128,33 @@ return false; | ||
} | ||
async function readJSON(path) { | ||
function readJSON(path) { | ||
try { | ||
const data = await fs.promises.readFile(path, "utf8"); | ||
return JSON.parse(data); | ||
return JSON.parse(fs.readFileSync(path, "utf8")); | ||
} catch (error) { | ||
} | ||
} | ||
function getParentDirectory(path) { | ||
const parent = (0, import_path.dirname)(path); | ||
if (parent === path) return path; | ||
return getParentDirectory(parent); | ||
} | ||
function getParentDirectoryWith(path, f) { | ||
const parent = getParentDirectory(path); | ||
if (parent === path) return void 0; | ||
if (f(parent)) return parent; | ||
return getParentDirectoryWith(parent, f); | ||
} | ||
async function prompt(message) { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
return new Promise((resolve) => { | ||
rl.question(message, (answer) => { | ||
rl.close(); | ||
resolve(answer); | ||
}); | ||
}); | ||
} | ||
function link(text, url) { | ||
return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`; | ||
} |
{ | ||
"name": "fambda", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"packageManager": "yarn@4.3.0", | ||
"scripts": { | ||
"build": "esbuild src/index.ts --bundle --platform=node --banner:js=\"#!/usr/bin/env node\" --outfile=dist/index.js", | ||
"cli": "yarn run build && node dist/index.js" | ||
"cli": "npm run build && node dist/index.js", | ||
"publish": "npm run build && npm version patch && npm publish" | ||
}, | ||
@@ -9,0 +10,0 @@ "bin": { |
import * as fs from "fs"; | ||
import { existsSync } from "fs"; | ||
import { dirname, normalize } from "path"; | ||
import * as readline from "readline"; | ||
@@ -16,28 +18,33 @@ const host = | ||
// Get a path from the command line | ||
const path = process.argv[2]; | ||
if (!path) { | ||
exit(1, "no path, run with: deploy <project> <path>"); | ||
const _path = process.argv[2]; | ||
if (!_path) { | ||
exit(1, "npx frunc <path>"); | ||
} | ||
const absolutePath = path.startsWith("/") ? path : `${process.cwd()}/${path}`; | ||
let path = normalize(_path); | ||
// Check if the path is a directory | ||
if (!(await isDirectory(absolutePath))) { | ||
exit(1, `${absolutePath} is not a directory`); | ||
// If the path is a file, get the parent directory | ||
if (!isDirectory(path)) { | ||
path = dirname(path); | ||
} | ||
// Check if we already have deploy info file | ||
const deployInfoPath = `${absolutePath}/deploy.json`; | ||
const deployInfo = (await readJSON(deployInfoPath)) || { | ||
const deployInfoDirectory = | ||
getParentDirectoryWith(path, (p) => { | ||
return isDirectory(p) && existsSync(`${p}/package.json`); | ||
}) || path; | ||
const deployInfoPath = `${deployInfoDirectory}/.deploy.json`; | ||
// console.debug({ deployInfoPath }); | ||
const deployInfo = readJSON(deployInfoPath) || { | ||
project: "", | ||
secret: "", | ||
}; | ||
// console.debug({ deployInfo }); | ||
if (!deployInfo.project) { | ||
// Ask for the project name | ||
const projectName = await prompt("Project name: "); | ||
if (!projectName) { | ||
exit(1, "no project name"); | ||
} | ||
if (!projectName) exit(1, "no project name"); | ||
deployInfo.project = projectName; | ||
@@ -47,3 +54,3 @@ } | ||
// Check if the directory has an index.js file | ||
const indexJsPath = `${absolutePath}/index.js`; | ||
const indexJsPath = `${path}/index.js`; | ||
if (!existsSync(indexJsPath)) { | ||
@@ -77,3 +84,3 @@ exit(1, `${indexJsPath} does not exist`); | ||
const url = `${host}/${deployInfo.project}/_deploy`; | ||
console.log("Deploying to", url); | ||
console.log(`\n\nš¦ Deploying ${path}...`); | ||
@@ -94,4 +101,14 @@ try { | ||
const deployInfoResponse = await response.json(); | ||
console.log("Deploy info:", deployInfoResponse); | ||
// console.log("Deploy info:", deployInfoResponse); | ||
console.log(`ā Deploy successful in ${deployInfoResponse.took}ms...`); | ||
console.log( | ||
"š", | ||
link( | ||
`https://on.aws/${deployBody.project}/${deployInfoResponse.hash}`, | ||
deployInfoResponse.url | ||
) | ||
); | ||
console.log("\n"); | ||
// Update the deploy info | ||
@@ -110,6 +127,5 @@ deployInfo.secret = deployInfoResponse.secret; | ||
async function isDirectory(path: string): Promise<boolean> { | ||
function isDirectory(path: string): boolean { | ||
try { | ||
const stats = await fs.promises.stat(path); | ||
return stats.isDirectory(); | ||
return fs.statSync(path).isDirectory(); | ||
} catch (error) { | ||
@@ -120,7 +136,40 @@ return false; | ||
async function readJSON<T = any>(path: string): Promise<T | undefined> { | ||
function readJSON<T = any>(path: string): T | undefined { | ||
try { | ||
const data = await fs.promises.readFile(path, "utf8"); | ||
return JSON.parse(data); | ||
return JSON.parse(fs.readFileSync(path, "utf8")); | ||
} catch (error) {} | ||
} | ||
function getParentDirectory(path: string): string { | ||
const parent = dirname(path); | ||
if (parent === path) return path; | ||
return getParentDirectory(parent); | ||
} | ||
function getParentDirectoryWith( | ||
path: string, | ||
f: (path: string) => boolean | ||
): string | undefined { | ||
const parent = getParentDirectory(path); | ||
if (parent === path) return undefined; | ||
if (f(parent)) return parent; | ||
return getParentDirectoryWith(parent, f); | ||
} | ||
async function prompt(message: string): Promise<string> { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
return new Promise((resolve) => { | ||
rl.question(message, (answer) => { | ||
rl.close(); | ||
resolve(answer); | ||
}); | ||
}); | ||
} | ||
function link(text: string, url: string): string { | ||
return `\u001b]8;;${url}\u0007${text}\u001b]8;;\u0007`; | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
0
-100%4
-77.78%2
-60%9195
-99.91%4
-78.95%1
Infinity%291
-91.32%