Skip to content

Commit 6185623

Browse files
feat: add bulk processing in iapp init
1 parent 5a3e4f1 commit 6185623

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

cli/src/cmd/init.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function init() {
8888

8989
const {
9090
useArgs = true,
91-
useProtectedData = true,
91+
protectedData = 'useProtectedData',
9292
useInputFile = false,
9393
useRequesterSecret = false,
9494
useAppSecret = false,
@@ -119,11 +119,36 @@ export async function init() {
119119
initial: false,
120120
},
121121
{
122-
type: 'confirm',
123-
name: 'useProtectedData',
124-
message: `Would you like to use a protected data inside your iApp? ${color.promptHelper(
122+
type: 'select',
123+
name: 'protectedData',
124+
message: `Would you like to use protected data inside your iApp? ${color.promptHelper(
125125
'(protected data a secret file, the protected data is provided by a third party for users that will run your iApp)'
126126
)}`,
127+
choices: [
128+
{
129+
title: 'no',
130+
value: 'noProtectedData',
131+
},
132+
{
133+
title: 'yes - only one protected data',
134+
value: 'useProtectedData',
135+
selected: true,
136+
description: 'one protected data per iApp run',
137+
},
138+
{
139+
title: 'yes - many protected data (bulk processing)',
140+
value: 'useBulkProcessing',
141+
description:
142+
'multiple protected data loaded in the same context of an iApp run',
143+
},
144+
],
145+
},
146+
{
147+
type: 'confirm',
148+
name: 'useBulkProcessing',
149+
message: `Would you like to use multiple protected data in bulk processing inside your iApp? ${color.promptHelper(
150+
'(bulk processing allows you to load multiple protected data files in a single iApp run)'
151+
)}`,
127152
initial: false,
128153
},
129154
{
@@ -135,6 +160,9 @@ export async function init() {
135160
])
136161
: {}; // default
137162

163+
const useProtectedData = protectedData === 'useProtectedData';
164+
const useBulkProcessing = protectedData === 'useBulkProcessing';
165+
138166
await mkdir(projectName);
139167
process.chdir(projectName);
140168

@@ -146,6 +174,7 @@ export async function init() {
146174
template,
147175
useArgs,
148176
useProtectedData,
177+
useBulkProcessing,
149178
useInputFile,
150179
useRequesterSecret,
151180
useAppSecret,
@@ -189,6 +218,12 @@ export async function init() {
189218
${color.comment('# with a protected data')}
190219
${color.command('$ iapp test --protectedData default')}`
191220
: ''
221+
}${
222+
useBulkProcessing
223+
? `
224+
${color.comment('# with a multiple protected data processed in bulk')}
225+
${color.command('$ iapp test --protectedData data1 data2 data3')}`
226+
: ''
192227
}
193228
194229
-2- Deploy your iApp on the iExec protocol:

cli/src/utils/initIAppWorkspace.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export async function initIAppWorkspace({
1818
template = 'JavaScript',
1919
useArgs = false,
2020
useProtectedData = false,
21+
useBulkProcessing = false,
2122
useInputFile = false,
2223
useRequesterSecret = false,
2324
useAppSecret = false,
@@ -26,6 +27,7 @@ export async function initIAppWorkspace({
2627
template: TemplateName;
2728
useArgs?: boolean;
2829
useProtectedData?: boolean;
30+
useBulkProcessing?: boolean;
2931
useInputFile?: boolean;
3032
useRequesterSecret?: boolean;
3133
useAppSecret?: boolean;
@@ -40,6 +42,7 @@ export async function initIAppWorkspace({
4042
useInputFile,
4143
useRequesterSecret,
4244
useAppSecret,
45+
useBulkProcessing,
4346
});
4447
// Create other files
4548
await createConfigurationFiles({
@@ -92,6 +95,7 @@ async function copyChosenTemplateFiles({
9295
useInputFile,
9396
useRequesterSecret,
9497
useAppSecret,
98+
useBulkProcessing,
9599
}: {
96100
template: string;
97101
srcFiles: string[];
@@ -100,6 +104,7 @@ async function copyChosenTemplateFiles({
100104
useInputFile: boolean;
101105
useRequesterSecret: boolean;
102106
useAppSecret: boolean;
107+
useBulkProcessing: boolean;
103108
}) {
104109
const templatesBaseDir = path.resolve(
105110
fileURLToPath(import.meta.url),
@@ -139,6 +144,12 @@ async function copyChosenTemplateFiles({
139144
''
140145
);
141146
}
147+
if (!useBulkProcessing) {
148+
modifiedCode = modifiedCode.replaceAll(
149+
/ *(\/\/|#) <<bulkProcessing>>\n((.*)\n)*? *(\/\/|#) <<\/bulkProcessing>>(\n)?/g,
150+
''
151+
);
152+
}
142153
if (!useInputFile) {
143154
modifiedCode = modifiedCode.replaceAll(
144155
/ *(\/\/|#) <<inputFile>>\n((.*)\n)*? *(\/\/|#) <<\/inputFile>>(\n)?/g,
@@ -173,7 +184,7 @@ async function copyChosenTemplateFiles({
173184
const commonPath = path.resolve(templatesBaseDir, 'common');
174185
await copy(commonPath, path.join(process.cwd()));
175186

176-
if (useProtectedData) {
187+
if (useProtectedData || useBulkProcessing) {
177188
const mockPath = path.resolve(templatesBaseDir, 'mock', 'protectedData');
178189
await copy(mockPath, PROTECTED_DATA_MOCK_DIR);
179190
}

cli/templates/JavaScript/src/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import figlet from 'figlet';
66
// <<protectedData>>
77
import { IExecDataProtectorDeserializer } from '@iexec/dataprotector-deserializer';
88
// <</protectedData>>
9+
// <<bulkProcessing>>
10+
import { IExecDataProtectorDeserializer } from '@iexec/dataprotector-deserializer';
11+
// <</bulkProcessing>>
912

1013
const main = async () => {
1114
const { IEXEC_OUT } = process.env;
136 Bytes
Binary file not shown.
136 Bytes
Binary file not shown.
136 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)