Skip to content

Commit

Permalink
Merge pull request #24 from IceBreakerG/output.path
Browse files Browse the repository at this point in the history
Added support for the base dist folder.
  • Loading branch information
IceBreakerG authored May 17, 2021
2 parents 1d9845d + d5d3baa commit be02c0f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
46 changes: 12 additions & 34 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets",
"src/version.json"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets", "src/version.json"],
"styles": ["src/styles.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -88,27 +82,16 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
"tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
Expand Down Expand Up @@ -136,13 +119,13 @@
"options": {
"tsConfig": "projects/version-check/tsconfig.lib.json",
"project": "projects/version-check/ng-package.json"
}
, "configurations": {
},
"configurations": {
"production": {
"tsConfig": "projects/version-check/tsconfig.lib.prod.json"
}
}
},
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
Expand All @@ -154,17 +137,12 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/version-check/tsconfig.lib.json",
"projects/version-check/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"tsConfig": ["projects/version-check/tsconfig.lib.json", "projects/version-check/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "ngx-version-check"
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build": "ng build --prod",
"build-dev": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"dev": "ng serve --host=0.0.0.0 --disable-host-check",
"create-package": "npm run build-library && npm run package-library",
"create-package-unix": "npm run build-library-unix && npm run package-library",
"build-library": "ng build version-check --prod",
"build-library-unix": "ng build version-check --prod",
"postbuild": "node projects/version-check/src/build/post-build.js",
"postbuild-library": "xcopy /i /y /z projects\\version-check\\src\\build\\* dist\\version-check\\build && xcopy /i /y /z projects\\version-check\\src\\assets\\* dist\\version-check\\assets",
"postbuild-library-unix": "cp -R projects/version-check/src/build dist/version-check/build && cp -R projects/version-check/src/assets dist/version-check/assets",
"package-library": "cd dist/version-check && npm pack"
Expand Down
2 changes: 1 addition & 1 deletion projects/version-check/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-version-check",
"version": "1.0.4",
"version": "1.0.5",
"author": {
"name": "Eric Garrison"
},
Expand Down
20 changes: 16 additions & 4 deletions projects/version-check/src/build/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ const path = require('path')
const fs = require('fs')
const util = require('util')

console.log('Starting post build [ngx-version-check]\n')

process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`)
})

let project = process.argv[2]
let basePath = path.join(__dirname, `../../../dist/${project}/`)

console.log(`\nProject: ${project}`)

if (!project) {
console.log('Project name parameter is undefined. Using the /dist folder')
}

let outputDirectory = project ? `../../../dist/${project}/` : `../../../dist/`
let basePath = path.join(__dirname, outputDirectory)

console.log(`Base Path: ${basePath}`)

// Get application version from package.json
Expand All @@ -27,7 +36,7 @@ const readDir = util.promisify(fs.readdir)
const writeFile = util.promisify(fs.writeFile)
const readFile = util.promisify(fs.readFile)

console.log('\nRunning post-build tasks')
console.log('\nRunning post-build tasks [ngx-version-check]')

// our version.json will be in the dist folder
const versionFilePath = `${basePath}version.json`
Expand Down Expand Up @@ -59,13 +68,15 @@ if (versionParts.length > 3) {

let appVersion = `${year}.${month}.${day}${revision}`

console.log(`Current Version From File: ${versionFromFile}`)
// This currently doesn't make sense. Need to re-evaluate the use case for this
// console.log(`Current Version From File: ${versionFromFile}`)

if (versionFromFile === appVersion) {
appVersion = appVersion.concat('.1')
}

console.log(`Changed Version To: ${appVersion}`)
// This is currently not needed based on the current version, since it's currently unavailable
// console.log(`Changed Version To: ${appVersion}`)

// read the dist folder files and find the one we're looking for
readDir(`${basePath}`)
Expand Down Expand Up @@ -102,6 +113,7 @@ readDir(`${basePath}`)
return readFile(mainFilepath, 'utf8').then(mainFileData => {
console.log(`Application Version: ${appVersion}`)
console.log(`Application Hash: ${mainHash}`)
console.log('End post build [ngx-version-check]\n')

const replacedFile = mainFileData
.replace('{{POST_BUILD_ENTERS_HASH_HERE}}', mainHash)
Expand Down

0 comments on commit be02c0f

Please sign in to comment.