@efebia/hardhat-compile-monorepo 0.0.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/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +13 -0
- package/lib/task.d.ts +1 -0
- package/lib/task.js +91 -0
- package/lib/types.d.ts +18 -0
- package/lib/types.js +3 -0
- package/package.json +20 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const packageName = "@efebia/hardhat-compile-monorepo";
|
package/lib/constants.js
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("hardhat/config");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
require("./task");
|
|
6
|
+
require("./types");
|
|
7
|
+
(0, config_1.extendConfig)((config, userConfig) => {
|
|
8
|
+
config.compileMonorepo = Object.assign({
|
|
9
|
+
paths: [],
|
|
10
|
+
path: `./${constants_1.packageName}`,
|
|
11
|
+
keep: false
|
|
12
|
+
}, userConfig.compileMonorepo);
|
|
13
|
+
});
|
package/lib/task.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types";
|
package/lib/task.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const config_1 = require("hardhat/config");
|
|
9
|
+
const plugins_1 = require("hardhat/plugins");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const task_names_1 = require("hardhat/builtin-tasks/task-names");
|
|
12
|
+
const constants_1 = require("./constants");
|
|
13
|
+
require("./types");
|
|
14
|
+
const generate = function (dependency) {
|
|
15
|
+
return [
|
|
16
|
+
"// SPDX-License-Identifier: UNLICENSED",
|
|
17
|
+
"pragma solidity >0.0.0;",
|
|
18
|
+
`import '${dependency}';`,
|
|
19
|
+
]
|
|
20
|
+
.map((l) => `${l}\n`)
|
|
21
|
+
.join("");
|
|
22
|
+
};
|
|
23
|
+
(0, config_1.task)(task_names_1.TASK_COMPILE, async (args, hre, runSuper) => {
|
|
24
|
+
const config = hre.config.compileMonorepo;
|
|
25
|
+
const directory = path_1.default.resolve(hre.config.paths.sources, config.path);
|
|
26
|
+
if (!directory.startsWith(hre.config.paths.sources)) {
|
|
27
|
+
throw new plugins_1.HardhatPluginError(constants_1.packageName, "resolved path must be inside of sources directory");
|
|
28
|
+
}
|
|
29
|
+
if (directory === hre.config.paths.sources) {
|
|
30
|
+
throw new plugins_1.HardhatPluginError(constants_1.packageName, "resolved path must not be sources directory");
|
|
31
|
+
}
|
|
32
|
+
if (fs_1.default.existsSync(directory)) {
|
|
33
|
+
const segments = constants_1.packageName.split("/");
|
|
34
|
+
const lastElement = segments.pop();
|
|
35
|
+
if (fs_1.default.existsSync(path_1.default.resolve(directory, segments.join("/"), `.${lastElement}`))) {
|
|
36
|
+
fs_1.default.rmSync(directory, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new plugins_1.HardhatPluginError(constants_1.packageName, `temporary source directory must have been generated by ${constants_1.packageName}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
fs_1.default.mkdirSync(directory, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
const segments = constants_1.packageName.split("/");
|
|
46
|
+
const lastElement = segments.pop();
|
|
47
|
+
fs_1.default.mkdirSync(path_1.default.resolve(directory, segments.join("/")), {
|
|
48
|
+
recursive: true,
|
|
49
|
+
});
|
|
50
|
+
fs_1.default.writeFileSync(path_1.default.resolve(directory, segments.join("/"), `.${lastElement}`), `directory approved for write access by ${constants_1.packageName}\n`);
|
|
51
|
+
for (const dependency of config.paths) {
|
|
52
|
+
const fullPath = path_1.default.join(directory, dependency);
|
|
53
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(fullPath))) {
|
|
54
|
+
fs_1.default.mkdirSync(path_1.default.dirname(fullPath), { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
let files = [{ path: fullPath, dependency }];
|
|
57
|
+
if (!path_1.default.extname(dependency)) {
|
|
58
|
+
const modulePath = require.resolve(dependency);
|
|
59
|
+
const pathDetails = path_1.default.parse(modulePath);
|
|
60
|
+
const packageJsonPath = path_1.default.join(pathDetails.dir, "package.json");
|
|
61
|
+
const packageJson = require(packageJsonPath);
|
|
62
|
+
const packageJsonFiles = packageJson.files[0] || "**/*.sol";
|
|
63
|
+
const resolvedGlobFiles = glob_1.default.sync(packageJsonFiles, {
|
|
64
|
+
cwd: pathDetails.dir,
|
|
65
|
+
});
|
|
66
|
+
files = resolvedGlobFiles.map((globbedFile) => {
|
|
67
|
+
const currentPath = path_1.default.join(directory, `${dependency}/${globbedFile}`);
|
|
68
|
+
fs_1.default.mkdirSync(path_1.default.dirname(currentPath), { recursive: true });
|
|
69
|
+
return {
|
|
70
|
+
path: currentPath,
|
|
71
|
+
dependency: `${dependency}/${globbedFile}`,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
fs_1.default.writeFileSync(file.path, generate(file.dependency));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await runSuper();
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (!config.keep) {
|
|
84
|
+
fs_1.default.rmSync(directory, { recursive: true });
|
|
85
|
+
if (fs_1.default.existsSync(hre.config.paths.sources) &&
|
|
86
|
+
fs_1.default.readdirSync(hre.config.paths.sources).length === 0) {
|
|
87
|
+
fs_1.default.rmSync(hre.config.paths.sources, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "hardhat/types/config";
|
|
2
|
+
declare module "hardhat/types/config" {
|
|
3
|
+
interface HardhatConfig {
|
|
4
|
+
compileMonorepo: {
|
|
5
|
+
paths: string[];
|
|
6
|
+
path: string;
|
|
7
|
+
keep: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface HardhatUserConfig {
|
|
11
|
+
compileMonorepo: {
|
|
12
|
+
paths: string[];
|
|
13
|
+
path: string;
|
|
14
|
+
keep: boolean;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/lib/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@efebia/hardhat-compile-monorepo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"glob": "^8.0.3",
|
|
7
|
+
"hardhat": "^2.12.6"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/glob": "^8.0.0",
|
|
11
|
+
"typescript": "^4.9.4"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"/lib"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc"
|
|
18
|
+
},
|
|
19
|
+
"main": "./lib"
|
|
20
|
+
}
|