Socket
Book a DemoInstallSign in
Socket

fambda

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fambda - npm Package Compare versions

Comparing version

to
1.0.1

readme.md

77

dist/index.js

@@ -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`;
}
SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.