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