secrez 1.0.3 → 1.1.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.
- package/README.md +17 -53
- package/package.json +71 -71
- package/src/commands/Import.js +2 -2
- package/src/commands/Totp.js +20 -3
- package/src/utils/HelpProto.js +2 -2
- package/LICENSE +0 -21
- package/coverage.report +0 -328
- package/pnpm-lock.yaml +0 -3381
- package/src/commands/Git.js +0 -184
package/src/commands/Git.js
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
const {execSync} = require('child_process')
|
2
|
-
const {execAsync} = require('@secrez/utils')
|
3
|
-
const chalk = require('chalk')
|
4
|
-
const path = require('path')
|
5
|
-
const fs = require('fs-extra')
|
6
|
-
const _ = require('lodash')
|
7
|
-
|
8
|
-
class Git extends require('../Command') {
|
9
|
-
|
10
|
-
setHelpAndCompletion() {
|
11
|
-
this.cliConfig.completion.git = {
|
12
|
-
_self: this
|
13
|
-
}
|
14
|
-
this.cliConfig.completion.help.git = true
|
15
|
-
this.optionDefinitions = [
|
16
|
-
{
|
17
|
-
name: 'help',
|
18
|
-
alias: 'h',
|
19
|
-
type: Boolean
|
20
|
-
},
|
21
|
-
{
|
22
|
-
name: 'push',
|
23
|
-
alias: 'p',
|
24
|
-
type: Boolean
|
25
|
-
},
|
26
|
-
{
|
27
|
-
name: 'pull',
|
28
|
-
alias: 'P',
|
29
|
-
type: Boolean
|
30
|
-
},
|
31
|
-
{
|
32
|
-
name: 'info',
|
33
|
-
alias: 'i',
|
34
|
-
type: Boolean
|
35
|
-
},
|
36
|
-
{
|
37
|
-
name: 'message',
|
38
|
-
type: String
|
39
|
-
},
|
40
|
-
{
|
41
|
-
name: 'init',
|
42
|
-
type: Boolean
|
43
|
-
},
|
44
|
-
{
|
45
|
-
name: 'remote-url',
|
46
|
-
type: String
|
47
|
-
},
|
48
|
-
{
|
49
|
-
name: 'main-branch',
|
50
|
-
type: String
|
51
|
-
}
|
52
|
-
]
|
53
|
-
}
|
54
|
-
|
55
|
-
help() {
|
56
|
-
return {
|
57
|
-
description: ['Minimalistic git repo managements.',
|
58
|
-
'For missing commands use "shell" instead, like:',
|
59
|
-
'shell "cd ~/.secrez && git history"'],
|
60
|
-
examples: [
|
61
|
-
['git -i', 'get info about the repo, like the remote url'],
|
62
|
-
['git -p', 'adds all changes and commits. If there is a remote origin, it also pushes to the remote repo'],
|
63
|
-
['git -p --message "before migrating the db"', 'adds a message to the push; in general, it is better to not specify messages, but in some special case, it can be useful to add a message'],
|
64
|
-
['git --init', 'initiates a git repo using "master" as main branch'],
|
65
|
-
['git --init --main-branch main', 'initiates a git repo using "main" as main branch'],
|
66
|
-
['git --main-branch main', 'sets the main branch'],
|
67
|
-
['git --remote-url git@github.com:sullof/priv-repo.git', 'sets the origin of the local repo'],
|
68
|
-
['git -P', '(notice the uppercase P) pulls from origin and merges']
|
69
|
-
]
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
async git(options) {
|
74
|
-
let result = await execAsync('which', __dirname, ['git'])
|
75
|
-
if (!result.message || result.code === 1) {
|
76
|
-
throw new Error('Git not installed')
|
77
|
-
}
|
78
|
-
let containerPath = this.secrez.config.container
|
79
|
-
let repoExists = await fs.pathExists(path.join(containerPath, '.git'))
|
80
|
-
|
81
|
-
if (options.init) {
|
82
|
-
if (repoExists) {
|
83
|
-
throw new Error('Repo already initiated.')
|
84
|
-
}
|
85
|
-
let res = (await execAsync('git', containerPath, ['init'])).message
|
86
|
-
await execAsync('git', containerPath, ['add', '-A'])
|
87
|
-
res += '\n' + (await execAsync('git', containerPath, ['commit', '-m', 'first-commit'])).message
|
88
|
-
await execAsync('git', containerPath, ['branch', '-M', options.mainBranch || 'master'])
|
89
|
-
return res
|
90
|
-
}
|
91
|
-
|
92
|
-
if (options.mainBranch) {
|
93
|
-
await execAsync('git', containerPath, ['branch', '-M', options.mainBranch])
|
94
|
-
return `New main branch: ${options.mainBranch}`
|
95
|
-
}
|
96
|
-
|
97
|
-
if (!repoExists) {
|
98
|
-
throw new Error('Repo not found. Run "git --init" to initiate the repo')
|
99
|
-
}
|
100
|
-
|
101
|
-
result = await execAsync('git', containerPath, ['remote', '-v'])
|
102
|
-
let remoteUrl
|
103
|
-
if (result.message && result.code !== 1) {
|
104
|
-
for (let line of result.message.split('\n')) {
|
105
|
-
if (/^origin/.test(line) && /\(push\)/.test(line)) {
|
106
|
-
remoteUrl = line.replace(/origin\s+(.+)\s+\(push.+/, '$1')
|
107
|
-
break
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
if (options.remoteUrl) {
|
112
|
-
if (remoteUrl) {
|
113
|
-
await execAsync('git', containerPath, ['remote','remove','origin'])
|
114
|
-
}
|
115
|
-
await execAsync('git', containerPath, ['remote', 'add', 'origin', options.remoteUrl])
|
116
|
-
return `Remote url: ${options.remoteUrl}`
|
117
|
-
}
|
118
|
-
|
119
|
-
result = await execAsync('git', containerPath, ['rev-parse', '--abbrev-ref', 'HEAD'])
|
120
|
-
if (!result.message || result.code === 1) {
|
121
|
-
throw new Error('No active branch found')
|
122
|
-
}
|
123
|
-
let branch = _.trim(result.message)
|
124
|
-
|
125
|
-
result = await execAsync('git', containerPath, ['diff', '--name-only'])
|
126
|
-
let count = 0
|
127
|
-
if (_.trim(result.message)) {
|
128
|
-
count = _.trim(result.message).split('\n').length
|
129
|
-
}
|
130
|
-
|
131
|
-
this.internalFs.cleanPreviousRootEntry()
|
132
|
-
|
133
|
-
if (!remoteUrl) {
|
134
|
-
if (options.info) {
|
135
|
-
return `
|
136
|
-
Current branch: ${chalk.bold(branch)}
|
137
|
-
Number of changed files: ${chalk.bold(count)}
|
138
|
-
`
|
139
|
-
} else if (options.push) {
|
140
|
-
await execAsync('git', containerPath, ['add', '-A'])
|
141
|
-
return (await execAsync('git', containerPath, ['commit', '-m', options.message || 'another-commit'])).message
|
142
|
-
} else {
|
143
|
-
throw new Error('Wrong parameters')
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
result = await execAsync('git', containerPath, ['diff', `origin/${branch}`, '--name-only'])
|
148
|
-
count = 0
|
149
|
-
if (_.trim(result.message)) {
|
150
|
-
count = _.trim(result.message).split('\n').length
|
151
|
-
}
|
152
|
-
|
153
|
-
if (options.info) {
|
154
|
-
return `Current branch: ${chalk.bold(branch)}
|
155
|
-
Remote url: ${chalk.bold(remoteUrl)}
|
156
|
-
Number of changed files: ${chalk.bold(count)}`
|
157
|
-
}
|
158
|
-
|
159
|
-
if (options.pull || options.push) {
|
160
|
-
await execAsync('git', containerPath, ['add', '-A'])
|
161
|
-
return `${(await execAsync('git', containerPath, ['commit', '-m', options.message || 'another-commit'])).message}
|
162
|
-
${execSync(`cd ${containerPath} && git ${options.pull ? 'pull' : 'push'} origin ${branch}`).toString()}
|
163
|
-
` }
|
164
|
-
|
165
|
-
throw new Error('Wrong parameters')
|
166
|
-
}
|
167
|
-
|
168
|
-
async exec(options = {}) {
|
169
|
-
if (options.help) {
|
170
|
-
return this.showHelp()
|
171
|
-
}
|
172
|
-
try {
|
173
|
-
this.validate(options)
|
174
|
-
this.Logger.reset(await this.git(options))
|
175
|
-
} catch (e) {
|
176
|
-
this.Logger.red(e.message)
|
177
|
-
}
|
178
|
-
await this.prompt.run()
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
|
-
module.exports = Git
|
183
|
-
|
184
|
-
|