Skip to content

Commit 7c8acdb

Browse files
committed
build: add new root uuid generation scripts
1 parent 3568342 commit 7c8acdb

File tree

3 files changed

+202
-85
lines changed

3 files changed

+202
-85
lines changed

root.cjs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
{
49+
console.log( `${ process.env.GUID }` );
50+
}
51+
else if ( action === 'setup' )
52+
{
53+
fs.writeFileSync( '.env', '', ( err ) =>
54+
{
55+
if ( err )
56+
{
57+
console.error( err );
58+
}
59+
else
60+
{
61+
console.log( `Wrote to .env successfully` );
62+
}
63+
});
64+
}
65+
else if ( action === 'generate' )
66+
{
67+
const buildGuid = uuidv5( `${ repository.url }`, uuidv5.URL );
68+
const buildUuid = uuidv5( version, buildGuid );
69+
70+
const ids = `
71+
VERSION=${ version }
72+
GUID=${ buildGuid }
73+
UUID=${ buildUuid }
74+
`;
75+
76+
console.log( version );
77+
console.log( buildGuid );
78+
console.log( buildUuid );
79+
80+
fs.writeFileSync( '.env', ids, ( err ) =>
81+
{
82+
if ( err )
83+
{
84+
console.error( `Could not write env vars: ${ err }` );
85+
}
86+
else
87+
{
88+
console.log( `Wrote env vars to .env` );
89+
}
90+
});
91+
}
92+
else if ( action === 'uuid' )
93+
{
94+
console.log( `${ process.env.UUID }` );
95+
}
96+
else
97+
{
98+
console.log( version );
99+
}
100+
101+
process.exit( 0 );

root.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

root.mjs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
{
49+
console.log( `${ process.env.GUID }` );
50+
}
51+
else if ( action === 'setup' )
52+
{
53+
fs.writeFileSync( '.env', '', ( err ) =>
54+
{
55+
if ( err )
56+
{
57+
console.error( err );
58+
}
59+
else
60+
{
61+
console.log( `Wrote to .env successfully` );
62+
}
63+
});
64+
}
65+
else if ( action === 'generate' )
66+
{
67+
const buildGuid = uuidv5( `${ repository.url }`, uuidv5.URL );
68+
const buildUuid = uuidv5( version, buildGuid );
69+
70+
const ids = `
71+
VERSION=${ version }
72+
GUID=${ buildGuid }
73+
UUID=${ buildUuid }
74+
`;
75+
76+
console.log( version );
77+
console.log( buildGuid );
78+
console.log( buildUuid );
79+
80+
fs.writeFileSync( '.env', ids, ( err ) =>
81+
{
82+
if ( err )
83+
{
84+
console.error( `Could not write env vars: ${ err }` );
85+
}
86+
else
87+
{
88+
console.log( `Wrote env vars to .env` );
89+
}
90+
});
91+
}
92+
else if ( action === 'uuid' )
93+
{
94+
console.log( `${ process.env.UUID }` );
95+
}
96+
else
97+
{
98+
console.log( version );
99+
}
100+
101+
process.exit( 0 );

0 commit comments

Comments
 (0)