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.
- package/README.md +72 -146
- package/dist/scripts/add-mode.d.ts +11 -0
- package/dist/scripts/add-mode.d.ts.map +1 -0
- package/dist/{add-mode.js → scripts/add-mode.js} +84 -58
- package/dist/scripts/builders.d.ts +19 -0
- package/dist/scripts/builders.d.ts.map +1 -0
- package/dist/scripts/builders.js +211 -0
- package/dist/{config.d.ts → scripts/config.d.ts} +24 -3
- package/dist/scripts/config.d.ts.map +1 -0
- package/dist/scripts/config.js +465 -0
- package/dist/scripts/doctor.d.ts +11 -0
- package/dist/scripts/doctor.d.ts.map +1 -0
- package/dist/scripts/doctor.js +165 -0
- package/dist/scripts/generate-config.d.ts +9 -0
- package/dist/scripts/generate-config.d.ts.map +1 -0
- package/dist/scripts/generate-config.js +323 -0
- package/dist/scripts/generate-docs.d.ts +10 -0
- package/dist/scripts/generate-docs.d.ts.map +1 -0
- package/dist/scripts/generate-docs.js +190 -0
- package/dist/scripts/index.d.ts +12 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +384 -0
- package/dist/scripts/maintenance.d.ts +13 -0
- package/dist/scripts/maintenance.d.ts.map +1 -0
- package/dist/scripts/maintenance.js +271 -0
- package/dist/{prompts.d.ts → scripts/ui.d.ts} +8 -7
- package/dist/scripts/ui.d.ts.map +1 -0
- package/dist/scripts/ui.js +170 -0
- package/dist/scripts/utils.d.ts +86 -0
- package/dist/scripts/utils.d.ts.map +1 -0
- package/dist/scripts/utils.js +525 -0
- package/package.json +25 -13
- package/dist/add-mode.d.ts +0 -21
- package/dist/add-mode.d.ts.map +0 -1
- package/dist/add-mode.js.map +0 -1
- package/dist/builders.d.ts +0 -30
- package/dist/builders.d.ts.map +0 -1
- package/dist/builders.js +0 -195
- package/dist/builders.js.map +0 -1
- package/dist/commands.d.ts +0 -19
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -91
- package/dist/commands.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -398
- package/dist/config.js.map +0 -1
- package/dist/constants.d.ts +0 -16
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -40
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -337
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -79
- package/dist/prompts.js.map +0 -1
- package/dist/ui.d.ts +0 -35
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js +0 -155
- package/dist/ui.js.map +0 -1
- package/dist/utils.d.ts +0 -99
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -285
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Project Builders - Core logic for scaffolding FHEVM projects.
|
|
4
|
+
*
|
|
5
|
+
* Handles the creation of single example projects, category-based
|
|
6
|
+
* project bundles, and specialized test environments.
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.createSingleExample = createSingleExample;
|
|
43
|
+
exports.createCategoryProject = createCategoryProject;
|
|
44
|
+
exports.createLocalTestProject = createLocalTestProject;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const config_1 = require("./config");
|
|
48
|
+
const utils_1 = require("./utils");
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// Helper Functions
|
|
51
|
+
// =============================================================================
|
|
52
|
+
/**
|
|
53
|
+
* Downloads contract dependencies to the output directory
|
|
54
|
+
*/
|
|
55
|
+
async function downloadDependencies(dependencies, outputDir) {
|
|
56
|
+
for (const depPath of dependencies) {
|
|
57
|
+
const relativePath = depPath.replace(/^contracts\//, "");
|
|
58
|
+
const depDestPath = path.join(outputDir, "contracts", relativePath);
|
|
59
|
+
const depDestDir = path.dirname(depDestPath);
|
|
60
|
+
if (!fs.existsSync(depDestDir)) {
|
|
61
|
+
fs.mkdirSync(depDestDir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
await (0, utils_1.downloadFileFromGitHub)(depPath, depDestPath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Initializes git repository (optional, fails silently)
|
|
68
|
+
*/
|
|
69
|
+
async function initGitRepo(outputDir) {
|
|
70
|
+
try {
|
|
71
|
+
await (0, utils_1.runCommand)("git", ["init"], outputDir);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Git init is optional
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// =============================================================================
|
|
78
|
+
// Project Scaffolding
|
|
79
|
+
// =============================================================================
|
|
80
|
+
/**
|
|
81
|
+
* Creates a single example project from the template
|
|
82
|
+
*/
|
|
83
|
+
async function createSingleExample(exampleName, outputDir, tempRepoPath) {
|
|
84
|
+
const example = config_1.EXAMPLES[exampleName];
|
|
85
|
+
if (!example) {
|
|
86
|
+
throw new Error(`Unknown example: ${exampleName}`);
|
|
87
|
+
}
|
|
88
|
+
const templateDir = path.join(tempRepoPath, utils_1.TEMPLATE_DIR_NAME);
|
|
89
|
+
const contractName = (0, utils_1.getContractName)(example.contract);
|
|
90
|
+
if (!contractName) {
|
|
91
|
+
throw new Error("Could not extract contract name");
|
|
92
|
+
}
|
|
93
|
+
// 1. Copy template and clean up
|
|
94
|
+
(0, utils_1.copyDirectoryRecursive)(templateDir, outputDir);
|
|
95
|
+
(0, utils_1.cleanupTemplate)(outputDir);
|
|
96
|
+
// 2. Download example contract and dependencies
|
|
97
|
+
await (0, utils_1.downloadFileFromGitHub)(example.contract, path.join(outputDir, "contracts", `${contractName}.sol`));
|
|
98
|
+
if (example.dependencies) {
|
|
99
|
+
await downloadDependencies(example.dependencies, outputDir);
|
|
100
|
+
}
|
|
101
|
+
// 3. Download test file
|
|
102
|
+
await (0, utils_1.downloadFileFromGitHub)(example.test, path.join(outputDir, "test", path.basename(example.test)));
|
|
103
|
+
// 4. Update deploy script and package.json
|
|
104
|
+
fs.writeFileSync(path.join(outputDir, "deploy", "deploy.ts"), (0, utils_1.generateDeployScript)(contractName));
|
|
105
|
+
(0, utils_1.updateProjectPackageJson)(outputDir, `fhevm-example-${exampleName}`, example.description, example.npmDependencies);
|
|
106
|
+
await initGitRepo(outputDir);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a category project with multiple examples
|
|
110
|
+
*/
|
|
111
|
+
async function createCategoryProject(categoryName, outputDir, tempRepoPath) {
|
|
112
|
+
const category = config_1.CATEGORIES[categoryName];
|
|
113
|
+
if (!category) {
|
|
114
|
+
throw new Error(`Unknown category: ${categoryName}`);
|
|
115
|
+
}
|
|
116
|
+
const templateDir = path.join(tempRepoPath, utils_1.TEMPLATE_DIR_NAME);
|
|
117
|
+
// 1. Copy template and clean up
|
|
118
|
+
(0, utils_1.copyDirectoryRecursive)(templateDir, outputDir);
|
|
119
|
+
(0, utils_1.cleanupTemplate)(outputDir);
|
|
120
|
+
// 2. Download all contracts and tests
|
|
121
|
+
for (const item of category.contracts) {
|
|
122
|
+
const contractName = (0, utils_1.getContractName)(item.sol);
|
|
123
|
+
if (contractName) {
|
|
124
|
+
await (0, utils_1.downloadFileFromGitHub)(item.sol, path.join(outputDir, "contracts", `${contractName}.sol`));
|
|
125
|
+
}
|
|
126
|
+
if (item.test) {
|
|
127
|
+
await (0, utils_1.downloadFileFromGitHub)(item.test, path.join(outputDir, "test", path.basename(item.test)));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// 3. Collect and download dependencies
|
|
131
|
+
const allDependencies = new Set();
|
|
132
|
+
const allNpmDependencies = {};
|
|
133
|
+
for (const [exampleName, exampleConfig] of Object.entries(config_1.EXAMPLES)) {
|
|
134
|
+
// Check if example belongs to this category
|
|
135
|
+
const configCategoryLower = exampleConfig.category
|
|
136
|
+
.toLowerCase()
|
|
137
|
+
.replace(/\s+/g, "");
|
|
138
|
+
if (configCategoryLower === categoryName ||
|
|
139
|
+
exampleConfig.category === category.name.replace(" Examples", "")) {
|
|
140
|
+
if (exampleConfig.dependencies) {
|
|
141
|
+
exampleConfig.dependencies.forEach((dep) => allDependencies.add(dep));
|
|
142
|
+
}
|
|
143
|
+
if (exampleConfig.npmDependencies) {
|
|
144
|
+
Object.assign(allNpmDependencies, exampleConfig.npmDependencies);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (allDependencies.size > 0) {
|
|
149
|
+
await downloadDependencies(Array.from(allDependencies), outputDir);
|
|
150
|
+
}
|
|
151
|
+
// 4. Update package.json
|
|
152
|
+
(0, utils_1.updateProjectPackageJson)(outputDir, `fhevm-examples-${categoryName}`, undefined, allNpmDependencies);
|
|
153
|
+
await initGitRepo(outputDir);
|
|
154
|
+
}
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Specialized Builders
|
|
157
|
+
// =============================================================================
|
|
158
|
+
/**
|
|
159
|
+
* Creates a temporary test project using LOCAL files (used by maintenance.ts)
|
|
160
|
+
*/
|
|
161
|
+
async function createLocalTestProject(exampleNames, outputDir) {
|
|
162
|
+
const rootDir = (0, utils_1.getRootDir)();
|
|
163
|
+
const templateDir = (0, utils_1.getTemplateDir)();
|
|
164
|
+
// 1. Setup base project from local template
|
|
165
|
+
(0, utils_1.copyDirectoryRecursive)(templateDir, outputDir);
|
|
166
|
+
(0, utils_1.cleanupTemplate)(outputDir);
|
|
167
|
+
const allNpmDeps = {};
|
|
168
|
+
const allContractDeps = new Set();
|
|
169
|
+
// 2. Copy local example files
|
|
170
|
+
for (const exampleName of exampleNames) {
|
|
171
|
+
const example = config_1.EXAMPLES[exampleName];
|
|
172
|
+
if (!example)
|
|
173
|
+
continue;
|
|
174
|
+
const contractPath = path.join(rootDir, example.contract);
|
|
175
|
+
const testPath = path.join(rootDir, example.test);
|
|
176
|
+
if (fs.existsSync(contractPath)) {
|
|
177
|
+
const contractName = (0, utils_1.getContractName)(example.contract);
|
|
178
|
+
if (contractName) {
|
|
179
|
+
fs.copyFileSync(contractPath, path.join(outputDir, "contracts", `${contractName}.sol`));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (fs.existsSync(testPath)) {
|
|
183
|
+
fs.copyFileSync(testPath, path.join(outputDir, "test", path.basename(example.test)));
|
|
184
|
+
}
|
|
185
|
+
if (example.dependencies) {
|
|
186
|
+
example.dependencies.forEach((dep) => allContractDeps.add(dep));
|
|
187
|
+
}
|
|
188
|
+
if (example.npmDependencies) {
|
|
189
|
+
Object.assign(allNpmDeps, example.npmDependencies);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// 3. Copy dependencies
|
|
193
|
+
for (const depPath of allContractDeps) {
|
|
194
|
+
const depFullPath = path.join(rootDir, depPath);
|
|
195
|
+
if (fs.existsSync(depFullPath)) {
|
|
196
|
+
const relativePath = depPath.replace(/^contracts\//, "");
|
|
197
|
+
const depDestPath = path.join(outputDir, "contracts", relativePath);
|
|
198
|
+
const depDestDir = path.dirname(depDestPath);
|
|
199
|
+
if (!fs.existsSync(depDestDir)) {
|
|
200
|
+
fs.mkdirSync(depDestDir, { recursive: true });
|
|
201
|
+
}
|
|
202
|
+
fs.copyFileSync(depFullPath, depDestPath);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// 4. Finalize project
|
|
206
|
+
(0, utils_1.updateProjectPackageJson)(outputDir, "fhevm-test-project", `Testing ${exampleNames.length} examples`, Object.keys(allNpmDeps).length > 0 ? allNpmDeps : undefined);
|
|
207
|
+
const typesPath = path.join(outputDir, "test", "types.ts");
|
|
208
|
+
if (!fs.existsSync(typesPath)) {
|
|
209
|
+
fs.writeFileSync(typesPath, utils_1.TEST_TYPES_CONTENT);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ⚠️ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY ⚠️
|
|
3
3
|
*
|
|
4
|
-
* This file is auto-generated by
|
|
5
|
-
* Run 'npm run
|
|
4
|
+
* This file is auto-generated by cli/generate-config.ts
|
|
5
|
+
* Run 'npm run generate:config' to regenerate
|
|
6
6
|
*/
|
|
7
7
|
export interface ExampleConfig {
|
|
8
8
|
/** Path to the Solidity contract file */
|
|
@@ -17,6 +17,8 @@ export interface ExampleConfig {
|
|
|
17
17
|
description: string;
|
|
18
18
|
/** Category for grouping */
|
|
19
19
|
category: string;
|
|
20
|
+
/** Output path for generated documentation */
|
|
21
|
+
docsOutput: string;
|
|
20
22
|
/** Title for documentation */
|
|
21
23
|
title: string;
|
|
22
24
|
}
|
|
@@ -31,7 +33,26 @@ export interface CategoryConfig {
|
|
|
31
33
|
}
|
|
32
34
|
export declare const REPO_URL = "https://github.com/NecipAkgz/fhevm-example-factory";
|
|
33
35
|
export declare const REPO_BRANCH = "main";
|
|
34
|
-
export declare const TEMPLATE_SUBMODULE_PATH = "fhevm-hardhat-template";
|
|
35
36
|
export declare const EXAMPLES: Record<string, ExampleConfig>;
|
|
36
37
|
export declare const CATEGORIES: Record<string, CategoryConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Get list of example names
|
|
40
|
+
*/
|
|
41
|
+
export declare function getExampleNames(): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Get list of category names
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCategoryNames(): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Get example by name
|
|
48
|
+
*/
|
|
49
|
+
export declare function getExample(name: string): ExampleConfig | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Get category by name
|
|
52
|
+
*/
|
|
53
|
+
export declare function getCategory(name: string): CategoryConfig | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Generate consistent docs filename with fhe- prefix
|
|
56
|
+
*/
|
|
57
|
+
export declare function getDocsFileName(exampleName: string): string;
|
|
37
58
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../scripts/config.ts"],"names":[],"mappings":"A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