diff --git a/package.json b/package.json index e0da6c9..cd65b20 100644 --- a/package.json +++ b/package.json @@ -20,14 +20,14 @@ "@types/parse": "^2.18.18", "@types/prettier": "^2.7.0", "@types/webpack": "^5.28.0", + "husky": "^8.0.0", "typescript": "^4.6.4", - "webpack": "^5.74.0", - "husky": "^8.0.0" + "webpack": "^5.74.0" }, "dependencies": { "eta": "^2.0.0", "glob": "^8.1.0", - "parse": "^3.4.4", + "parse": "^4.0.1", "prettier": "^2.8.3", "webpack-inject-plugin": "^1.5.5" } diff --git a/src/main.ts b/src/main.ts index f3bb8c7..c8d41b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,6 +119,7 @@ interface ParseFunctionService { triggers: string[]; jobs: string[]; config?: string; + json?: string; } interface ParseServiceMap { @@ -182,7 +183,7 @@ export class ParseFunctionsPlugin implements WebpackPluginInstance { console.warn('[PARSE FUNCTIONS PLUGIN]', 'No build folder found; creating one now'); } - fs.mkdirSync(this.buildPath!); + fs.mkdirSync(this.buildPath!); const services = this.schemaPaths!.reduce((memo, schemaPath) => { const p = schemaPath.split(path.sep); @@ -205,7 +206,7 @@ export class ParseFunctionsPlugin implements WebpackPluginInstance { config: hookConfig, }; return hMemo; - }, {} as Hooks); + }, {} as Hooks); memo[serviceDirName] = { name: serviceDirName, @@ -219,8 +220,9 @@ export class ParseFunctionsPlugin implements WebpackPluginInstance { jobs, config, }; + return memo; - }, {} as ParseServiceMap); + }, {} as ParseServiceMap); const helpersFile = await this.makeHelpersFile(services); fs.writeFileSync(path.resolve(`${this.buildPath}`, 'helpers.ts'), helpersFile); diff --git a/templates/index.eta b/templates/index.eta index c076f69..b3ee81e 100644 --- a/templates/index.eta +++ b/templates/index.eta @@ -1,10 +1,22 @@ import type P from 'parse'; import { registerParseInstance } from './helpers'; import { ParseFunctionConfig } from './types'; + <% Object.entries(it.services).forEach(([serviceName, service]) => { %> - import <%~ serviceName %> from './<%~ serviceName %>'; + import <%~ serviceName %>, { functions as <%~ serviceName %>functions, jobs as <%~ serviceName %>jobs } from './<%~ serviceName %>'; <% }) %> +export const functions = { + <% Object.entries(it.services).forEach(([serviceName, service]) => { %> + ...<%~ serviceName %>functions, + <% }) %> +} + +export const jobs = { + <% Object.entries(it.services).forEach(([serviceName, service]) => { %> + ...<%~ serviceName %>jobs, + <% }) %> +} type ParseType = typeof P; diff --git a/templates/service.eta b/templates/service.eta index 8353ea2..002cd4b 100644 --- a/templates/service.eta +++ b/templates/service.eta @@ -60,6 +60,7 @@ const defaultTriggerConfig = { requireMaster: true, }; +export const config = <%~ it.service.json %> /* === SERVICE === */ const service: <% if (it.service.config) { %> ServiceInitializer <% } else { %> ServiceInitializer <% } %> = @@ -163,7 +164,7 @@ const service: <% if (it.service.config) { %> ServiceInitializer Object.assign({}, defaultFunctionConfig, <%~ it.helpers.getSanitizedFunctionName(functionPath, 'config_') %>) ); <% }) %> - + // JOBS <% it.service.jobs.forEach((jobPath) => { %> Parse.Cloud.job( @@ -180,4 +181,16 @@ const service: <% if (it.service.config) { %> ServiceInitializer }; }; +export const functions = { + <% it.service.functions.forEach((functionPath) => { %> + '<%~ it.helpers.getSanitizedFunctionName(functionPath) %>': Object.assign({}, defaultFunctionConfig, <%~ it.helpers.getSanitizedFunctionName(functionPath, 'config_') %>), + <% }) %> +} + +export const jobs = { + <% it.service.jobs.forEach((jobPath) => { %> + '<%~ it.helpers.getSanitizedFunctionName(jobPath) %>': {}, + <% }) %> +} + export default service;