Skip to content

Commit

Permalink
Merge pull request #10 from citizensas/custom-branch-name
Browse files Browse the repository at this point in the history
Custom branch name
  • Loading branch information
citizensas authored Apr 16, 2020
2 parents c5ed8df + 0cf1604 commit 64b1700
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 119 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Just put the command in your package.json scripts section.

| Flag | Default value | Description |
| :---------------- | :------------ | :--------------------------------------------------- |
| `-b, --branch` | `origin` | Specify a custom branch name to be pushed to your repository |
| `-r, --remote` | `origin` | Git remote name to use |
| `-p, --protocole` | `git+ssh` | Git protocol (i.e. git+ssh, https) |
| `--token` | | Git user token for remote authentication |
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/citizensas/generate-preview.git"
"url": "https://github.com/citizensas/generate-preview.git"
},
"author": "Sassoun Derderian",
"bugs": {
Expand All @@ -26,26 +26,26 @@
"homepage": "https://github.com/citizensas/generate-preview#readme",
"license": "MIT",
"dependencies": {
"commander": "4.1.0",
"commander": "^5.0.0",
"git-url-parse": "11.1.2",
"rimraf": "3.0.0",
"simple-git": "1.129.0",
"tar": "5.0.5",
"tempy": "0.3.0",
"rimraf": "^3.0.2",
"simple-git": "^1.132.0",
"tar": "^6.0.1",
"tempy": "^0.3.0",
"winston": "3.2.1"
},
"devDependencies": {
"@types/git-url-parse": "^9.0.0",
"@types/node": "^13.1.6",
"@types/rimraf": "^2.0.2",
"@types/node": "^13.11.1",
"@types/rimraf": "^3.0.0",
"@types/tar": "^4.0.3",
"husky": "^4.0.6",
"prettier": "^1.15.2",
"prettier": "^2.0.4",
"pretty-quick": "^2.0.1",
"typescript": "^3.6.4"
},
"engines": {
"node": ">=8",
"npm": ">=5.2"
"node": ">=10",
"npm": ">=5.6.0"
}
}
4 changes: 2 additions & 2 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {logger} from './logger'
export function cleanup(pathsToRemove: string[]) {
logger.info('Cleaning up')
const promises: Array<Promise<void>> = []
pathsToRemove.forEach(path => {
pathsToRemove.forEach((path) => {
logger.verbose(`Removing ${path}`)
promises.push(
new Promise((resolve, reject) => {
rimraf(path, err => {
rimraf(path, (err) => {
if (err) {
reject(err)
} else {
Expand Down
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
branchName?: string
}

let flags: IFlags
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const REMOTE_URL_TYPES = {
FTP: 'ftp',
FTPS: 'ftps',
HTTPS: 'https',
HTTP: 'http'
HTTP: 'http',
} as const
6 changes: 3 additions & 3 deletions src/generate-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function generatePreview(flags: IFlags) {
return {
pathsToRemove: [TMP_DIR, packedFilePath],
remoteUrl: remoteUrl,
distBranchName: distBranchName
distBranchName: distBranchName,
}
})
.catch((err: unknown) =>
Expand All @@ -33,7 +33,7 @@ export function generatePreview(flags: IFlags) {
})
)
})
.then(res =>
.then((res) =>
cleanup(res.pathsToRemove).then(() => {
logger.info(
`Now you can install generated URL in you module using Yarn or NPM. Just run the following command.`
Expand All @@ -43,7 +43,7 @@ export function generatePreview(flags: IFlags) {
console.log(`yarn add ${res.remoteUrl}#${res.distBranchName}`)
})
)
.catch(err => {
.catch((err) => {
logger.error(err)
process.exit(1)
})
Expand Down
10 changes: 8 additions & 2 deletions src/getBranchName.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import * as gitP from 'simple-git/promise'
import {MODULE_DIR} from './constants'
import {logger} from './logger'
import {getFlags} from './cliFlags'

const moduleGit = gitP(MODULE_DIR)

export function getBranchName() {
const {branchName} = getFlags()
logger.verbose('Getting branch name')
if (branchName) {
logger.info(`Branch name: ${branchName}`)
return Promise.resolve(branchName)
}
return moduleGit
.branchLocal()
.then(branchSummary => branchSummary.current)
.then(branchName => {
.then((branchSummary) => branchSummary.current)
.then((branchName) => {
logger.info(`Branch name: ${branchName}-dist`)
return branchName + '-dist'
})
Expand Down
6 changes: 3 additions & 3 deletions src/getRemoteUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export function getRemoteUrl() {
logger.verbose('Getting remote url')
return moduleGit
.getRemotes(true)
.then(remotes => {
const remoteFound = remotes.find(remote => remote.name === remoteName)
.then((remotes) => {
const remoteFound = remotes.find((remote) => remote.name === remoteName)
if (remoteFound) {
return remoteFound
}
throw `Remote "${remoteName}" not found.`
})
.then(remote => {
.then((remote) => {
const parsedUrl = GitUrlParse(remote.refs.fetch)
let remoteUrl
if (
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const pkg = require('../package.json')
program
.version(pkg.version)
.name('npx generate-preview')
.option('-b, --branch [name]', 'specify a custom branch name to be pushed to your repository')
.option('-r, --remote [name]', 'git remote name to use', REMOTE_NAME)
.option('-p, --protocol [protocol]', 'git protocol (i.e. git+ssh, https)', REMOTE_URL_TYPES.GIT_SSH)
.option('--verbose', 'prints higher level of logs')
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,
branchName: program.branch,
})
2 changes: 1 addition & 1 deletion src/initializeGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {logger} from './logger'

function createTempDirectory(dir: string) {
return new Promise<void>((resolve, reject) => {
fs.mkdir(dir, {recursive: true}, err => {
fs.mkdir(dir, {recursive: true}, (err) => {
if (err) {
reject(err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function initLogger(level: TLoglevels) {
logger = createLogger({
level: level,
format: format.cli(),
transports: [new transports.Console()]
transports: [new transports.Console()],
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/npmPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {logger} from './logger'
export function npmPack() {
logger.verbose(`Packing ${PACKAGE_JSON.name}`)
return new Promise<string>((resolve, reject) =>
child_process.exec(`npm_config_loglevel=silent npm pack`, {cwd: MODULE_DIR, maxBuffer: 1024 * 500}, function(
child_process.exec(`npm_config_loglevel=silent npm pack`, {cwd: MODULE_DIR, maxBuffer: 1024 * 500}, function (
err,
stdout
) {
Expand Down
4 changes: 2 additions & 2 deletions src/unpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function unpack(packedFilename: string) {
return tar
.x({
file: packedFilename,
cwd: TMP_DIR
cwd: TMP_DIR,
})
.then(result => {
.then((result) => {
logger.verbose(`Package "${PACKAGE_JSON.name}" unpacked in ${TMP_PACKAGE_DIR}`)
return result
})
Expand Down
Loading

0 comments on commit 64b1700

Please sign in to comment.