oneclickpush 0.3.0 → 0.4.1
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.
- package/README.md +12 -24
- package/cli.js +23 -13
- package/index.d.ts +22 -64
- package/index.js +18 -34
- package/package.json +2 -2
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
|
-
|
|
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
|
-
|
|
|
133
|
-
|
|
|
134
|
-
| `dir`
|
|
135
|
-
| `exclude`
|
|
136
|
-
| `branch`
|
|
137
|
-
| `message`
|
|
138
|
-
| `remote`
|
|
139
|
-
| `author`
|
|
140
|
-
| `force`
|
|
141
|
-
| `dryRun`
|
|
142
|
-
| `
|
|
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
|
|
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
|
|
|
@@ -37,6 +47,12 @@ commands and full errors.`
|
|
|
37
47
|
|
|
38
48
|
const LEVELS = ['silent', 'normal', 'verbose']
|
|
39
49
|
|
|
50
|
+
/** @param {string} msg @returns {never} */
|
|
51
|
+
const fail = (msg) => {
|
|
52
|
+
console.error(`${msg}\nTry "oneclickpush --help" for usage`)
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
|
|
40
56
|
const { values: v, positionals } = (() => {
|
|
41
57
|
try {
|
|
42
58
|
return parseArgs({
|
|
@@ -57,9 +73,7 @@ const { values: v, positionals } = (() => {
|
|
|
57
73
|
} catch (/** @type {any} */ e) {
|
|
58
74
|
if (!e.code?.startsWith('ERR_PARSE_ARGS_')) throw e
|
|
59
75
|
// Keep only the first sentence, Node appends a long "-- " hint to some messages
|
|
60
|
-
|
|
61
|
-
console.error(`${msg}, run "oneclickpush --help" for usage`)
|
|
62
|
-
process.exit(1)
|
|
76
|
+
fail(e.message.split('. ')[0].replace(/\.$/, ''))
|
|
63
77
|
}
|
|
64
78
|
})()
|
|
65
79
|
|
|
@@ -75,19 +89,15 @@ if (v.version) {
|
|
|
75
89
|
}
|
|
76
90
|
|
|
77
91
|
if (positionals.length !== 1) {
|
|
78
|
-
|
|
79
|
-
positionals.length === 0
|
|
80
|
-
? 'Missing required argument <dir>, run "oneclickpush --help" for usage'
|
|
81
|
-
: 'Expected exactly one directory, run "oneclickpush --help" for usage'
|
|
92
|
+
fail(
|
|
93
|
+
positionals.length === 0 ? 'Missing required argument <dir>' : 'Expected exactly one directory'
|
|
82
94
|
)
|
|
83
|
-
process.exit(1)
|
|
84
95
|
}
|
|
85
96
|
const dir = positionals[0]
|
|
86
97
|
|
|
87
|
-
const level =
|
|
98
|
+
const level = v['log-level']
|
|
88
99
|
if (!LEVELS.includes(level)) {
|
|
89
|
-
|
|
90
|
-
process.exit(1)
|
|
100
|
+
fail(`Invalid --log-level "${level}", expected one of: ${LEVELS.join(', ')}`)
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
// Dead simple spinner (normal level, TTY only)
|
|
@@ -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,
|
|
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 {
|
|
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
|
-
|
|
78
|
-
}:
|
|
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 {
|
|
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 =
|
|
41
|
-
branch =
|
|
42
|
-
message =
|
|
43
|
-
remote =
|
|
24
|
+
exclude = ['**/.DS_Store'],
|
|
25
|
+
branch = 'gh-pages',
|
|
26
|
+
message = 'Updates',
|
|
27
|
+
remote = 'origin',
|
|
44
28
|
author,
|
|
45
|
-
force =
|
|
46
|
-
dryRun =
|
|
47
|
-
|
|
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 (
|
|
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
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "One-click GitHub Pages deployer",
|
|
5
5
|
"author": "Jason Lee <jason@zerodevx.com>",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@eslint/js": "^10.0.1",
|
|
14
|
-
"eslint": "^10.
|
|
14
|
+
"eslint": "^10.13.0",
|
|
15
15
|
"globals": "^17.13.0",
|
|
16
16
|
"prettier": "^3.9.10",
|
|
17
17
|
"typescript": "^7.0.2"
|