From 5270e3410931e058a33fe538562149ec8e9c3591 Mon Sep 17 00:00:00 2001 From: Alex Rock Date: Wed, 3 Jul 2024 11:56:36 -0600 Subject: [PATCH] feat: first pass at sending the raw file along to Flatfile --- apps/getting-started/package.json | 6 ++- package-lock.json | 13 ++++--- packages/cli/src/x/actions/deploy.action.ts | 42 +++++++++++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/apps/getting-started/package.json b/apps/getting-started/package.json index eaf81a52..b75a2df6 100644 --- a/apps/getting-started/package.json +++ b/apps/getting-started/package.json @@ -6,15 +6,17 @@ "main": "index.js", "scripts": { "develop": "flatfile develop index.ts", + "deploy": "flatfile deploy index.ts", "paginate": "flatfile develop paginate-records.ts" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { + "@flatfile/api": "^1.8.5", "@flatfile/cross-env-config": "*", "@flatfile/hooks": "^1.3.0", - "@flatfile/api": "^1.8.5", + "@flatfile/listener": "^1.0.5", "@flatfile/plugin-record-hook": "^1.5.2", "actions": "^1.3.0", "ansi-colors": "^4.1.3", @@ -28,4 +30,4 @@ "devDependencies": { "@types/node": "^18.16.0" } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 614a6c0f..2eb08164 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "@flatfile/api": "^1.8.5", "@flatfile/cross-env-config": "*", "@flatfile/hooks": "^1.3.0", + "@flatfile/listener": "^1.0.5", "@flatfile/plugin-record-hook": "^1.5.2", "actions": "^1.3.0", "ansi-colors": "^4.1.3", @@ -33306,7 +33307,7 @@ }, "packages/embedded-utils": { "name": "@flatfile/embedded-utils", - "version": "1.2.4", + "version": "1.3.0", "license": "ISC", "dependencies": { "@flatfile/api": "^1.8.9", @@ -33430,10 +33431,10 @@ }, "packages/javascript": { "name": "@flatfile/javascript", - "version": "1.3.7", + "version": "1.3.9", "license": "ISC", "dependencies": { - "@flatfile/embedded-utils": "^1.2.4", + "@flatfile/embedded-utils": "^1.3.0", "@flatfile/listener": "^1.0.4", "@flatfile/plugin-record-hook": "^1.5.2" }, @@ -36769,7 +36770,7 @@ }, "packages/react": { "name": "@flatfile/react", - "version": "7.9.9", + "version": "7.9.10", "license": "ISC", "dependencies": { "@flatfile/api": "^1.8.5", @@ -38734,9 +38735,9 @@ }, "packages/vue": { "name": "@flatfile/vue", - "version": "1.0.17", + "version": "1.0.18", "dependencies": { - "@flatfile/embedded-utils": "1.2.4", + "@flatfile/embedded-utils": "1.3.0", "@flatfile/listener": "^1.0.4", "@flatfile/plugin-record-hook": "^1.5.2", "@vue/runtime-dom": "^3.3.4", diff --git a/packages/cli/src/x/actions/deploy.action.ts b/packages/cli/src/x/actions/deploy.action.ts index 9be81b6a..5fab054b 100644 --- a/packages/cli/src/x/actions/deploy.action.ts +++ b/packages/cli/src/x/actions/deploy.action.ts @@ -73,36 +73,50 @@ async function handleAgentSelection( } } -function findActiveTopics(allTopics: ListenerTopics[], client: any, topicsWithListeners = new Set()) { +function findActiveTopics( + allTopics: ListenerTopics[], + client: any, + topicsWithListeners = new Set() +) { client.listeners?.forEach((listener: ListenerTopics | ListenerTopics[]) => { - const listenerTopics = Array.isArray(listener[0]) ? listener[0] : [listener[0]] - listenerTopics.forEach(listenerTopic => { + const listenerTopics = Array.isArray(listener[0]) + ? listener[0] + : [listener[0]] + listenerTopics.forEach((listenerTopic) => { if (listenerTopic === '**') { // Filter cron events out of '**' list - they must be added explicitly - const filteredTopics = allTopics.filter(event => !event.startsWith('cron:')) - filteredTopics.forEach(topic => topicsWithListeners.add(topic)) + const filteredTopics = allTopics.filter( + (event) => !event.startsWith('cron:') + ) + filteredTopics.forEach((topic) => topicsWithListeners.add(topic)) } else if (listenerTopic.includes('**')) { const [prefix] = listenerTopic.split(':') - allTopics.forEach(topic => { if (topic.split(':')[0] === prefix) topicsWithListeners.add(topic) }) + allTopics.forEach((topic) => { + if (topic.split(':')[0] === prefix) topicsWithListeners.add(topic) + }) } else if (allTopics.includes(listenerTopic)) { topicsWithListeners.add(listenerTopic) } }) }) - client.nodes?.forEach((nestedClient: any) => findActiveTopics(allTopics, nestedClient, topicsWithListeners)) + client.nodes?.forEach((nestedClient: any) => + findActiveTopics(allTopics, nestedClient, topicsWithListeners) + ) return topicsWithListeners } -async function getActiveTopics(file: string): Promise{ +async function getActiveTopics(file: string): Promise { const allTopics = Object.values(Flatfile.events.EventTopic) let mount try { mount = await import(url.pathToFileURL(file).href) - } catch(e) { + } catch (e) { return program.error(messages.error(e)) } - return Array.from(findActiveTopics(allTopics, mount.default)) as Flatfile.EventTopic[]; + return Array.from( + findActiveTopics(allTopics, mount.default) + ) as Flatfile.EventTopic[] } export async function deployAction( @@ -164,8 +178,10 @@ export async function deployAction( path.basename(file!) ) ) - + const fileContent = fs.readFileSync(file, 'utf8') + console.log({ file, fileContent }) const entry = result.split(path.sep).join(path.posix.sep) + // console.log({ entry }) fs.writeFileSync(path.join(outDir, '_entry.js'), entry, 'utf8') const buildingSpinner = ora({ text: `Building deployable code package`, @@ -215,7 +231,9 @@ export async function deployAction( const deployFile = path.join(outDir, 'deploy.js') fs.writeFileSync(deployFile, code, 'utf8') - const activeTopics: Flatfile.EventTopic[] = await getActiveTopics(deployFile) + const activeTopics: Flatfile.EventTopic[] = await getActiveTopics( + deployFile + ) if (err) { return program.error(messages.error(err))