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: add pattern option #278

Merged
merged 3 commits into from
Dec 8, 2024
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ or even shorter if default settings are used:
| `pullTagsBranch` | Target branch for tags fetching hook. If '' empty string, skips this action | `globalConfig.branch` \|\| `master` |
| `dotfiles` | gh-pages [dotfiles](https://github.com/tschaub/gh-pages#optionsdotfiles) option | `false` |
| `add` | gh-pages [add](https://github.com/tschaub/gh-pages#optionsadd) option | `false` |
| `pattern` | gh-pages [src](https://github.com/tschaub/gh-pages#optionssrc) option | `**/*` |

## License
[MIT](./LICENSE)
7 changes: 6 additions & 1 deletion src/main/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DEFAULT_DST,
DEFAULT_ENTERPRISE,
DEFAULT_MSG,
DEFAULT_PATTERN,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
PLUGIN_PATH} from './defaults'
Expand All @@ -27,7 +28,8 @@ export {
DEFAULT_DST,
DEFAULT_ENTERPRISE,
PLUGIN_PATH,
DEFAULT_PULL_TAGS_BRANCH
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_PATTERN,
} from './defaults'

const gitUrlParse = catchToSmth(gitParse, {})
Expand Down Expand Up @@ -132,6 +134,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
msg = DEFAULT_MSG,
src = DEFAULT_SRC,
dst = DEFAULT_DST,
pattern = DEFAULT_PATTERN,
add,
dotfiles
} = opts
Expand All @@ -149,6 +152,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
debug('ciBranch= %s', ciBranch)
debug('docsBranch= %s', docsBranch)
debug('pullTagsBranch= %s', pullTagsBranch)
debug('pattern = %s', pattern)

return {
src,
Expand All @@ -162,6 +166,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
token,
add,
dotfiles,
pattern,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/ts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const DEFAULT_DST = '.'
export const DEFAULT_MSG = 'docs updated <%= nextRelease.gitTag %>'
export const DEFAULT_ENTERPRISE = false
export const DEFAULT_PULL_TAGS_BRANCH = 'master'
export const DEFAULT_PATTERN = '**/*'
5 changes: 3 additions & 2 deletions src/main/ts/ghpages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ export const pullTags = (opts: IPushOpts): Promise<any> => {
* @private
*/
export const pushPages = (opts: IPushOpts) => new Promise((resolve, reject) => {
const { src, logger , repo, docsBranch, dst, message, add, dotfiles} = opts
const { src, logger , repo, docsBranch, dst, message, add, dotfiles, pattern } = opts
const ghpagesOpts: PublishOptions = {
repo,
branch: docsBranch,
dest: dst,
message,
add,
dotfiles,
src: pattern,
}

ghpagePublish(src, ghpagesOpts, (err?: any) => {
Expand All @@ -56,7 +57,7 @@ export const pushPages = (opts: IPushOpts) => new Promise((resolve, reject) => {
reject(err)

} else {
logger.log(`Docs published successfully, branch=${ghpagesOpts.branch}, src=${src}, dst=${ghpagesOpts.dest}`)
logger.log(`Docs published successfully, branch=${ghpagesOpts.branch}, src=${src}, pattern=${ghpagesOpts.src}, dst=${ghpagesOpts.dest}`)
resolve(OK)
}
})
Expand Down
1 change: 1 addition & 0 deletions src/main/ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IGhpagesPluginConfig {
enterprise?: boolean,
dotfiles?: boolean
add?: boolean
pattern?: string,
}

export interface IPushOpts extends IGhpagesPluginConfig {
Expand Down
13 changes: 9 additions & 4 deletions src/test/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DEFAULT_MSG,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
DEFAULT_PATTERN,
// getRepo,
extractRepoDomain,
extractRepoName,
Expand Down Expand Up @@ -141,7 +142,8 @@ describe('config', () => {
msg: 'doc update',
token,
repo: `https://${token}@enterprise.com/org/repo.git`,
pullTagsBranch: 'dev'
pullTagsBranch: 'dev',
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -188,7 +190,8 @@ describe('config', () => {
msg: 'doc update',
token,
repo: `https://${token}@enterprise.com/org/repo.git`,
pullTagsBranch: 'foo'
pullTagsBranch: 'foo',
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -227,7 +230,8 @@ describe('config', () => {
src: DEFAULT_SRC,
token,
repo: repositoryUrl,
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH,
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -328,7 +332,8 @@ describe('config', () => {
src: 'dist/web',
token: 'secure',
repo: `https://[email protected]/foo/bar.git`,
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH,
pattern: DEFAULT_PATTERN,
})
})
})
Expand Down
12 changes: 8 additions & 4 deletions src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DEFAULT_MSG,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
DEFAULT_PATTERN,
PLUGIN_PATH
} from '../../main/ts'
import { getUrlFromPackage } from '../../main/ts/config'
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('index', () => {
msg: DEFAULT_MSG,
dst: DEFAULT_DST,
src: DEFAULT_SRC,
pattern: DEFAULT_PATTERN,
enterprise: DEFAULT_ENTERPRISE,
repo: await getRepoUrl(pluginConfig, context, DEFAULT_ENTERPRISE),
token,
Expand Down Expand Up @@ -203,7 +205,8 @@ describe('index', () => {
repo: await getRepoUrl(pluginConfig, context, false),
branch: 'doc-branch',
message: 'docs updated v{{=it.nextRelease.gitTag}}',
dest: 'root'
dest: 'root',
src: DEFAULT_PATTERN,
}
const execaOpts = {
cwd,
Expand All @@ -228,7 +231,7 @@ describe('index', () => {
)

expect(log).toHaveBeenCalledWith('Publishing docs via gh-pages')
expect(log).toHaveBeenCalledWith('Docs published successfully, branch=doc-branch, src=docs, dst=root')
expect(log).toHaveBeenCalledWith(`Docs published successfully, branch=doc-branch, src=docs, pattern=${DEFAULT_PATTERN}, dst=root`)

expect(ghpagesPublish).toHaveBeenCalledWith(DEFAULT_SRC, expectedOpts, expect.any(Function))
expect(res).toBe(OK)
Expand All @@ -252,7 +255,7 @@ describe('index', () => {
await publish(pluginConfig, context)

expect(log).toHaveBeenCalledWith('Publishing docs via gh-pages')
expect(log).toHaveBeenCalledWith('Docs published successfully, branch=gh-pages, src=docs, dst=.')
expect(log).toHaveBeenCalledWith(`Docs published successfully, branch=gh-pages, src=docs, pattern=${DEFAULT_PATTERN}, dst=.`)
})

it('throws rejection on gh-pages fail', async () => {
Expand All @@ -275,7 +278,8 @@ describe('index', () => {
repo: await getRepoUrl(pluginConfig, context, false),
branch: DEFAULT_BRANCH,
message: DEFAULT_MSG,
dest: DEFAULT_DST
dest: DEFAULT_DST,
src: DEFAULT_PATTERN,
}
const expected = {
src: DOCS_ERR,
Expand Down
Loading