@akanjs/devkit 0.0.61 → 0.0.63
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/package.json +1 -1
- package/src/executors.cjs +20 -12
- package/src/executors.d.ts +1 -0
- package/src/executors.js +20 -12
package/package.json
CHANGED
package/src/executors.cjs
CHANGED
|
@@ -107,15 +107,22 @@ class Executor {
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
+
#getPath(filePath) {
|
|
111
|
+
return import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
112
|
+
}
|
|
110
113
|
mkdir(dirPath) {
|
|
111
|
-
const writePath =
|
|
114
|
+
const writePath = this.#getPath(dirPath);
|
|
112
115
|
if (!import_fs.default.existsSync(writePath))
|
|
113
116
|
import_fs.default.mkdirSync(writePath, { recursive: true });
|
|
114
117
|
this.logger.verbose(`Make directory ${writePath}`);
|
|
115
118
|
return this;
|
|
116
119
|
}
|
|
120
|
+
exists(filePath) {
|
|
121
|
+
const readPath = this.#getPath(filePath);
|
|
122
|
+
return import_fs.default.existsSync(readPath);
|
|
123
|
+
}
|
|
117
124
|
writeFile(filePath, content) {
|
|
118
|
-
const writePath =
|
|
125
|
+
const writePath = this.#getPath(filePath);
|
|
119
126
|
const dir = import_path.default.dirname(writePath);
|
|
120
127
|
if (!import_fs.default.existsSync(dir))
|
|
121
128
|
import_fs.default.mkdirSync(dir, { recursive: true });
|
|
@@ -144,16 +151,16 @@ class Executor {
|
|
|
144
151
|
return { filepath, content };
|
|
145
152
|
}
|
|
146
153
|
readFile(filePath) {
|
|
147
|
-
const readPath =
|
|
154
|
+
const readPath = this.#getPath(filePath);
|
|
148
155
|
return import_fs.default.readFileSync(readPath, "utf8");
|
|
149
156
|
}
|
|
150
157
|
readJson(filePath) {
|
|
151
|
-
const readPath =
|
|
158
|
+
const readPath = this.#getPath(filePath);
|
|
152
159
|
return JSON.parse(import_fs.default.readFileSync(readPath, "utf8"));
|
|
153
160
|
}
|
|
154
161
|
async cp(srcPath, destPath) {
|
|
155
|
-
const src =
|
|
156
|
-
const dest =
|
|
162
|
+
const src = this.#getPath(srcPath);
|
|
163
|
+
const dest = this.#getPath(destPath);
|
|
157
164
|
await import_promises.default.cp(src, dest, { recursive: true });
|
|
158
165
|
}
|
|
159
166
|
log(msg) {
|
|
@@ -183,13 +190,16 @@ class Executor {
|
|
|
183
190
|
}, dict = {}) {
|
|
184
191
|
if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
|
|
185
192
|
const getContent = await import(templatePath);
|
|
186
|
-
const
|
|
193
|
+
const result = getContent.default(scanResult ?? null, dict);
|
|
194
|
+
if (result === null)
|
|
195
|
+
return;
|
|
196
|
+
const filename = typeof result === "object" ? result.filename : import_path.default.basename(targetPath).replace(".js", ".ts");
|
|
197
|
+
const content = typeof result === "object" ? result.content : result;
|
|
198
|
+
const dirname = import_path.default.dirname(targetPath);
|
|
187
199
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
188
200
|
(path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
|
|
189
|
-
|
|
201
|
+
`${dirname}/${filename}`
|
|
190
202
|
);
|
|
191
|
-
if (content === null)
|
|
192
|
-
return;
|
|
193
203
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
194
204
|
this.writeFile(convertedTargetPath, content);
|
|
195
205
|
} else if (targetPath.endsWith(".template")) {
|
|
@@ -217,8 +227,6 @@ class Executor {
|
|
|
217
227
|
const filename = import_path.default.basename(templatePath);
|
|
218
228
|
await this.#applyTemplateFile({ templatePath, targetPath: import_path.default.join(basePath, filename), scanResult }, dict);
|
|
219
229
|
} else {
|
|
220
|
-
if (!import_fs.default.existsSync(basePath))
|
|
221
|
-
await import_promises.default.mkdir(basePath, { recursive: true });
|
|
222
230
|
const subdirs = await import_promises.default.readdir(templatePath);
|
|
223
231
|
await Promise.all(
|
|
224
232
|
subdirs.map(async (subdir) => {
|
package/src/executors.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class Executor {
|
|
|
14
14
|
}>;
|
|
15
15
|
fork(modulePath: string, args?: string[], options?: ForkOptions): Promise<unknown>;
|
|
16
16
|
mkdir(dirPath: string): this;
|
|
17
|
+
exists(filePath: string): boolean;
|
|
17
18
|
writeFile(filePath: string, content: string | object): this;
|
|
18
19
|
writeJson(filePath: string, content: object): this;
|
|
19
20
|
getLocalFile(filePath: string): {
|
package/src/executors.js
CHANGED
|
@@ -71,15 +71,22 @@ class Executor {
|
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
#getPath(filePath) {
|
|
75
|
+
return path.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
76
|
+
}
|
|
74
77
|
mkdir(dirPath) {
|
|
75
|
-
const writePath =
|
|
78
|
+
const writePath = this.#getPath(dirPath);
|
|
76
79
|
if (!fs.existsSync(writePath))
|
|
77
80
|
fs.mkdirSync(writePath, { recursive: true });
|
|
78
81
|
this.logger.verbose(`Make directory ${writePath}`);
|
|
79
82
|
return this;
|
|
80
83
|
}
|
|
84
|
+
exists(filePath) {
|
|
85
|
+
const readPath = this.#getPath(filePath);
|
|
86
|
+
return fs.existsSync(readPath);
|
|
87
|
+
}
|
|
81
88
|
writeFile(filePath, content) {
|
|
82
|
-
const writePath =
|
|
89
|
+
const writePath = this.#getPath(filePath);
|
|
83
90
|
const dir = path.dirname(writePath);
|
|
84
91
|
if (!fs.existsSync(dir))
|
|
85
92
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -108,16 +115,16 @@ class Executor {
|
|
|
108
115
|
return { filepath, content };
|
|
109
116
|
}
|
|
110
117
|
readFile(filePath) {
|
|
111
|
-
const readPath =
|
|
118
|
+
const readPath = this.#getPath(filePath);
|
|
112
119
|
return fs.readFileSync(readPath, "utf8");
|
|
113
120
|
}
|
|
114
121
|
readJson(filePath) {
|
|
115
|
-
const readPath =
|
|
122
|
+
const readPath = this.#getPath(filePath);
|
|
116
123
|
return JSON.parse(fs.readFileSync(readPath, "utf8"));
|
|
117
124
|
}
|
|
118
125
|
async cp(srcPath, destPath) {
|
|
119
|
-
const src =
|
|
120
|
-
const dest =
|
|
126
|
+
const src = this.#getPath(srcPath);
|
|
127
|
+
const dest = this.#getPath(destPath);
|
|
121
128
|
await fsPromise.cp(src, dest, { recursive: true });
|
|
122
129
|
}
|
|
123
130
|
log(msg) {
|
|
@@ -147,13 +154,16 @@ class Executor {
|
|
|
147
154
|
}, dict = {}) {
|
|
148
155
|
if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
|
|
149
156
|
const getContent = await import(templatePath);
|
|
150
|
-
const
|
|
157
|
+
const result = getContent.default(scanResult ?? null, dict);
|
|
158
|
+
if (result === null)
|
|
159
|
+
return;
|
|
160
|
+
const filename = typeof result === "object" ? result.filename : path.basename(targetPath).replace(".js", ".ts");
|
|
161
|
+
const content = typeof result === "object" ? result.content : result;
|
|
162
|
+
const dirname = path.dirname(targetPath);
|
|
151
163
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
152
164
|
(path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
|
|
153
|
-
|
|
165
|
+
`${dirname}/${filename}`
|
|
154
166
|
);
|
|
155
|
-
if (content === null)
|
|
156
|
-
return;
|
|
157
167
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
158
168
|
this.writeFile(convertedTargetPath, content);
|
|
159
169
|
} else if (targetPath.endsWith(".template")) {
|
|
@@ -181,8 +191,6 @@ class Executor {
|
|
|
181
191
|
const filename = path.basename(templatePath);
|
|
182
192
|
await this.#applyTemplateFile({ templatePath, targetPath: path.join(basePath, filename), scanResult }, dict);
|
|
183
193
|
} else {
|
|
184
|
-
if (!fs.existsSync(basePath))
|
|
185
|
-
await fsPromise.mkdir(basePath, { recursive: true });
|
|
186
194
|
const subdirs = await fsPromise.readdir(templatePath);
|
|
187
195
|
await Promise.all(
|
|
188
196
|
subdirs.map(async (subdir) => {
|