-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b17ea12
commit 0eba61e
Showing
1 changed file
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,85 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
// Execute: | ||
// npx --quiet env-cmd --no-override node gistr.js version | ||
// npx --quiet env-cmd --no-override node gistr.js guid | ||
// npx --quiet env-cmd --no-override node gistr.js uuid | ||
/* | ||
This script handles the following: | ||
- read package.json | ||
- create .env file | ||
- return uuid, guid, version | ||
const args = process.argv.slice( 2, process.argv.length ); | ||
const action = args[ 0 ]; | ||
const a = args[ 1 ]; | ||
const b = args[ 2 ]; | ||
can be called with the following external commands: | ||
- node gistr.js | ||
- node gistr.js generate | ||
- node gistr.js uuid | ||
- node gistr.js guid | ||
- node gistr.js versiom | ||
if ( action === "guid" ) | ||
{ | ||
console.log( `${ process.env.GUID }` ); | ||
} | ||
else if( action === "uuid" ) | ||
{ | ||
console.log( `${ process.env.UUID }` ); | ||
} | ||
else | ||
{ | ||
console.log( require( './package.json' ).version ); | ||
can be called with the following KeeWeb commands: | ||
- npm run gistr | ||
- npm run gistr:generate | ||
- npm run env-gistr | ||
- 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 ); | ||
process.exit(0); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|