Skip to content

Commit

Permalink
feat: first pass at sending the raw file along to Flatfile
Browse files Browse the repository at this point in the history
  • Loading branch information
bangarang committed Jul 3, 2024
1 parent af477c2 commit 5270e34
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
6 changes: 4 additions & 2 deletions apps/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -28,4 +30,4 @@
"devDependencies": {
"@types/node": "^18.16.0"
}
}
}
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 30 additions & 12 deletions packages/cli/src/x/actions/deploy.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Flatfile.EventTopic[]>{
async function getActiveTopics(file: string): Promise<Flatfile.EventTopic[]> {
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(
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5270e34

Please sign in to comment.