@sera4/essentia 1.0.4 → 1.0.6

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/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = {
2
2
  paginator : require("./paginator/s4-pagination"),
3
- logger : require("./logger/s4-logger")
3
+ logger : require("./logger/s4-logger"),
4
+ lastCommit : require("./last_commit")
4
5
  }
package/last-commit.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ const lastCommit = require("./last_commit");
3
+ lastCommit.writeLastCommit()
4
+ .then(c => {
5
+ console.debug("Last commit written");
6
+ console.debug(c);
7
+ })
8
+ .catch(e => {
9
+ console.error("Failed to write last commit");
10
+ console.error(e);
11
+ })
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ const git = require('git-rev');
4
+ const fs = require('fs');
5
+ const async = require('async');
6
+ const path = require('path');
7
+ const appDir = path.dirname(require.main.filename);
8
+ const commitFile = `${appDir}/last-commit.json`;
9
+
10
+ module.exports = {
11
+ parseLastCommit() {
12
+ return new Promise((resolve, reject) => {
13
+ async.waterfall([
14
+ (next) => {
15
+ var commit = {};
16
+ git.branch((str) => {
17
+ commit["branch"] = str;
18
+ next(null, commit);
19
+ });
20
+ },
21
+ (commit, next) => {
22
+ git.long((str) => {
23
+ commit["commmit"] = str;
24
+ next(null, commit);
25
+ });
26
+ }
27
+ ], (err, commit) => {
28
+ if (err) {
29
+ reject(err);
30
+ } else {
31
+ resolve(commit);
32
+ }
33
+ })
34
+ })
35
+ },
36
+ getLastCommit() {
37
+ return new Promise((resolve, reject) => {
38
+ fs.readFile(commitFile, 'utf8', (err, data) => {
39
+ if (err) {
40
+ reject(err);
41
+ } else {
42
+ try {
43
+ var commit = JSON.parse(data);
44
+ resolve(commit);
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ }
49
+ });
50
+ });
51
+ },
52
+ getLastCommitSync() {
53
+ var data = fs.readFileSync(commitFile, 'utf8');
54
+ return JSON.parse(data);
55
+ },
56
+ writeLastCommit() {
57
+ return new Promise((resolve, reject) => {
58
+ async.waterfall([
59
+ (next) => {
60
+ this.parseLastCommit()
61
+ .then((commit) => next(null, commit))
62
+ .catch(e => next(e));
63
+ },
64
+ (commit, next) => {
65
+ fs.writeFile(commitFile, JSON.stringify(commit, null, 2), 'utf8', (err) => {
66
+ next(err, commit);
67
+ });
68
+ }
69
+ ],(err, commit) => {
70
+ if (err) {
71
+ reject(err);
72
+ } else {
73
+ resolve(commit);
74
+ }
75
+ })
76
+ });
77
+ }
78
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "./node_modules/.bin/mocha --reporter mocha-junit-reporter --reporter-options mochaFile=./test-results/result.xml --exit",
8
- "testdev": "./node_modules/.bin/mocha --watch"
8
+ "testdev": "./node_modules/.bin/mocha --watch",
9
+ "last-commit": "node last-commit.js"
9
10
  },
10
11
  "author": "Dev DM <dev@sera4.com>",
11
12
  "repository": {
@@ -23,6 +24,8 @@
23
24
  "sinon": "^5.0.1"
24
25
  },
25
26
  "dependencies": {
27
+ "async": "^2.6.1",
28
+ "git-rev": "^0.2.1",
26
29
  "winston": "^2.4.2"
27
30
  }
28
31
  }
package/package.tar.gz CHANGED
Binary file