-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from CentreForDigitalHumanities/feature/fronte…
…nd-configuration Feature/frontend configuration
- Loading branch information
Showing
26 changed files
with
85 additions
and
478 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
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
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 |
---|---|---|
|
@@ -6,64 +6,15 @@ const { exec } = require('child_process'); | |
|
||
console.log(colors.cyan('\nRunning pre-build tasks')); | ||
|
||
async function getHash() { | ||
return new Promise((resolve, reject) => { | ||
exec('git rev-parse HEAD', (error, stdout, stderr) => { | ||
if (error) { | ||
reject(`error: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
reject(`stderr: ${stderr}`); | ||
return; | ||
} | ||
|
||
resolve(stdout.trim()); | ||
}); | ||
}); | ||
} | ||
|
||
async function getRemoteUrl() { | ||
return new Promise((resolve, reject) => { | ||
exec('git config --get remote.origin.url', (error, stdout, stderr) => { | ||
if (error) { | ||
reject(`error: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
reject(`stderr: ${stderr}`); | ||
return; | ||
} | ||
|
||
// format is either: | ||
// [email protected]:UUDigitalHumanitieslab/lettercraft.git | ||
// or https://github.com/UUDigitalHumanitieslab/lettercraft.git | ||
// or https://USERNAME:[email protected]/UUDigitalHumanitieslab/lettercraft.git/ | ||
|
||
// remove https:// | ||
let sourceUrl = stdout.replace(/^https?:\/\//, '').trim(); | ||
// remove git@ or USERNAME:SECRET@ | ||
sourceUrl = sourceUrl.replace(/^[^@]+@/, '').trim(); | ||
// replace : with / | ||
sourceUrl = sourceUrl.replace(':', '/'); | ||
// remove .git/ | ||
sourceUrl = sourceUrl.replace(/\.git\/?\n?$/, ''); | ||
resolve('https://' + sourceUrl); | ||
}); | ||
}); | ||
} | ||
|
||
Promise.all([getHash(), getRemoteUrl()]).then(([hash, remoteUrl]) => { | ||
writeVersion(hash, remoteUrl); | ||
}).catch((error) => { | ||
try { | ||
writeVersion(); | ||
} catch { | ||
console.log(`${colors.red('Could not update version: ')} ${error}`); | ||
}); | ||
} | ||
|
||
function writeVersion(hash, remoteUrl) { | ||
function writeVersion() { | ||
const versionFilePath = path.join(__dirname + '/../src/environments/version.ts'); | ||
const src = `export const version = '${appVersion}'; | ||
export const buildTime = '${new Date()}'; | ||
export const sourceUrl = '${remoteUrl}/tree/${hash}'; | ||
`; | ||
|
||
// ensure version module pulls value from package.json | ||
|
@@ -74,6 +25,5 @@ export const sourceUrl = '${remoteUrl}/tree/${hash}'; | |
|
||
console.log(colors.green(`Updating application version ${colors.yellow(appVersion)}`)); | ||
console.log(`${colors.green('Writing version module to ')}${colors.yellow(versionFilePath)}\n`); | ||
console.log(src); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.