@naseej/blox 0.1.13 → 0.1.15

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 (2) hide show
  1. package/dist/run.js +99 -96
  2. package/package.json +1 -1
package/dist/run.js CHANGED
@@ -31,11 +31,15 @@ var option = (flags, description) => {
31
31
  };
32
32
 
33
33
  // package.json
34
- var version = "0.1.13";
34
+ var version = "0.1.15";
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
+
39
43
  // src/services/shell.ts
40
44
  var import_node_child_process = require("child_process");
41
45
 
@@ -73,6 +77,7 @@ var logWarningSection = (title, content) => {
73
77
 
74
78
  // src/services/shell.ts
75
79
  var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
80
+ debug(`Command executed: "${bin} ${options.join(" ")}" with cwd = ${cwd}`);
76
81
  return new Promise(function(resolve, reject) {
77
82
  const child = (0, import_node_child_process.spawn)(bin, options, { cwd, shell: true, stdio: ["pipe", "pipe", "pipe"] });
78
83
  let error2 = "";
@@ -101,81 +106,7 @@ var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
101
106
  });
102
107
  };
103
108
 
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
-
176
109
  // src/services/git.ts
177
- var import_node_path2 = __toESM(require("path"));
178
- var import_fs_extra2 = __toESM(require("fs-extra"));
179
110
  var checkAuth = (message) => {
180
111
  if (message.includes("Username for")) {
181
112
  throw "Login to git first";
@@ -249,14 +180,14 @@ var applyPatch = (patch, cwd = ".") => {
249
180
  };
250
181
  var unInit = (cwd) => {
251
182
  debug("UnInit");
252
- return import_fs_extra2.default.remove(import_node_path2.default.join(cwd, ".git"));
183
+ return import_fs_extra.default.remove(import_node_path.default.join(cwd, ".git"));
253
184
  };
254
185
  var init = async (cwd) => {
255
186
  debug("Init");
256
187
  await $("git", ["init"], { cwd });
257
- await $("git", ["branch", "-m", "main"], { cwd });
258
188
  await $("git", ["add", "."], { cwd });
259
189
  await $("git", ["commit", "-m", "init"], { cwd });
190
+ await $("git", ["branch", "-m", "main"], { cwd });
260
191
  };
261
192
  var git = {
262
193
  clone,
@@ -272,17 +203,17 @@ var git = {
272
203
  };
273
204
 
274
205
  // src/services/registry.ts
275
- var import_node_path4 = __toESM(require("path"));
206
+ var import_node_path3 = __toESM(require("path"));
276
207
  var import_dayjs = __toESM(require("dayjs"));
277
- var import_fs_extra5 = __toESM(require("fs-extra"));
278
- var import_klaw2 = __toESM(require("klaw"));
208
+ var import_fs_extra4 = __toESM(require("fs-extra"));
209
+ var import_klaw = __toESM(require("klaw"));
279
210
  var import_ms = __toESM(require("ms"));
280
211
 
281
212
  // src/services/fs.ts
282
- var import_fs_extra3 = __toESM(require("fs-extra"));
213
+ var import_fs_extra2 = __toESM(require("fs-extra"));
283
214
  var readJsonFile = (path7, defaultValue = {}) => {
284
215
  try {
285
- return import_fs_extra3.default.readJSONSync(path7);
216
+ return import_fs_extra2.default.readJSONSync(path7);
286
217
  } catch {
287
218
  return defaultValue;
288
219
  }
@@ -318,32 +249,42 @@ async function runTask(name, task) {
318
249
  }
319
250
 
320
251
  // src/services/config.ts
321
- var import_node_path3 = __toESM(require("path"));
252
+ var import_node_path2 = __toESM(require("path"));
322
253
  var import_env_paths = __toESM(require("env-paths"));
323
- var import_fs_extra4 = __toESM(require("fs-extra"));
254
+ var import_fs_extra3 = __toESM(require("fs-extra"));
255
+
256
+ // src/config/index.ts
257
+ var defaultConfig = {
258
+ syncFrequency: "1d",
259
+ registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
260
+ };
261
+ var basedOnFile = ".blox";
262
+ var blocksDir = "blocks";
263
+
264
+ // src/services/config.ts
324
265
  var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
325
- var configFilePath = import_node_path3.default.join(appPaths.config, "config.json");
266
+ var configFilePath = import_node_path2.default.join(appPaths.config, "config.json");
326
267
  var getLocalConfig = () => {
327
268
  try {
328
- return import_fs_extra4.default.readJSONSync(configFilePath);
269
+ return import_fs_extra3.default.readJSONSync(configFilePath);
329
270
  } catch {
330
271
  return defaultConfig;
331
272
  }
332
273
  };
333
274
  var updateLocalConfig = (config) => {
334
275
  debug("Update local config");
335
- import_fs_extra4.default.ensureFileSync(configFilePath);
276
+ import_fs_extra3.default.ensureFileSync(configFilePath);
336
277
  const current = getLocalConfig();
337
- import_fs_extra4.default.writeJsonSync(configFilePath, { ...current, ...config });
278
+ import_fs_extra3.default.writeJsonSync(configFilePath, { ...current, ...config });
338
279
  };
339
280
 
340
281
  // src/services/registry.ts
341
- var registriesDataPath = import_node_path4.default.join(appPaths.data, "registries");
342
- var registriesStatPath = import_node_path4.default.join(registriesDataPath, "stats.json");
282
+ var registriesDataPath = import_node_path3.default.join(appPaths.data, "registries");
283
+ var registriesStatPath = import_node_path3.default.join(registriesDataPath, "stats.json");
343
284
  var syncRegistries = async (force, logProgress = true) => {
344
285
  debug("Sync registries");
345
286
  logProgress = logProgress || isDebugMode();
346
- import_fs_extra5.default.ensureDirSync(registriesDataPath);
287
+ import_fs_extra4.default.ensureDirSync(registriesDataPath);
347
288
  const config = getLocalConfig();
348
289
  const registriesStat = readJsonFile(registriesStatPath);
349
290
  return Promise.all(
@@ -352,14 +293,14 @@ var syncRegistries = async (force, logProgress = true) => {
352
293
  try {
353
294
  const repoName = registry.split("/").pop() || "";
354
295
  logProgress && task.start(`Updating registry: ${registry}`);
355
- const repoDir = import_node_path4.default.join(registriesDataPath, repoName);
296
+ const repoDir = import_node_path3.default.join(registriesDataPath, repoName);
356
297
  if (!registriesStat[repoName]) {
357
298
  registriesStat[repoName] = {};
358
299
  }
359
300
  const now = (0, import_dayjs.default)();
360
301
  const lastUpdated = registriesStat[repoName].lastUpdated;
361
302
  const shouldUpdate = !lastUpdated || now.isAfter((0, import_dayjs.default)(lastUpdated).add((0, import_ms.default)(config.syncFrequency)));
362
- if (!import_fs_extra5.default.existsSync(repoDir)) {
303
+ if (!import_fs_extra4.default.existsSync(repoDir)) {
363
304
  await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
364
305
  registriesStat[repoName].lastUpdated = now.format();
365
306
  } else if (force || shouldUpdate) {
@@ -368,7 +309,7 @@ var syncRegistries = async (force, logProgress = true) => {
368
309
  } else {
369
310
  logProgress && import_prompts2.log.step(`Have recent version`);
370
311
  }
371
- import_fs_extra5.default.writeJSONSync(registriesStatPath, registriesStat);
312
+ import_fs_extra4.default.writeJSONSync(registriesStatPath, registriesStat);
372
313
  logProgress && task.stop(`Updated registry: ${registry}`);
373
314
  } catch (e) {
374
315
  task.stop(`Updating registry: ${registry} failed`, 1);
@@ -380,11 +321,11 @@ var syncRegistries = async (force, logProgress = true) => {
380
321
  var getAvailableTemplates = async () => {
381
322
  debug("Get available templates");
382
323
  const templates = {};
383
- for await (const file of (0, import_klaw2.default)(registriesDataPath, {
324
+ for await (const file of (0, import_klaw.default)(registriesDataPath, {
384
325
  filter: (item) => !item.includes(".git")
385
326
  })) {
386
327
  if (file.path.endsWith(".json")) {
387
- const data = import_fs_extra5.default.readJSONSync(file.path);
328
+ const data = import_fs_extra4.default.readJSONSync(file.path);
388
329
  Object.keys(data.templates || {}).forEach((templ) => {
389
330
  templates[templ] = {
390
331
  ...data.templates[templ],
@@ -411,6 +352,59 @@ var getAvailableBlocks = async (templateName) => {
411
352
  return blocks;
412
353
  };
413
354
 
355
+ // src/services/template.ts
356
+ var import_node_path4 = __toESM(require("path"));
357
+ var import_ejs = __toESM(require("ejs"));
358
+ var import_fs_extra5 = __toESM(require("fs-extra"));
359
+ var import_klaw2 = __toESM(require("klaw"));
360
+ async function replacePlaceholders(dir, context) {
361
+ debug("Replace placeholders");
362
+ for await (const file of (0, import_klaw2.default)(dir)) {
363
+ if (file.stats.isFile()) {
364
+ const template = import_fs_extra5.default.readFileSync(file.path, "utf-8");
365
+ const rendered = import_ejs.default.render(template, context);
366
+ import_fs_extra5.default.writeFileSync(file.path, rendered, "utf-8");
367
+ }
368
+ }
369
+ }
370
+ function getPackage(cwd) {
371
+ return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, "package.json"));
372
+ }
373
+ function getTemplateInfo(cwd = ".") {
374
+ debug("Get template info");
375
+ const templateInfo = getPackage(cwd).blox;
376
+ debug(templateInfo);
377
+ return templateInfo;
378
+ }
379
+ function getBasedOnInfo(cwd = ".") {
380
+ return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, basedOnFile));
381
+ }
382
+ function saveBasedOnInfo(info, cwd = ".") {
383
+ debug("Save info");
384
+ import_fs_extra5.default.writeJSONSync(import_node_path4.default.join(cwd, basedOnFile), info);
385
+ }
386
+ function updateBasedOnInfo(updates, cwd = ".") {
387
+ const info = getBasedOnInfo(cwd);
388
+ saveBasedOnInfo({ ...info, ...updates }, cwd);
389
+ }
390
+ function getUsedBlocks() {
391
+ debug("Get used blocks");
392
+ const blocks = [];
393
+ if (import_fs_extra5.default.existsSync(blocksDir)) {
394
+ import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
395
+ if (!file.isDirectory()) {
396
+ return;
397
+ }
398
+ const templateInfo = getTemplateInfo(import_node_path4.default.join(blocksDir, file.name));
399
+ if (templateInfo) {
400
+ blocks.push(templateInfo);
401
+ }
402
+ });
403
+ }
404
+ debug(blocks);
405
+ return blocks;
406
+ }
407
+
414
408
  // src/shared/prompts/index.ts
415
409
  var import_prompts4 = require("@clack/prompts");
416
410
  var checkIfCanceled = (value) => {
@@ -443,6 +437,15 @@ var textList = async (opts) => {
443
437
  return value.split(",");
444
438
  };
445
439
 
440
+ // src/commands/init/utils/index.ts
441
+ function runInitScript(cwd) {
442
+ debug(`Run init script in: ${cwd}`);
443
+ const info = getTemplateInfo(cwd);
444
+ if (info.init) {
445
+ return $(info.init, [], { cwd });
446
+ }
447
+ }
448
+
446
449
  // src/commands/add/index.ts
447
450
  var addBlock = async (block, blocks) => {
448
451
  const blockPath = `blocks/${block}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"