@iexec/iapp-maker 0.0.1-alpha-nightly-ef579faebe1b4ee041f6da3e79851c51d6dd180e → 0.0.1-alpha-nightly-c88f1c62428cda426ca60c8b374fb74970fb6fba

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iexec/iapp-maker",
3
- "version": "0.0.1-alpha-nightly-ef579faebe1b4ee041f6da3e79851c51d6dd180e",
3
+ "version": "0.0.1-alpha-nightly-c88f1c62428cda426ca60c8b374fb74970fb6fba",
4
4
  "description": "A CLI to guide you through the process of building an iExec iApp",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/cmd/deploy.js CHANGED
@@ -6,7 +6,10 @@ import {
6
6
  import { sconify } from '../utils/sconify.js';
7
7
  import { askForDockerhubUsername } from '../cli-helpers/askForDockerhubUsername.js';
8
8
  import { askForWalletAddress } from '../cli-helpers/askForWalletAddress.js';
9
- import { readPackageJonConfig } from '../utils/iAppConfigFile.js';
9
+ import {
10
+ projectNameToImageName,
11
+ readIAppConfig,
12
+ } from '../utils/iAppConfigFile.js';
10
13
  import { askForDockerhubAccessToken } from '../cli-helpers/askForDockerhubAccessToken.js';
11
14
  import { handleCliError } from '../cli-helpers/handleCliError.js';
12
15
  import { getSpinner } from '../cli-helpers/spinner.js';
@@ -22,6 +25,8 @@ export async function deploy() {
22
25
  const spinner = getSpinner();
23
26
  try {
24
27
  await goToProjectRoot({ spinner });
28
+ const { projectName } = await readIAppConfig();
29
+
25
30
  const dockerhubUsername = await askForDockerhubUsername({ spinner });
26
31
  const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner });
27
32
 
@@ -38,6 +43,8 @@ export async function deploy() {
38
43
  throw Error('Invalid version');
39
44
  }
40
45
 
46
+ const imageTag = `${dockerhubUsername}/${projectNameToImageName(projectName)}:${iAppVersion}`;
47
+
41
48
  const appSecret = await askForAppSecret({ spinner });
42
49
 
43
50
  const walletAddress = await askForWalletAddress({ spinner });
@@ -54,11 +61,6 @@ export async function deploy() {
54
61
  iexec = getIExecDebug(privateKey);
55
62
  }
56
63
 
57
- const config = await readPackageJonConfig();
58
- const iAppName = config.name.toLowerCase();
59
-
60
- const imageTag = `${dockerhubUsername}/${iAppName}:${iAppVersion}`;
61
-
62
64
  // just start the spinner, no need to persist success in terminal
63
65
  spinner.start('Checking docker daemon is running...');
64
66
  await checkDockerDaemon();
package/src/cmd/init.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import figlet from 'figlet';
3
3
  import { mkdir } from 'node:fs/promises';
4
+ import { fromError } from 'zod-validation-error';
4
5
  import { folderExists } from '../utils/fs.utils.js';
5
6
  import { initIAppWorkspace } from '../utils/initIAppWorkspace.js';
6
7
  import { getSpinner } from '../cli-helpers/spinner.js';
@@ -8,6 +9,7 @@ import { handleCliError } from '../cli-helpers/handleCliError.js';
8
9
  import { generateWallet } from '../utils/generateWallet.js';
9
10
  import * as color from '../cli-helpers/color.js';
10
11
  import { hintBox } from '../cli-helpers/box.js';
12
+ import { projectNameSchema } from '../utils/iAppConfigFile.js';
11
13
 
12
14
  const targetDir = 'hello-world';
13
15
 
@@ -30,6 +32,16 @@ export async function init() {
30
32
  name: 'projectName',
31
33
  message: `What's your project name? ${color.promptHelper('(A folder with this name will be created)')}`,
32
34
  initial: targetDir,
35
+ validate: (value) => {
36
+ try {
37
+ projectNameSchema.parse(value);
38
+ return true;
39
+ } catch (e) {
40
+ return fromError(e)
41
+ .details.map((issue) => issue.message)
42
+ .join('; ');
43
+ }
44
+ },
33
45
  });
34
46
 
35
47
  if (await folderExists(projectName)) {
@@ -3,8 +3,27 @@ import { z } from 'zod';
3
3
  import { fromError } from 'zod-validation-error';
4
4
  import { CONFIG_FILE } from '../config/config.js';
5
5
 
6
+ export const projectNameSchema = z
7
+ .string()
8
+ .min(2, 'Must contain at least 2 characters') // docker image name constraint
9
+ .refine(
10
+ (value) => !/(^\s)|(\s$)/.test(value),
11
+ 'Should not start or end with space'
12
+ )
13
+ .refine(
14
+ (value) => /^[a-zA-Z0-9- ]+$/.test(value ?? ''),
15
+ 'Only letters, numbers, spaces, and hyphens are allowed'
16
+ );
17
+
18
+ const dockerImageNameSchema = z
19
+ .string()
20
+ .refine(
21
+ (value) => /^[a-z0-9-]+$/.test(value ?? ''),
22
+ 'Invalid docker image name'
23
+ );
24
+
6
25
  const jsonConfigFileSchema = z.object({
7
- projectName: z.string(),
26
+ projectName: projectNameSchema,
8
27
  dockerhubUsername: z.string().optional(),
9
28
  dockerhubAccessToken: z.string().optional(),
10
29
  walletAddress: z.string().optional(),
@@ -12,6 +31,12 @@ const jsonConfigFileSchema = z.object({
12
31
  appSecret: z.string().optional().nullable(), // can be null or string (null means do no use secret)
13
32
  });
14
33
 
34
+ // transform the projectName into a suitable docker image name (no space, lowercase only)
35
+ export function projectNameToImageName(projectName = '') {
36
+ const imageName = projectName.toLowerCase().replaceAll(' ', '-');
37
+ return dockerImageNameSchema.parse(imageName);
38
+ }
39
+
15
40
  // Read JSON configuration file
16
41
  export async function readIAppConfig() {
17
42
  const configContent = await readFile(CONFIG_FILE, 'utf8').catch(() => {
@@ -37,16 +62,6 @@ export async function readIAppConfig() {
37
62
  }
38
63
  }
39
64
 
40
- // Read package.json file
41
- export async function readPackageJonConfig() {
42
- try {
43
- const packageContent = await readFile('./package.json', 'utf8');
44
- return JSON.parse(packageContent);
45
- } catch {
46
- throw Error('Failed to read `package.json` file.');
47
- }
48
- }
49
-
50
65
  // Utility function to write the iApp JSON configuration file
51
66
  export async function writeIAppConfig(config) {
52
67
  await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));