-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
obs.js
85 lines (72 loc) · 2.21 KB
/
obs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
/*
build obs by running
npm run build
guid and uuid will be automatically generated and placed
inside .env file which will then be read by the github workflow
build script.
*/
/*
This script handles the following:
- read package.json
- create .env file
- return uuid, guid, version
can be called with the following external commands:
- node obs.js returns version of obs
- node obs.js generate generates uuid / guid and shows all env vars in console
- node obs.js uuid returns obs uuid
- node obs.js guid returns obs guid
- node obs.js versiom returns version of obs
can be called with the following obs commands:
- npm run obs
- npm run obs:generate
- npm run env-obs
- npm run env-uuid
- npm run env-guid
- npm run env-version
*/
const fs = require('fs');
const { v5: uuid } = require('uuid');
/*
* declrations > package.json
*/
const { version, repository } = JSON.parse(fs.readFileSync('package.json'));
const args = process.argv.slice(2, process.argv.length);
const action = args[0];
// const a = args[ 1 ];
// const b = args[ 2 ];
if (action === 'guid') {
console.log(`${process.env.GUID}`);
} else if (action === 'setup') {
fs.writeFileSync('.env', '', (err) => {
if (err) {
console.error(err);
} else {
console.log(`Wrote to .env successfully`);
}
});
} else if (action === 'generate') {
const buildGuid = uuid(`${repository.url}`, uuid.URL);
const buildUuid = uuid(version, buildGuid);
const ids = `
VERSION=${version}
GUID=${buildGuid}
UUID=${buildUuid}
`;
console.log(version);
console.log(buildGuid);
console.log(buildUuid);
fs.writeFileSync('.env', ids, (err) => {
if (err) {
console.error(`Could not write env vars: ${err}`);
} else {
console.log(`Wrote env vars to .env`);
}
});
} else if (action === 'uuid') {
console.log(`${process.env.UUID}`);
} else {
console.log(version);
}
process.exit(0);