mirror of
https://github.com/rowyio/rowy.git
synced 2026-02-23 19:50:01 +01:00
add error log to sparks lib and resolve issues
This commit is contained in:
@@ -5,12 +5,6 @@ import { commandErrorHandler } from "../utils";
|
||||
const path = require("path");
|
||||
import admin from "firebase-admin";
|
||||
|
||||
async function asyncForEach(array: any[], callback: Function) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
}
|
||||
|
||||
export default async function generateConfig(
|
||||
schemaPath: string,
|
||||
user: admin.auth.UserRecord
|
||||
@@ -31,7 +25,13 @@ export default async function generateConfig(
|
||||
/(?<=(require\(("|'))).*?(?=("|')\))/g
|
||||
);
|
||||
if (requiredDependencies) {
|
||||
await addPackages(requiredDependencies.map((p: any) => ({ name: p })));
|
||||
const packgesAdded = await addPackages(
|
||||
requiredDependencies.map((p: any) => ({ name: p })),
|
||||
user
|
||||
);
|
||||
if (!packgesAdded) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const isFunctionConfigValid = await asyncExecute(
|
||||
@@ -50,10 +50,12 @@ export default async function generateConfig(
|
||||
const requiredSparks = sparksConfig.map((s: any) => s.type);
|
||||
console.log({ requiredSparks });
|
||||
|
||||
await asyncForEach(
|
||||
requiredSparks,
|
||||
async (s: any) => await addSparkLib(s)
|
||||
);
|
||||
for (const lib of requiredSparks) {
|
||||
const success = await addSparkLib(lib, user);
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import * as child from "child_process";
|
||||
import admin from "firebase-admin";
|
||||
import { commandErrorHandler } from "../utils";
|
||||
|
||||
function execute(command: string, callback: any) {
|
||||
console.log(command);
|
||||
@@ -17,33 +19,45 @@ export const asyncExecute = async (command: string, callback: any) =>
|
||||
});
|
||||
});
|
||||
|
||||
export const addPackages = (packages: { name: string; version?: string }[]) =>
|
||||
new Promise((resolve, reject) => {
|
||||
//const command =`cd FT_functions/functions;yarn add ${packageName}@${version}`
|
||||
const packagesString = packages.reduce((acc, currPackage) => {
|
||||
return `${acc} ${currPackage.name}@${currPackage.version ?? "latest"}`;
|
||||
}, "");
|
||||
if (packagesString.trim().length !== 0) {
|
||||
execute("ls", function () {});
|
||||
export const addPackages = async (
|
||||
packages: { name: string; version?: string }[],
|
||||
user: admin.auth.UserRecord
|
||||
) => {
|
||||
const packagesString = packages.reduce((acc, currPackage) => {
|
||||
return `${acc} ${currPackage.name}@${currPackage.version ?? "latest"}`;
|
||||
}, "");
|
||||
if (packagesString.trim().length !== 0) {
|
||||
const success = await asyncExecute(
|
||||
`cd build/functions;yarn add ${packagesString}`,
|
||||
commandErrorHandler({
|
||||
user,
|
||||
description: "Error adding packages",
|
||||
})
|
||||
);
|
||||
return success;
|
||||
}
|
||||
};
|
||||
|
||||
const command = `cd ../functions;yarn add ${packagesString}`;
|
||||
console.log(command);
|
||||
execute(command, function () {
|
||||
resolve(true);
|
||||
});
|
||||
} else resolve(false);
|
||||
});
|
||||
export const addSparkLib = async (
|
||||
name: string,
|
||||
user: admin.auth.UserRecord
|
||||
) => {
|
||||
const { dependencies } = require(`../sparksLib/${name}`);
|
||||
const packages = Object.keys(dependencies).map((key) => ({
|
||||
name: key,
|
||||
version: dependencies[key],
|
||||
}));
|
||||
let success = await addPackages(packages, user);
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export const addSparkLib = (name: string) =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
const { dependencies } = require(`../sparksLib/${name}`);
|
||||
const packages = Object.keys(dependencies).map((key) => ({
|
||||
name: key,
|
||||
version: dependencies[key],
|
||||
}));
|
||||
await addPackages(packages);
|
||||
const command = `cp ../sparksLib/${name}.ts ../functions/src/sparks/${name}.ts`;
|
||||
execute(command, function () {
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
success = await asyncExecute(
|
||||
`cp build/sparksLib/${name}.ts build/functions/src/sparks/${name}.ts`,
|
||||
commandErrorHandler({
|
||||
user,
|
||||
description: "Error copying sparksLib",
|
||||
})
|
||||
);
|
||||
return success;
|
||||
};
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"include": ["src", "generateConfig.ts"],
|
||||
"ignore": ["sparks","sparksLib"]
|
||||
"ignore": ["sparks", "sparksLib"]
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import generateConfig from "./compiler";
|
||||
import { auth } from "./firebaseConfig";
|
||||
import meta from "./package.json";
|
||||
import { commandErrorHandler, logErrorToDB } from "./utils";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
import firebase from "firebase-admin";
|
||||
|
||||
const app = express();
|
||||
@@ -127,6 +125,7 @@ app.post("/", jsonParser, async (req: any, res: any) => {
|
||||
commandErrorHandler({ user })
|
||||
);
|
||||
|
||||
console.log("build complete");
|
||||
res.send({
|
||||
success: true,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "yarn build && node build",
|
||||
"build": "rm -rf build && tsc --project ./ && cp -r functions build",
|
||||
"build": "rm -rf build && tsc --project ./ && cp -r functions build && cp -r sparksLib build",
|
||||
"deploy": "./deploy.sh"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"exclude": ["functions", "build"],
|
||||
"include": ["*.ts", "firebase.json"]
|
||||
"include": ["*.ts", "firebase.json", "sparksLib"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user