oneclickpush 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +12 -24
  2. package/cli.js +13 -3
  3. package/index.d.ts +22 -64
  4. package/index.js +18 -34
  5. package/package.json +1 -1
package/README.md CHANGED
@@ -109,7 +109,7 @@ const changes = await deploy({
109
109
  author: 'Deploy Bot <bot@example.com>',
110
110
  force: false,
111
111
  dryRun: false,
112
- logLevel: 'normal'
112
+ verbose: false
113
113
  })
114
114
 
115
115
  if (changes) {
@@ -119,31 +119,19 @@ if (changes) {
119
119
  }
120
120
  ```
121
121
 
122
- The default values are also exported as `DEFAULTS`:
123
-
124
- ```javascript
125
- import { DEFAULTS } from 'oneclickpush'
126
-
127
- console.log(DEFAULTS.branch) // "gh-pages"
128
- ```
129
-
130
122
  ### Options
131
123
 
132
- | Option | Type | Default | Description |
133
- | ---------- | ----------------------------------- | ------------------ | --------------------------------------------------- |
134
- | `dir` | `string` | - (required) | Directory to deploy |
135
- | `exclude` | `string[]` | `["**/.DS_Store"]` | Paths to exclude relative to `dir` |
136
- | `branch` | `string` | `"gh-pages"` | Target git branch |
137
- | `message` | `string` | `"Updates"` | Git commit message |
138
- | `remote` | `string` | `"origin"` | Remote name or repository URL/path to deploy to |
139
- | `author` | `string` | - | Commit author and committer, as `"Name <email>"` |
140
- | `force` | `boolean` | `false` | Force push fresh commit with no previous history |
141
- | `dryRun` | `boolean` | `false` | Return staged changes without committing or pushing |
142
- | `logLevel` | `"silent" \| "normal" \| "verbose"` | `"normal"` | Only `"verbose"` has an effect: logs git commands |
143
-
144
- > [!NOTE]
145
- > The library never prints anything except at `"verbose"`. `"silent"` and `"normal"` only differ in
146
- > the CLI.
124
+ | Name | Type | Default | Description |
125
+ | --------- | ---------- | ------------------ | --------------------------------------------------- |
126
+ | `dir` | `string` | - (required) | Directory to deploy |
127
+ | `exclude` | `string[]` | `["**/.DS_Store"]` | Paths to exclude relative to `dir` |
128
+ | `branch` | `string` | `"gh-pages"` | Target git branch |
129
+ | `message` | `string` | `"Updates"` | Git commit message |
130
+ | `remote` | `string` | `"origin"` | Remote name or repository URL/path to deploy to |
131
+ | `author` | `string` | - | Commit author and committer, as `"Name <email>"` |
132
+ | `force` | `boolean` | `false` | Force push fresh commit with no previous history |
133
+ | `dryRun` | `boolean` | `false` | Return staged changes without committing or pushing |
134
+ | `verbose` | `boolean` | `false` | Logs git commands to stderr |
147
135
 
148
136
  ## How It Works
149
137
 
package/cli.js CHANGED
@@ -1,7 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { parseArgs } from 'node:util'
3
3
  import { readFileSync } from 'node:fs'
4
- import { deploy, DEFAULTS } from './index.js'
4
+ import { deploy } from './index.js'
5
+
6
+ const DEFAULTS = {
7
+ exclude: ['**/.DS_Store'],
8
+ branch: 'gh-pages',
9
+ message: 'Updates',
10
+ remote: 'origin',
11
+ force: false,
12
+ dryRun: false,
13
+ logLevel: 'normal'
14
+ }
5
15
 
6
16
  const HELP = `Usage: oneclickpush <dir> [options]
7
17
 
@@ -84,7 +94,7 @@ if (positionals.length !== 1) {
84
94
  }
85
95
  const dir = positionals[0]
86
96
 
87
- const level = /** @type {import('./index.js').OcpOptionsLogLevel} */ (v['log-level'])
97
+ const level = v['log-level']
88
98
  if (!LEVELS.includes(level)) {
89
99
  console.error(`Invalid --log-level "${level}", expected one of: ${LEVELS.join(', ')}`)
90
100
  process.exit(1)
@@ -100,7 +110,7 @@ const spin =
100
110
  const stop = () => spin && (clearInterval(spin), process.stderr.write('\r \r'))
101
111
 
102
112
  try {
103
- const changes = await deploy({ ...v, dir, logLevel: level, dryRun: v['dry-run'] })
113
+ const changes = await deploy({ ...v, dir, verbose: level === 'verbose', dryRun: v['dry-run'] })
104
114
  stop()
105
115
  if (level !== 'silent') {
106
116
  console.log(
package/index.d.ts CHANGED
@@ -1,68 +1,16 @@
1
- export type OcpOptionsLogLevel = 'silent' | 'normal' | 'verbose'
2
- /** @typedef {'silent' | 'normal' | 'verbose'} OcpOptionsLogLevel */
3
- export declare const DEFAULTS: {
4
- exclude: string[]
5
- branch: string
6
- message: string
7
- remote: string
8
- force: boolean
9
- dryRun: boolean
10
- logLevel: OcpOptionsLogLevel
11
- }
12
- export type OcpOptions = {
13
- /**
14
- * Directory to deploy (required)
15
- */
16
- dir: string
17
- /**
18
- * Paths to leave out, relative to dir (default: `**\/.DS_Store`)
19
- */
20
- exclude?: string[]
21
- /**
22
- * Target branch
23
- */
24
- branch?: string
25
- /**
26
- * Commit message
27
- */
28
- message?: string
29
- /**
30
- * Remote name of the current repo, or a repository URL or path
31
- */
32
- remote?: string
33
- /**
34
- * Commit author and committer as "Name <email>"
35
- */
36
- author?: string
37
- /**
38
- * Force push new commit with no history
39
- */
40
- force?: boolean
41
- /**
42
- * Show what would change, without committing or pushing
43
- */
44
- dryRun?: boolean
45
- /**
46
- * Only "verbose" logs (git commands, to stderr)
47
- */
48
- logLevel?: OcpOptionsLogLevel
49
- }
50
- /**
51
- * @typedef {object} OcpOptions
52
- * @prop {string} dir Directory to deploy (required)
53
- * @prop {string[]} [exclude] Paths to leave out, relative to dir (default: `**\/.DS_Store`)
54
- * @prop {string} [branch="gh-pages"] Target branch
55
- * @prop {string} [message="Updates"] Commit message
56
- * @prop {string} [remote="origin"] Remote name of the current repo, or a repository URL or path
57
- * @prop {string} [author] Commit author and committer as "Name <email>"
58
- * @prop {boolean} [force=false] Force push new commit with no history
59
- * @prop {boolean} [dryRun=false] Show what would change, without committing or pushing
60
- * @prop {OcpOptionsLogLevel} [logLevel="normal"] Only "verbose" logs (git commands, to stderr)
61
- */
62
1
  /**
63
2
  * Replace the contents of a git branch with the contents of a directory.
64
3
  * Returns the staged changes as `git diff --name-status` text or "" if nothing changed.
65
- * @param {OcpOptions} options
4
+ * @param {object} o
5
+ * @param {string} o.dir Directory to deploy (required)
6
+ * @param {string[]} [o.exclude] Paths to leave out, relative to dir (default: `**\/.DS_Store`)
7
+ * @param {string} [o.branch="gh-pages"] Target branch
8
+ * @param {string} [o.message="Updates"] Commit message
9
+ * @param {string} [o.remote="origin"] Remote name of the current repo, or a repository URL or path
10
+ * @param {string} [o.author] Commit author and committer as "Name <email>"
11
+ * @param {boolean} [o.force=false] Force push new commit with no history
12
+ * @param {boolean} [o.dryRun=false] Return staged changes without committing or pushing
13
+ * @param {boolean} [o.verbose=false] Log git commands to stderr
66
14
  * @returns {Promise<string>}
67
15
  */
68
16
  export declare function deploy({
@@ -74,5 +22,15 @@ export declare function deploy({
74
22
  author,
75
23
  force,
76
24
  dryRun,
77
- logLevel
78
- }: OcpOptions): Promise<string>
25
+ verbose
26
+ }: {
27
+ dir: string
28
+ exclude?: string[]
29
+ branch?: string
30
+ message?: string
31
+ remote?: string
32
+ author?: string
33
+ force?: boolean
34
+ dryRun?: boolean
35
+ verbose?: boolean
36
+ }): Promise<string>
package/index.js CHANGED
@@ -4,47 +4,31 @@ import { mkdtemp, rm } from 'node:fs/promises'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { join, resolve } from 'node:path'
6
6
 
7
- /** @typedef {'silent' | 'normal' | 'verbose'} OcpOptionsLogLevel */
8
-
9
- export const DEFAULTS = {
10
- exclude: ['**/.DS_Store'],
11
- branch: 'gh-pages',
12
- message: 'Updates',
13
- remote: 'origin',
14
- force: false,
15
- dryRun: false,
16
- logLevel: /** @type {OcpOptionsLogLevel} */ ('normal')
17
- }
18
-
19
- /**
20
- * @typedef {object} OcpOptions
21
- * @prop {string} dir Directory to deploy (required)
22
- * @prop {string[]} [exclude] Paths to leave out, relative to dir (default: `**\/.DS_Store`)
23
- * @prop {string} [branch="gh-pages"] Target branch
24
- * @prop {string} [message="Updates"] Commit message
25
- * @prop {string} [remote="origin"] Remote name of the current repo, or a repository URL or path
26
- * @prop {string} [author] Commit author and committer as "Name <email>"
27
- * @prop {boolean} [force=false] Force push new commit with no history
28
- * @prop {boolean} [dryRun=false] Show what would change, without committing or pushing
29
- * @prop {OcpOptionsLogLevel} [logLevel="normal"] Only "verbose" logs (git commands, to stderr)
30
- */
31
-
32
7
  /**
33
8
  * Replace the contents of a git branch with the contents of a directory.
34
9
  * Returns the staged changes as `git diff --name-status` text or "" if nothing changed.
35
- * @param {OcpOptions} options
10
+ * @param {object} o
11
+ * @param {string} o.dir Directory to deploy (required)
12
+ * @param {string[]} [o.exclude] Paths to leave out, relative to dir (default: `**\/.DS_Store`)
13
+ * @param {string} [o.branch="gh-pages"] Target branch
14
+ * @param {string} [o.message="Updates"] Commit message
15
+ * @param {string} [o.remote="origin"] Remote name of the current repo, or a repository URL or path
16
+ * @param {string} [o.author] Commit author and committer as "Name <email>"
17
+ * @param {boolean} [o.force=false] Force push new commit with no history
18
+ * @param {boolean} [o.dryRun=false] Return staged changes without committing or pushing
19
+ * @param {boolean} [o.verbose=false] Log git commands to stderr
36
20
  * @returns {Promise<string>}
37
21
  */
38
22
  export async function deploy({
39
23
  dir,
40
- exclude = DEFAULTS.exclude,
41
- branch = DEFAULTS.branch,
42
- message = DEFAULTS.message,
43
- remote = DEFAULTS.remote,
24
+ exclude = ['**/.DS_Store'],
25
+ branch = 'gh-pages',
26
+ message = 'Updates',
27
+ remote = 'origin',
44
28
  author,
45
- force = DEFAULTS.force,
46
- dryRun = DEFAULTS.dryRun,
47
- logLevel = DEFAULTS.logLevel
29
+ force = false,
30
+ dryRun = false,
31
+ verbose = false
48
32
  }) {
49
33
  if (!dir) throw new Error('dir is required')
50
34
  dir = resolve(dir)
@@ -66,7 +50,7 @@ export async function deploy({
66
50
 
67
51
  /** @type {(args: string[], cwd?: string, env?: Record<string, string>) => Promise<string>} */
68
52
  const git = async (args, cwd, env) => {
69
- if (logLevel === 'verbose') console.error(`$ git ${args.join(' ')}`)
53
+ if (verbose) console.error(`$ git ${args.join(' ')}`)
70
54
  const { stdout } = await run('git', args, { cwd, env: { ...process.env, ...env } })
71
55
  return stdout.trim()
72
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneclickpush",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "One-click GitHub Pages deployer",
5
5
  "author": "Jason Lee <jason@zerodevx.com>",
6
6
  "scripts": {