Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
8 changes: 5 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ interface ParseFunctionService {
triggers: string[];
jobs: string[];
config?: string;
json?: string;
}

interface ParseServiceMap {
Expand Down Expand Up @@ -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);
Expand All @@ -205,7 +206,7 @@ export class ParseFunctionsPlugin implements WebpackPluginInstance {
config: hookConfig,
};
return hMemo;
}, {} as Hooks);
}, {} as Hooks);

memo[serviceDirName] = {
name: serviceDirName,
Expand All @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion templates/index.eta
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
15 changes: 14 additions & 1 deletion templates/service.eta
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const defaultTriggerConfig = {
requireMaster: true,
};

export const config = <%~ it.service.json %>

/* === SERVICE === */
const service: <% if (it.service.config) { %> ServiceInitializer<ServiceConfig> <% } else { %> ServiceInitializer <% } %> =
Expand Down Expand Up @@ -163,7 +164,7 @@ const service: <% if (it.service.config) { %> ServiceInitializer<ServiceConfig>
Object.assign({}, defaultFunctionConfig, <%~ it.helpers.getSanitizedFunctionName(functionPath, 'config_') %>)
);
<% }) %>

// JOBS
<% it.service.jobs.forEach((jobPath) => { %>
Parse.Cloud.job(
Expand All @@ -180,4 +181,16 @@ const service: <% if (it.service.config) { %> ServiceInitializer<ServiceConfig>
};
};

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;