saturn-core-cli 0.0.7 → 0.0.9

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.
@@ -16,29 +16,32 @@ var exec = require("child-process-promise").exec;
16
16
  var spawn = require("child-process-promise").spawn;
17
17
  const semverInc = require("semver/functions/inc");
18
18
 
19
- try {
20
- exemptions = require(saturnignore);
21
- } catch (e) {
22
- exemptions = [];
23
- }
24
-
25
- async function action(options) {
19
+ async function action(release = "patch", options) {
26
20
  try {
27
- let version_raw = options["version"];
21
+ try {
22
+ exemptions = (await import(saturnignore)).default;
23
+ } catch (e) {
24
+ console.log(e.message, e);
25
+ exemptions = [];
26
+ }
28
27
  let message = options["message"];
29
28
  const packageObj = await fs.readJson(`package.json`);
30
29
  //if (version == undefined) {
31
30
  //let version = packageObj.version;
32
31
  //}
33
- let version = semverInc(packageObj.version, version_raw);
32
+ console.log("Exemptions", exemptions);
33
+ let version = semverInc(packageObj.version, release);
34
34
  packageObj.version = version;
35
35
  await fs.writeJson(`package.json`, packageObj, { spaces: 2 });
36
36
  let map = await new mapper({ exemptions: exemptions }).createMap("./");
37
+ console.log("MAP", map);
37
38
  if (options.dry) {
38
39
  return;
39
40
  }
41
+
40
42
  let core = await getCoreId(packageObj.saturn.core);
41
43
  await createInstance(map, core.id, version, message);
44
+ console.log("DONE");
42
45
  await doGitAdd();
43
46
  await doGitCommit("SC Publish");
44
47
  await doGitPush();
@@ -207,7 +210,7 @@ async function createInstance(map, core, version, message) {
207
210
  );
208
211
  return response.data.data;
209
212
  } catch (e) {
210
- console.log("ERROR", e.message);
213
+ console.log("ERROR", e.message, e);
211
214
  }
212
215
  }
213
216
 
@@ -217,12 +220,7 @@ function command(prog) {
217
220
  program
218
221
  .command("publish [release]", { isDefault: true })
219
222
  .option("-d, --dry <template>", "Dry Run", false)
220
- .option(
221
- "-v, --version",
222
- "Version, options are major, minor, patch",
223
- "patch"
224
- )
225
- .option("-m, --description", "Description of the update", "")
223
+ .option("-m, --message", "Description of the update", "")
226
224
  .description("Publish Saturn Version")
227
225
  .action(action);
228
226
  }
package/mapper.js CHANGED
@@ -2,23 +2,54 @@ let klawSync = require("klaw-sync");
2
2
  let _ = require("lodash");
3
3
  let path = require("path");
4
4
  let crypto = require("crypto");
5
- let fs = require("fs");
5
+ let fs = require("graceful-fs");
6
6
 
7
7
  let exemptions = [];
8
8
  let dir_path = ".";
9
9
 
10
+ /* function generateChecksum(file) {
11
+ return new Promise(function (resolve, reject) {
12
+ try {
13
+ var hash = crypto.createHash("md5");
14
+ var stream = fs.createReadStream(file);
15
+ stream.on("data", function (data) {
16
+ hash.update(data);
17
+ });
18
+ stream.on("end", function () {
19
+ var sha = hash.digest("hex");
20
+ resolve(sha);
21
+ });
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ });
26
+ } */
10
27
  function generateChecksum(file) {
11
28
  return new Promise(function (resolve, reject) {
12
29
  try {
13
30
  var hash = crypto.createHash("md5");
14
31
  var stream = fs.createReadStream(file);
32
+
15
33
  stream.on("data", function (data) {
16
34
  hash.update(data);
17
35
  });
36
+
37
+ // Listen for the 'end' event to finish the hash calculation
18
38
  stream.on("end", function () {
19
39
  var sha = hash.digest("hex");
40
+ stream.close(); // Manually close the stream (if necessary)
20
41
  resolve(sha);
21
42
  });
43
+
44
+ // Listen for the 'close' event to ensure resources are released
45
+ stream.on("close", function () {
46
+ // console.log(`Stream for ${file} closed`);
47
+ });
48
+
49
+ // Handle errors
50
+ stream.on("error", function (error) {
51
+ reject(error);
52
+ });
22
53
  } catch (e) {
23
54
  reject(e);
24
55
  }
@@ -28,7 +59,9 @@ function generateChecksum(file) {
28
59
  function isExemptedDirectory(item) {
29
60
  let file = _.last(item.path.split(dir_path + "/"));
30
61
  let included = _.includes(
31
- _.map(exemptions, (exem) => _.startsWith(file, exem)),
62
+ _.map(exemptions, (exem) => {
63
+ return _.startsWith(file, exem);
64
+ }),
32
65
  true
33
66
  );
34
67
  return !included;
@@ -49,10 +82,10 @@ module.exports = class Mapper {
49
82
  return _.groupBy(
50
83
  await Promise.all(
51
84
  files.map(async function (file) {
85
+ //console.log("Mapping::", file.path);
52
86
  return {
53
87
  file: _.last(file.path.split(dir_path + "/")),
54
88
  size: file.stats.size,
55
-
56
89
  checksum: await generateChecksum(file.path),
57
90
  creation_date: file.stats.birthtime,
58
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saturn-core-cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Saturn Core CLI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@
21
21
  "colors": "^1.4.0",
22
22
  "commander": "^11.1.0",
23
23
  "fs-extra": "^11.1.1",
24
+ "graceful-fs": "^4.2.11",
24
25
  "klaw-sync": "^6.0.0",
25
26
  "lodash": "^4.17.21",
26
27
  "pluralize": "^8.0.0",