Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: logFinalVersion cli flag added which logs the final version int… #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cliFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IFlags {
remoteName: string
protocol: string
token: string
logFinalVersion?: boolean
}

let flags: IFlags
Expand Down
31 changes: 29 additions & 2 deletions src/generate-preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MODULE_DIR, TMP_DIR} from './constants'

import * as path from 'path'
import * as fs from 'fs'

import {getBranchName} from './getBranchName'
import {getRemoteUrl} from './getRemoteUrl'
Expand All @@ -12,6 +13,27 @@ import {cleanup} from './cleanup'
import {IFlags, setFlags} from './cliFlags'
import {logger} from './logger'

const logFileName = 'generate-preview.log'

const writeIntoLogFile = (content: string) => {
const path = logFileName
return new Promise((resolve, reject) => {
fs.open(path, 'w+', function(err) {
if (err) {
reject(err)
} else {
fs.writeFile(path, content, function(err) {
if (err) {
reject(err)
} else {
resolve()
}
})
}
})
})
}

export function generatePreview(flags: IFlags) {
setFlags(flags)
Promise.all([getBranchName(), getRemoteUrl(), npmPack()])
Expand All @@ -38,9 +60,14 @@ export function generatePreview(flags: IFlags) {
logger.info(
`Now you can install generated URL in you module using Yarn or NPM. Just run the following command.`
)
console.log(`npm install ${res.remoteUrl}#${res.distBranchName}`)
const version = `${res.remoteUrl}#${res.distBranchName}`
console.log(`npm install ${version}`)
console.log(' OR ')
console.log(`yarn add ${res.remoteUrl}#${res.distBranchName}`)
console.log(`yarn add ${version}`)
if (flags.logFinalVersion) {
console.log(`Logging the final version into ${logFileName}...`)
return writeIntoLogFile(version)
}
})
)
.catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ program
.option('-p, --protocol [protocol]', 'git protocol (i.e. git+ssh, https)', REMOTE_URL_TYPES.GIT_SSH)
.option('--verbose', 'prints higher level of logs')
.option('--token [token]', 'git user token for remote authentication', '')
.option('--logFinalVersion', 'whether should log the final version into the generate-preview.log file')

program.parse(process.argv)

Expand All @@ -22,5 +23,6 @@ logger.info(`Running generate-preview with version ${pkg.version}`)
generatePreview({
remoteName: program.remote,
protocol: program.protocol,
token: program.token
token: program.token,
logFinalVersion: program.logFinalVersion
})