@naseej/blox 0.1.11 → 0.1.13
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/dist/run.js +101 -88
- package/package.json +1 -1
package/dist/run.js
CHANGED
|
@@ -31,15 +31,11 @@ var option = (flags, description) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// package.json
|
|
34
|
-
var version = "0.1.
|
|
34
|
+
var version = "0.1.13";
|
|
35
35
|
|
|
36
36
|
// src/commands/add/index.ts
|
|
37
37
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
38
38
|
|
|
39
|
-
// src/services/git.ts
|
|
40
|
-
var import_node_path = __toESM(require("path"));
|
|
41
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
42
|
-
|
|
43
39
|
// src/services/shell.ts
|
|
44
40
|
var import_node_child_process = require("child_process");
|
|
45
41
|
|
|
@@ -105,7 +101,81 @@ var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
|
105
101
|
});
|
|
106
102
|
};
|
|
107
103
|
|
|
104
|
+
// src/services/template.ts
|
|
105
|
+
var import_node_path = __toESM(require("path"));
|
|
106
|
+
var import_ejs = __toESM(require("ejs"));
|
|
107
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
108
|
+
var import_klaw = __toESM(require("klaw"));
|
|
109
|
+
|
|
110
|
+
// src/config/index.ts
|
|
111
|
+
var defaultConfig = {
|
|
112
|
+
syncFrequency: "1d",
|
|
113
|
+
registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
|
|
114
|
+
};
|
|
115
|
+
var basedOnFile = ".blox";
|
|
116
|
+
var blocksDir = "blocks";
|
|
117
|
+
|
|
118
|
+
// src/services/template.ts
|
|
119
|
+
async function replacePlaceholders(dir, context) {
|
|
120
|
+
debug("Replace placeholders");
|
|
121
|
+
for await (const file of (0, import_klaw.default)(dir)) {
|
|
122
|
+
if (file.stats.isFile()) {
|
|
123
|
+
const template = import_fs_extra.default.readFileSync(file.path, "utf-8");
|
|
124
|
+
const rendered = import_ejs.default.render(template, context);
|
|
125
|
+
import_fs_extra.default.writeFileSync(file.path, rendered, "utf-8");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function getPackage(cwd) {
|
|
130
|
+
return import_fs_extra.default.readJSONSync(import_node_path.default.join(cwd, "package.json"));
|
|
131
|
+
}
|
|
132
|
+
function getTemplateInfo(cwd = ".") {
|
|
133
|
+
debug("Get template info");
|
|
134
|
+
const templateInfo = getPackage(cwd).blox;
|
|
135
|
+
debug(templateInfo);
|
|
136
|
+
return templateInfo;
|
|
137
|
+
}
|
|
138
|
+
function getBasedOnInfo(cwd = ".") {
|
|
139
|
+
return import_fs_extra.default.readJSONSync(import_node_path.default.join(cwd, basedOnFile));
|
|
140
|
+
}
|
|
141
|
+
function saveBasedOnInfo(info, cwd = ".") {
|
|
142
|
+
debug("Save info");
|
|
143
|
+
import_fs_extra.default.writeJSONSync(import_node_path.default.join(cwd, basedOnFile), info);
|
|
144
|
+
}
|
|
145
|
+
function updateBasedOnInfo(updates, cwd = ".") {
|
|
146
|
+
const info = getBasedOnInfo(cwd);
|
|
147
|
+
saveBasedOnInfo({ ...info, ...updates }, cwd);
|
|
148
|
+
}
|
|
149
|
+
function getUsedBlocks() {
|
|
150
|
+
debug("Get used blocks");
|
|
151
|
+
const blocks = [];
|
|
152
|
+
if (import_fs_extra.default.existsSync(blocksDir)) {
|
|
153
|
+
import_fs_extra.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
154
|
+
if (!file.isDirectory()) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const templateInfo = getTemplateInfo(import_node_path.default.join(blocksDir, file.name));
|
|
158
|
+
if (templateInfo) {
|
|
159
|
+
blocks.push(templateInfo);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
debug(blocks);
|
|
164
|
+
return blocks;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/commands/init/utils/index.ts
|
|
168
|
+
function runInitScript(cwd) {
|
|
169
|
+
debug(`Run init script in: ${cwd}`);
|
|
170
|
+
const info = getTemplateInfo(cwd);
|
|
171
|
+
if (info.init) {
|
|
172
|
+
return $(info.init, [], { cwd });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
108
176
|
// src/services/git.ts
|
|
177
|
+
var import_node_path2 = __toESM(require("path"));
|
|
178
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
109
179
|
var checkAuth = (message) => {
|
|
110
180
|
if (message.includes("Username for")) {
|
|
111
181
|
throw "Login to git first";
|
|
@@ -179,7 +249,7 @@ var applyPatch = (patch, cwd = ".") => {
|
|
|
179
249
|
};
|
|
180
250
|
var unInit = (cwd) => {
|
|
181
251
|
debug("UnInit");
|
|
182
|
-
return
|
|
252
|
+
return import_fs_extra2.default.remove(import_node_path2.default.join(cwd, ".git"));
|
|
183
253
|
};
|
|
184
254
|
var init = async (cwd) => {
|
|
185
255
|
debug("Init");
|
|
@@ -202,17 +272,17 @@ var git = {
|
|
|
202
272
|
};
|
|
203
273
|
|
|
204
274
|
// src/services/registry.ts
|
|
205
|
-
var
|
|
275
|
+
var import_node_path4 = __toESM(require("path"));
|
|
206
276
|
var import_dayjs = __toESM(require("dayjs"));
|
|
207
|
-
var
|
|
208
|
-
var
|
|
277
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
278
|
+
var import_klaw2 = __toESM(require("klaw"));
|
|
209
279
|
var import_ms = __toESM(require("ms"));
|
|
210
280
|
|
|
211
281
|
// src/services/fs.ts
|
|
212
|
-
var
|
|
282
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
213
283
|
var readJsonFile = (path7, defaultValue = {}) => {
|
|
214
284
|
try {
|
|
215
|
-
return
|
|
285
|
+
return import_fs_extra3.default.readJSONSync(path7);
|
|
216
286
|
} catch {
|
|
217
287
|
return defaultValue;
|
|
218
288
|
}
|
|
@@ -248,42 +318,32 @@ async function runTask(name, task) {
|
|
|
248
318
|
}
|
|
249
319
|
|
|
250
320
|
// src/services/config.ts
|
|
251
|
-
var
|
|
321
|
+
var import_node_path3 = __toESM(require("path"));
|
|
252
322
|
var import_env_paths = __toESM(require("env-paths"));
|
|
253
|
-
var
|
|
254
|
-
|
|
255
|
-
// src/config/index.ts
|
|
256
|
-
var defaultConfig = {
|
|
257
|
-
syncFrequency: "1d",
|
|
258
|
-
registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
|
|
259
|
-
};
|
|
260
|
-
var basedOnFile = ".blox";
|
|
261
|
-
var blocksDir = "blocks";
|
|
262
|
-
|
|
263
|
-
// src/services/config.ts
|
|
323
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
264
324
|
var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
|
|
265
|
-
var configFilePath =
|
|
325
|
+
var configFilePath = import_node_path3.default.join(appPaths.config, "config.json");
|
|
266
326
|
var getLocalConfig = () => {
|
|
267
327
|
try {
|
|
268
|
-
return
|
|
328
|
+
return import_fs_extra4.default.readJSONSync(configFilePath);
|
|
269
329
|
} catch {
|
|
270
330
|
return defaultConfig;
|
|
271
331
|
}
|
|
272
332
|
};
|
|
273
333
|
var updateLocalConfig = (config) => {
|
|
274
334
|
debug("Update local config");
|
|
275
|
-
|
|
335
|
+
import_fs_extra4.default.ensureFileSync(configFilePath);
|
|
276
336
|
const current = getLocalConfig();
|
|
277
|
-
|
|
337
|
+
import_fs_extra4.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
278
338
|
};
|
|
279
339
|
|
|
280
340
|
// src/services/registry.ts
|
|
281
|
-
var registriesDataPath =
|
|
282
|
-
var registriesStatPath =
|
|
341
|
+
var registriesDataPath = import_node_path4.default.join(appPaths.data, "registries");
|
|
342
|
+
var registriesStatPath = import_node_path4.default.join(registriesDataPath, "stats.json");
|
|
283
343
|
var syncRegistries = async (force, logProgress = true) => {
|
|
284
344
|
debug("Sync registries");
|
|
285
345
|
logProgress = logProgress || isDebugMode();
|
|
286
|
-
|
|
346
|
+
import_fs_extra5.default.ensureDirSync(registriesDataPath);
|
|
287
347
|
const config = getLocalConfig();
|
|
288
348
|
const registriesStat = readJsonFile(registriesStatPath);
|
|
289
349
|
return Promise.all(
|
|
@@ -292,14 +352,14 @@ var syncRegistries = async (force, logProgress = true) => {
|
|
|
292
352
|
try {
|
|
293
353
|
const repoName = registry.split("/").pop() || "";
|
|
294
354
|
logProgress && task.start(`Updating registry: ${registry}`);
|
|
295
|
-
const repoDir =
|
|
355
|
+
const repoDir = import_node_path4.default.join(registriesDataPath, repoName);
|
|
296
356
|
if (!registriesStat[repoName]) {
|
|
297
357
|
registriesStat[repoName] = {};
|
|
298
358
|
}
|
|
299
359
|
const now = (0, import_dayjs.default)();
|
|
300
360
|
const lastUpdated = registriesStat[repoName].lastUpdated;
|
|
301
361
|
const shouldUpdate = !lastUpdated || now.isAfter((0, import_dayjs.default)(lastUpdated).add((0, import_ms.default)(config.syncFrequency)));
|
|
302
|
-
if (!
|
|
362
|
+
if (!import_fs_extra5.default.existsSync(repoDir)) {
|
|
303
363
|
await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
|
|
304
364
|
registriesStat[repoName].lastUpdated = now.format();
|
|
305
365
|
} else if (force || shouldUpdate) {
|
|
@@ -308,7 +368,7 @@ var syncRegistries = async (force, logProgress = true) => {
|
|
|
308
368
|
} else {
|
|
309
369
|
logProgress && import_prompts2.log.step(`Have recent version`);
|
|
310
370
|
}
|
|
311
|
-
|
|
371
|
+
import_fs_extra5.default.writeJSONSync(registriesStatPath, registriesStat);
|
|
312
372
|
logProgress && task.stop(`Updated registry: ${registry}`);
|
|
313
373
|
} catch (e) {
|
|
314
374
|
task.stop(`Updating registry: ${registry} failed`, 1);
|
|
@@ -320,11 +380,11 @@ var syncRegistries = async (force, logProgress = true) => {
|
|
|
320
380
|
var getAvailableTemplates = async () => {
|
|
321
381
|
debug("Get available templates");
|
|
322
382
|
const templates = {};
|
|
323
|
-
for await (const file of (0,
|
|
383
|
+
for await (const file of (0, import_klaw2.default)(registriesDataPath, {
|
|
324
384
|
filter: (item) => !item.includes(".git")
|
|
325
385
|
})) {
|
|
326
386
|
if (file.path.endsWith(".json")) {
|
|
327
|
-
const data =
|
|
387
|
+
const data = import_fs_extra5.default.readJSONSync(file.path);
|
|
328
388
|
Object.keys(data.templates || {}).forEach((templ) => {
|
|
329
389
|
templates[templ] = {
|
|
330
390
|
...data.templates[templ],
|
|
@@ -351,59 +411,6 @@ var getAvailableBlocks = async (templateName) => {
|
|
|
351
411
|
return blocks;
|
|
352
412
|
};
|
|
353
413
|
|
|
354
|
-
// src/services/template.ts
|
|
355
|
-
var import_node_path4 = __toESM(require("path"));
|
|
356
|
-
var import_ejs = __toESM(require("ejs"));
|
|
357
|
-
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
358
|
-
var import_klaw2 = __toESM(require("klaw"));
|
|
359
|
-
async function replacePlaceholders(dir, context) {
|
|
360
|
-
debug("Replace placeholders");
|
|
361
|
-
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
362
|
-
if (file.stats.isFile()) {
|
|
363
|
-
const template = import_fs_extra5.default.readFileSync(file.path, "utf-8");
|
|
364
|
-
const rendered = import_ejs.default.render(template, context);
|
|
365
|
-
import_fs_extra5.default.writeFileSync(file.path, rendered, "utf-8");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function getPackage(cwd) {
|
|
370
|
-
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, "package.json"));
|
|
371
|
-
}
|
|
372
|
-
function getTemplateInfo(cwd = ".") {
|
|
373
|
-
debug("Get template info");
|
|
374
|
-
const templateInfo = getPackage(cwd).blox;
|
|
375
|
-
debug(templateInfo);
|
|
376
|
-
return templateInfo;
|
|
377
|
-
}
|
|
378
|
-
function getBasedOnInfo(cwd = ".") {
|
|
379
|
-
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, basedOnFile));
|
|
380
|
-
}
|
|
381
|
-
function saveBasedOnInfo(info, cwd = ".") {
|
|
382
|
-
debug("Save info");
|
|
383
|
-
import_fs_extra5.default.writeJSONSync(import_node_path4.default.join(cwd, basedOnFile), info);
|
|
384
|
-
}
|
|
385
|
-
function updateBasedOnInfo(updates, cwd = ".") {
|
|
386
|
-
const info = getBasedOnInfo(cwd);
|
|
387
|
-
saveBasedOnInfo({ ...info, ...updates }, cwd);
|
|
388
|
-
}
|
|
389
|
-
function getUsedBlocks() {
|
|
390
|
-
debug("Get used blocks");
|
|
391
|
-
const blocks = [];
|
|
392
|
-
if (import_fs_extra5.default.existsSync(blocksDir)) {
|
|
393
|
-
import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
394
|
-
if (!file.isDirectory()) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
const templateInfo = getTemplateInfo(import_node_path4.default.join(blocksDir, file.name));
|
|
398
|
-
if (templateInfo) {
|
|
399
|
-
blocks.push(templateInfo);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
debug(blocks);
|
|
404
|
-
return blocks;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
414
|
// src/shared/prompts/index.ts
|
|
408
415
|
var import_prompts4 = require("@clack/prompts");
|
|
409
416
|
var checkIfCanceled = (value) => {
|
|
@@ -448,6 +455,7 @@ var addBlock = async (block, blocks) => {
|
|
|
448
455
|
await git.unInit(blockPath);
|
|
449
456
|
await replacePlaceholders(blockPath, {});
|
|
450
457
|
saveBasedOnInfo({ commit }, blockPath);
|
|
458
|
+
await runInitScript(blockPath);
|
|
451
459
|
task.stop(`Block ${block} added`);
|
|
452
460
|
} else {
|
|
453
461
|
import_prompts2.log.warn(`${block} already exists, may need to be updated`);
|
|
@@ -539,6 +547,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
539
547
|
await replacePlaceholders(name, { app: { name } });
|
|
540
548
|
saveBasedOnInfo({ commit }, name);
|
|
541
549
|
await git.init(name);
|
|
550
|
+
await runInitScript(name);
|
|
542
551
|
task.stop(`App initialized in ${name}`);
|
|
543
552
|
} catch (e) {
|
|
544
553
|
error(e);
|
|
@@ -568,6 +577,10 @@ async function updateFromRemote(name, source = "", destPath = ".") {
|
|
|
568
577
|
const fromCommit = getBasedOnInfo(destPath).commit;
|
|
569
578
|
const toCommit = await git.getLatestCommitFromRemote(name);
|
|
570
579
|
debug({ fromCommit, toCommit });
|
|
580
|
+
if (fromCommit == toCommit) {
|
|
581
|
+
debug("No new version");
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
571
584
|
const patchFilePath = import_node_path5.default.join(destPath, "diff.patch");
|
|
572
585
|
await git.createPatch(fromCommit, toCommit, patchFilePath);
|
|
573
586
|
const changes = await git.getChangesLog(fromCommit, toCommit);
|