create-fhevm-example 1.2.3 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +72 -146
  2. package/dist/scripts/add-mode.d.ts +11 -0
  3. package/dist/scripts/add-mode.d.ts.map +1 -0
  4. package/dist/{add-mode.js → scripts/add-mode.js} +84 -58
  5. package/dist/scripts/builders.d.ts +19 -0
  6. package/dist/scripts/builders.d.ts.map +1 -0
  7. package/dist/scripts/builders.js +211 -0
  8. package/dist/{config.d.ts → scripts/config.d.ts} +24 -3
  9. package/dist/scripts/config.d.ts.map +1 -0
  10. package/dist/scripts/config.js +465 -0
  11. package/dist/scripts/doctor.d.ts +11 -0
  12. package/dist/scripts/doctor.d.ts.map +1 -0
  13. package/dist/scripts/doctor.js +165 -0
  14. package/dist/scripts/generate-config.d.ts +9 -0
  15. package/dist/scripts/generate-config.d.ts.map +1 -0
  16. package/dist/scripts/generate-config.js +323 -0
  17. package/dist/scripts/generate-docs.d.ts +10 -0
  18. package/dist/scripts/generate-docs.d.ts.map +1 -0
  19. package/dist/scripts/generate-docs.js +190 -0
  20. package/dist/scripts/index.d.ts +12 -0
  21. package/dist/scripts/index.d.ts.map +1 -0
  22. package/dist/scripts/index.js +384 -0
  23. package/dist/scripts/maintenance.d.ts +13 -0
  24. package/dist/scripts/maintenance.d.ts.map +1 -0
  25. package/dist/scripts/maintenance.js +271 -0
  26. package/dist/{prompts.d.ts → scripts/ui.d.ts} +8 -7
  27. package/dist/scripts/ui.d.ts.map +1 -0
  28. package/dist/scripts/ui.js +170 -0
  29. package/dist/scripts/utils.d.ts +86 -0
  30. package/dist/scripts/utils.d.ts.map +1 -0
  31. package/dist/scripts/utils.js +525 -0
  32. package/package.json +25 -13
  33. package/dist/add-mode.d.ts +0 -21
  34. package/dist/add-mode.d.ts.map +0 -1
  35. package/dist/add-mode.js.map +0 -1
  36. package/dist/builders.d.ts +0 -30
  37. package/dist/builders.d.ts.map +0 -1
  38. package/dist/builders.js +0 -195
  39. package/dist/builders.js.map +0 -1
  40. package/dist/commands.d.ts +0 -19
  41. package/dist/commands.d.ts.map +0 -1
  42. package/dist/commands.js +0 -91
  43. package/dist/commands.js.map +0 -1
  44. package/dist/config.d.ts.map +0 -1
  45. package/dist/config.js +0 -398
  46. package/dist/config.js.map +0 -1
  47. package/dist/constants.d.ts +0 -16
  48. package/dist/constants.d.ts.map +0 -1
  49. package/dist/constants.js +0 -40
  50. package/dist/constants.js.map +0 -1
  51. package/dist/index.d.ts +0 -20
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/index.js +0 -337
  54. package/dist/index.js.map +0 -1
  55. package/dist/prompts.d.ts.map +0 -1
  56. package/dist/prompts.js +0 -79
  57. package/dist/prompts.js.map +0 -1
  58. package/dist/ui.d.ts +0 -35
  59. package/dist/ui.d.ts.map +0 -1
  60. package/dist/ui.js +0 -155
  61. package/dist/ui.js.map +0 -1
  62. package/dist/utils.d.ts +0 -99
  63. package/dist/utils.d.ts.map +0 -1
  64. package/dist/utils.js +0 -285
  65. package/dist/utils.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Interactive Prompts
2
+ * User Interface - CLI Prompts and Interaction Logic.
3
3
  *
4
- * Category and example selection prompts for interactive mode.
5
- * Similar structure to main project's interactive flows.
4
+ * Provides centralized components for user input, selection menus,
5
+ * and standard command execution feedback for the CLI.
6
6
  */
7
7
  /**
8
8
  * Counts how many examples exist in each category
@@ -10,17 +10,18 @@
10
10
  export declare function countExamplesPerCategory(): Record<string, number>;
11
11
  /**
12
12
  * Prompts user to select a category
13
- * Returns the selected category name
14
13
  */
15
14
  export declare function promptSelectCategory(): Promise<string | symbol>;
16
15
  /**
17
16
  * Prompts user to select an example from a specific category
18
- * Returns the selected example name
19
17
  */
20
18
  export declare function promptSelectExampleFromCategory(category: string): Promise<string | symbol>;
21
19
  /**
22
20
  * Prompts user to select a category project
23
- * Returns the selected category key (lowercase)
24
21
  */
25
22
  export declare function promptSelectCategoryProject(): Promise<string | symbol>;
26
- //# sourceMappingURL=prompts.d.ts.map
23
+ /**
24
+ * Runs npm install, compile, and test in the project directory
25
+ */
26
+ export declare function runInstallAndTest(projectPath: string): Promise<void>;
27
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../scripts/ui.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMjE;AAMD;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAmBrE;AAED;;GAEG;AACH,wBAAsB,+BAA+B,CACnD,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAe1B;AAED;;GAEG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAS5E;AAMD;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD1E"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /**
3
+ * User Interface - CLI Prompts and Interaction Logic.
4
+ *
5
+ * Provides centralized components for user input, selection menus,
6
+ * and standard command execution feedback for the CLI.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.countExamplesPerCategory = countExamplesPerCategory;
46
+ exports.promptSelectCategory = promptSelectCategory;
47
+ exports.promptSelectExampleFromCategory = promptSelectExampleFromCategory;
48
+ exports.promptSelectCategoryProject = promptSelectCategoryProject;
49
+ exports.runInstallAndTest = runInstallAndTest;
50
+ const p = __importStar(require("@clack/prompts"));
51
+ const picocolors_1 = __importDefault(require("picocolors"));
52
+ const config_1 = require("./config");
53
+ const utils_1 = require("./utils");
54
+ // =============================================================================
55
+ // Category Helpers
56
+ // =============================================================================
57
+ /**
58
+ * Counts how many examples exist in each category
59
+ */
60
+ function countExamplesPerCategory() {
61
+ const counts = {};
62
+ for (const config of Object.values(config_1.EXAMPLES)) {
63
+ counts[config.category] = (counts[config.category] || 0) + 1;
64
+ }
65
+ return counts;
66
+ }
67
+ // =============================================================================
68
+ // Selection Prompts
69
+ // =============================================================================
70
+ /**
71
+ * Prompts user to select a category
72
+ */
73
+ async function promptSelectCategory() {
74
+ const categoryCounts = countExamplesPerCategory();
75
+ const allCategories = Object.keys(categoryCounts);
76
+ const orderedCategories = [
77
+ ...utils_1.CATEGORY_ORDER.filter((cat) => allCategories.includes(cat)),
78
+ ...allCategories.filter((cat) => !utils_1.CATEGORY_ORDER.includes(cat)).sort(),
79
+ ];
80
+ return p.select({
81
+ message: "Select a category:",
82
+ options: orderedCategories.map((category) => ({
83
+ value: category,
84
+ label: `${utils_1.CATEGORY_ICON} ${category}`,
85
+ hint: `${categoryCounts[category] || 0} example${categoryCounts[category] !== 1 ? "s" : ""}`,
86
+ })),
87
+ });
88
+ }
89
+ /**
90
+ * Prompts user to select an example from a specific category
91
+ */
92
+ async function promptSelectExampleFromCategory(category) {
93
+ const categoryExamples = Object.entries(config_1.EXAMPLES)
94
+ .filter(([, config]) => config.category === category)
95
+ .map(([key, config]) => ({
96
+ value: key,
97
+ label: key,
98
+ hint: config.description.slice(0, utils_1.MAX_DESCRIPTION_LENGTH) +
99
+ (config.description.length > utils_1.MAX_DESCRIPTION_LENGTH ? "..." : ""),
100
+ }));
101
+ return p.select({
102
+ message: `Select an example from ${category}:`,
103
+ options: categoryExamples,
104
+ });
105
+ }
106
+ /**
107
+ * Prompts user to select a category project
108
+ */
109
+ async function promptSelectCategoryProject() {
110
+ return p.select({
111
+ message: "Select a category:",
112
+ options: Object.entries(config_1.CATEGORIES).map(([key, config]) => ({
113
+ value: key,
114
+ label: `${utils_1.CATEGORY_ICON} ${config.name}`,
115
+ hint: `${config.contracts.length} contracts`,
116
+ })),
117
+ });
118
+ }
119
+ // =============================================================================
120
+ // Install & Test Commands
121
+ // =============================================================================
122
+ /**
123
+ * Runs npm install, compile, and test in the project directory
124
+ */
125
+ async function runInstallAndTest(projectPath) {
126
+ const steps = [
127
+ {
128
+ name: "Installing dependencies",
129
+ cmd: "npm",
130
+ args: ["install"],
131
+ showOutput: false,
132
+ },
133
+ {
134
+ name: "Compiling contracts",
135
+ cmd: "npm",
136
+ args: ["run", "compile"],
137
+ showOutput: false,
138
+ },
139
+ {
140
+ name: "Running tests",
141
+ cmd: "npm",
142
+ args: ["run", "test"],
143
+ showOutput: true,
144
+ },
145
+ ];
146
+ for (const step of steps) {
147
+ const s = p.spinner();
148
+ s.start(step.name + "...");
149
+ try {
150
+ const output = await (0, utils_1.runCommand)(step.cmd, step.args, projectPath);
151
+ if (step.showOutput) {
152
+ const testResults = (0, utils_1.extractTestResults)(output);
153
+ s.stop(testResults
154
+ ? picocolors_1.default.green(`✓ ${step.name} - ${testResults}`)
155
+ : picocolors_1.default.green(`✓ ${step.name} completed`));
156
+ }
157
+ else {
158
+ s.stop(picocolors_1.default.green(`✓ ${step.name} completed`));
159
+ }
160
+ }
161
+ catch (error) {
162
+ s.stop(picocolors_1.default.red(`✗ ${step.name} failed`));
163
+ if (error instanceof Error) {
164
+ p.log.error(error.message);
165
+ }
166
+ throw new Error(`${step.name} failed`);
167
+ }
168
+ }
169
+ p.log.success(picocolors_1.default.green("🔐 All encryption tests passed!"));
170
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Shared Utilities - Helper functions for the FHEVM Example Factory.
3
+ *
4
+ * Contains common logic for file system operations, string formatting,
5
+ * error handling, and terminal logging used throughout the project.
6
+ */
7
+ export type ProjectMode = "single" | "category";
8
+ export declare const CATEGORY_ICON = "\uD83D\uDCC1";
9
+ /** Template directory name within the cloned repo */
10
+ export declare const TEMPLATE_DIR_NAME = "fhevm-hardhat-template";
11
+ /** Maximum description length for UI display */
12
+ export declare const MAX_DESCRIPTION_LENGTH = 80;
13
+ /** Directories to exclude when copying template */
14
+ export declare const EXCLUDE_DIRS: string[];
15
+ /** FHEVM package versions for --add mode */
16
+ export declare const FHEVM_DEPENDENCIES: {
17
+ dependencies: {
18
+ "encrypted-types": string;
19
+ "@fhevm/solidity": string;
20
+ };
21
+ devDependencies: {
22
+ "@fhevm/hardhat-plugin": string;
23
+ "@zama-fhe/relayer-sdk": string;
24
+ };
25
+ };
26
+ export declare const CATEGORY_ORDER: string[];
27
+ export declare const TEST_TYPES_CONTENT = "import type { HardhatEthersSigner } from \"@nomicfoundation/hardhat-ethers/signers\";\n\n/**\n * Common signers interface used across test files\n */\nexport interface Signers {\n owner: HardhatEthersSigner;\n alice: HardhatEthersSigner;\n}\n";
28
+ export declare const ERROR_MESSAGES: {
29
+ EXAMPLE_REQUIRED: string;
30
+ BOTH_SPECIFIED: string;
31
+ UNKNOWN_EXAMPLE: (name: string) => string;
32
+ UNKNOWN_CATEGORY: (name: string) => string;
33
+ DIR_EXISTS: (path: string) => string;
34
+ NOT_HARDHAT: string;
35
+ CONFIG_NOT_FOUND: string;
36
+ CONTRACT_NAME_FAILED: string;
37
+ };
38
+ export declare const log: {
39
+ success: (msg: string) => void;
40
+ error: (msg: string) => void;
41
+ info: (msg: string) => void;
42
+ dim: (msg: string) => void;
43
+ message: (msg: string) => void;
44
+ };
45
+ /**
46
+ * Standardized error handler for CLI - logs error and exits
47
+ */
48
+ export declare function handleError(error: unknown, exitCode?: number): never;
49
+ /** Resolves root directory of the project */
50
+ export declare function getRootDir(): string;
51
+ /** Resolves template directory path */
52
+ export declare function getTemplateDir(): string;
53
+ /** Copies directory recursively, excluding specified directories */
54
+ export declare function copyDirectoryRecursive(source: string, destination: string, excludeDirs?: string[]): void;
55
+ export declare function toKebabCase(str: string): string;
56
+ export declare function contractNameToExampleName(contractName: string): string;
57
+ export declare function contractNameToTitle(contractName: string): string;
58
+ export declare function formatCategoryName(folderName: string): string;
59
+ export declare function getContractName(contractPathOrContent: string): string | null;
60
+ export declare function validateExample(name: string): void;
61
+ export declare function validateCategory(name: string): void;
62
+ export declare function validateDirectoryNotExists(dirPath: string): void;
63
+ export declare function cleanupTemplate(outputDir: string): void;
64
+ export declare function generateDeployScript(contractName: string): string;
65
+ export declare function generateGitBookMarkdown(description: string, contractContent: string, testContent: string, contractName: string, testFileName: string): string;
66
+ export declare function updateProjectPackageJson(outputDir: string, projectName: string, description?: string, npmDependencies?: Record<string, string>): void;
67
+ export declare function runCommand(cmd: string, args: string[], cwd: string): Promise<string>;
68
+ export declare function runCommandWithStatus(cmd: string, args: string[], cwd: string): Promise<{
69
+ success: boolean;
70
+ output: string;
71
+ }>;
72
+ export declare function extractTestResults(output: string): string | null;
73
+ export declare function extractErrorMessage(output: string): string;
74
+ /**
75
+ * Downloads a file from GitHub repository
76
+ */
77
+ export declare function downloadFileFromGitHub(filePath: string, outputPath: string): Promise<void>;
78
+ /**
79
+ * Clones the template repository to temp directory
80
+ */
81
+ export declare function cloneTemplate(tempDir: string): Promise<string>;
82
+ /**
83
+ * Initializes git submodule for the template
84
+ */
85
+ export declare function initSubmodule(repoPath: string): Promise<void>;
86
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../scripts/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhD,eAAO,MAAM,aAAa,iBAAO,CAAC;AAElC,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,gDAAgD;AAChD,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,mDAAmD;AACnD,eAAO,MAAM,YAAY,UAQxB,CAAC;AAEF,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB;;;;;;;;;CAS9B,CAAC;AAEF,eAAO,MAAM,cAAc,UAQ1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,yPAS9B,CAAC;AAEF,eAAO,MAAM,cAAc;;;4BAGD,MAAM;6BACL,MAAM;uBACZ,MAAM;;;;CAI1B,CAAC;AAMF,eAAO,MAAM,GAAG;mBACC,MAAM;iBACR,MAAM;gBACP,MAAM;eACP,MAAM;mBACF,MAAM;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAI,GAAG,KAAK,CAI/D;AAMD,6CAA6C;AAC7C,wBAAgB,UAAU,IAAI,MAAM,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