Skip to content

Commit 639a532

Browse files
committed
build(root): add cjs, mjs
1 parent c223394 commit 639a532

2 files changed

Lines changed: 168 additions & 0 deletions

File tree

root.cjs

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

root.mjs

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

0 commit comments

Comments
 (0)