one-way-git-sync 3.1.2 → 3.1.3
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 +1 -1
- package/package.json +34 -29
- package/dist/index.js +0 -269
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -60,4 +60,4 @@ The sample commands are as follows:
|
|
|
60
60
|
- [sample-of-one-way-git-sync](https://github.com/WillBooster/sample-of-one-way-git-sync): an example synchronized repository.
|
|
61
61
|
- [release.yml](.github/workflows/release.yml): releases a new npm package and add a tag automatically in this repository using `semantic-release`.
|
|
62
62
|
- [sync.yml](.github/workflows/sync.yml): it synchronizes `sample-of-one-way-git-sync` repository using `one-way-git-sync` when a new version is released.
|
|
63
|
-
- [force-sync.yml](.github/workflows/force
|
|
63
|
+
- [force-sync.yml](.github/workflows/sync-force.yml): we can manually trigger this workflow which forces synchronizing `sample-of-one-way-git-sync` repository.
|
package/package.json
CHANGED
|
@@ -28,57 +28,62 @@
|
|
|
28
28
|
"typecheck": "tsc --noEmit --Pretty"
|
|
29
29
|
},
|
|
30
30
|
"prettier": "@willbooster/prettier-config",
|
|
31
|
+
"resolutions": {
|
|
32
|
+
"npm/chalk": "^4.1.2"
|
|
33
|
+
},
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"fs-extra": "10.0.0",
|
|
33
36
|
"simple-git": "2.48.0",
|
|
34
|
-
"winston": "3.
|
|
35
|
-
"yargs": "17.3.
|
|
37
|
+
"winston": "3.5.1",
|
|
38
|
+
"yargs": "17.3.1"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "7.
|
|
39
|
-
"@babel/helper-plugin-utils": "7.16.
|
|
40
|
-
"@babel/node": "7.16.
|
|
41
|
-
"@babel/plugin-proposal-class-properties": "7.16.
|
|
42
|
-
"@babel/plugin-proposal-numeric-separator": "7.16.
|
|
43
|
-
"@babel/preset-env": "7.16.
|
|
44
|
-
"@babel/preset-typescript": "7.16.
|
|
41
|
+
"@babel/core": "7.17.2",
|
|
42
|
+
"@babel/helper-plugin-utils": "7.16.7",
|
|
43
|
+
"@babel/node": "7.16.8",
|
|
44
|
+
"@babel/plugin-proposal-class-properties": "7.16.7",
|
|
45
|
+
"@babel/plugin-proposal-numeric-separator": "7.16.7",
|
|
46
|
+
"@babel/preset-env": "7.16.11",
|
|
47
|
+
"@babel/preset-typescript": "7.16.7",
|
|
45
48
|
"@rollup/plugin-babel": "5.3.0",
|
|
46
49
|
"@rollup/plugin-commonjs": "21.0.1",
|
|
47
|
-
"@rollup/plugin-node-resolve": "13.1.
|
|
48
|
-
"@types/eslint": "8.
|
|
50
|
+
"@rollup/plugin-node-resolve": "13.1.3",
|
|
51
|
+
"@types/eslint": "8.4.1",
|
|
49
52
|
"@types/fs-extra": "9.0.13",
|
|
50
53
|
"@types/micromatch": "4.0.2",
|
|
51
54
|
"@types/semantic-release": "17.2.3",
|
|
52
|
-
"@types/yargs": "17.0.
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
54
|
-
"@typescript-eslint/parser": "5.
|
|
55
|
-
"@willbooster/eslint-config-ts": "
|
|
56
|
-
"@willbooster/prettier-config": "
|
|
57
|
-
"@willbooster/renovate-config": "
|
|
55
|
+
"@types/yargs": "17.0.8",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "5.12.0",
|
|
57
|
+
"@typescript-eslint/parser": "5.12.0",
|
|
58
|
+
"@willbooster/eslint-config-ts": "9.0.0",
|
|
59
|
+
"@willbooster/prettier-config": "9.0.0",
|
|
60
|
+
"@willbooster/renovate-config": "9.2.0",
|
|
58
61
|
"babel-plugin-transform-remove-console": "6.9.4",
|
|
59
62
|
"babel-plugin-unassert": "3.2.0",
|
|
60
63
|
"babel-preset-power-assert": "3.0.0",
|
|
61
|
-
"conventional-changelog-conventionalcommits": "4.6.
|
|
62
|
-
"core-js": "3.
|
|
63
|
-
"eslint": "8.
|
|
64
|
+
"conventional-changelog-conventionalcommits": "4.6.3",
|
|
65
|
+
"core-js": "3.21.0",
|
|
66
|
+
"eslint": "8.9.0",
|
|
64
67
|
"eslint-config-prettier": "8.3.0",
|
|
65
|
-
"eslint-import-resolver-
|
|
66
|
-
"eslint-plugin-import": "2.25.
|
|
68
|
+
"eslint-import-resolver-typescript": "2.5.0",
|
|
69
|
+
"eslint-plugin-import": "2.25.4",
|
|
70
|
+
"eslint-plugin-sort-class-members": "1.14.1",
|
|
71
|
+
"eslint-plugin-sort-destructure-keys": "1.4.0",
|
|
67
72
|
"husky": "7.0.4",
|
|
68
|
-
"lint-staged": "12.
|
|
73
|
+
"lint-staged": "12.3.4",
|
|
69
74
|
"micromatch": "4.0.4",
|
|
70
75
|
"pinst": "2.1.6",
|
|
71
76
|
"power-assert": "1.6.1",
|
|
72
77
|
"prettier": "2.5.1",
|
|
73
|
-
"rollup": "2.
|
|
74
|
-
"rollup-plugin-node-externals": "
|
|
78
|
+
"rollup": "2.67.2",
|
|
79
|
+
"rollup-plugin-node-externals": "4.0.0",
|
|
75
80
|
"semantic-release": "18.0.1",
|
|
76
|
-
"sort-package-json": "1.
|
|
77
|
-
"typescript": "4.5.
|
|
81
|
+
"sort-package-json": "1.54.0",
|
|
82
|
+
"typescript": "4.5.5"
|
|
78
83
|
},
|
|
79
84
|
"engines": {
|
|
80
85
|
"node": ">=14"
|
|
81
86
|
},
|
|
82
|
-
"packageManager": "yarn@3.
|
|
83
|
-
"version": "3.1.
|
|
87
|
+
"packageManager": "yarn@3.2.0-rc.15",
|
|
88
|
+
"version": "3.1.3"
|
|
84
89
|
}
|
package/dist/index.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var helpers = require('yargs/helpers');
|
|
6
|
-
var yargs = require('yargs/yargs');
|
|
7
|
-
var child_process = require('child_process');
|
|
8
|
-
var fsp = require('fs/promises');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
var fse = require('fs-extra');
|
|
11
|
-
var simpleGit = require('simple-git');
|
|
12
|
-
var winston = require('winston');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);
|
|
17
|
-
var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
|
|
18
|
-
var fsp__default = /*#__PURE__*/_interopDefaultLegacy(fsp);
|
|
19
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
20
|
-
var fse__default = /*#__PURE__*/_interopDefaultLegacy(fse);
|
|
21
|
-
var simpleGit__default = /*#__PURE__*/_interopDefaultLegacy(simpleGit);
|
|
22
|
-
|
|
23
|
-
const logger = winston.createLogger({
|
|
24
|
-
transports: [new winston.transports.Console({
|
|
25
|
-
format: winston.format.cli({
|
|
26
|
-
colors: {
|
|
27
|
-
error: 'red'
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
})]
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const syncDirPath = path__default["default"].join('node_modules', '.temp', 'sync-git-repo');
|
|
34
|
-
const ignoreNames = ['.git', 'node_modules'];
|
|
35
|
-
async function sync(opts, init) {
|
|
36
|
-
await fsp__default["default"].mkdir(syncDirPath, {
|
|
37
|
-
recursive: true
|
|
38
|
-
});
|
|
39
|
-
const dirPath = await fsp__default["default"].mkdtemp(path__default["default"].join(syncDirPath, 'repo-'));
|
|
40
|
-
const ret = await syncCore(dirPath, opts, init);
|
|
41
|
-
await fsp__default["default"].rm(dirPath, {
|
|
42
|
-
recursive: true,
|
|
43
|
-
force: true
|
|
44
|
-
});
|
|
45
|
-
process.exit(ret ? 0 : 1);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function syncCore(destRepoPath, opts, init) {
|
|
49
|
-
var _srcLog$latest, _opts$prefix;
|
|
50
|
-
|
|
51
|
-
await simpleGit__default["default"]().clone(opts.dest, destRepoPath, opts.force ? undefined : {
|
|
52
|
-
'--depth': 1
|
|
53
|
-
});
|
|
54
|
-
logger.verbose('Cloned a destination repo');
|
|
55
|
-
const dstGit = simpleGit__default["default"](destRepoPath);
|
|
56
|
-
|
|
57
|
-
if (opts.branch) {
|
|
58
|
-
try {
|
|
59
|
-
await dstGit.checkout(opts.branch);
|
|
60
|
-
} catch (_) {
|
|
61
|
-
await dstGit.checkoutLocalBranch(opts.branch);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const dstLog = await dstGit.log();
|
|
66
|
-
let from;
|
|
67
|
-
|
|
68
|
-
if (!init) {
|
|
69
|
-
from = extractCommitHash(dstLog);
|
|
70
|
-
|
|
71
|
-
if (!from) {
|
|
72
|
-
logger.error('No valid commit in destination repo');
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
logger.verbose(`Extracted a valid commit: ${from}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const srcGit = simpleGit__default["default"]();
|
|
80
|
-
let srcLog;
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
// '--first-parent' hides children commits of merge commits
|
|
84
|
-
srcLog = await srcGit.log(from ? {
|
|
85
|
-
from,
|
|
86
|
-
to: 'HEAD',
|
|
87
|
-
'--first-parent': undefined
|
|
88
|
-
} : undefined);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
logger.error('Failed to get source commit history:', e);
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const latestHash = (_srcLog$latest = srcLog.latest) === null || _srcLog$latest === void 0 ? void 0 : _srcLog$latest.hash;
|
|
95
|
-
|
|
96
|
-
if (!latestHash) {
|
|
97
|
-
logger.info('No synchronizable commit');
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const [destFiles, srcFiles] = await Promise.all([fsp__default["default"].readdir(destRepoPath), fsp__default["default"].readdir('.')]);
|
|
102
|
-
|
|
103
|
-
for (const destFile of destFiles) {
|
|
104
|
-
if (ignoreNames.includes(destFile)) continue;
|
|
105
|
-
await fsp__default["default"].rm(path__default["default"].join(destRepoPath, destFile), {
|
|
106
|
-
recursive: true,
|
|
107
|
-
force: true
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
for (const srcFile of srcFiles) {
|
|
112
|
-
if (ignoreNames.includes(srcFile)) continue;
|
|
113
|
-
fse__default["default"].copySync(srcFile, path__default["default"].join(destRepoPath, srcFile));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
await dstGit.add('-A');
|
|
117
|
-
let srcTag = '';
|
|
118
|
-
|
|
119
|
-
if (opts['tag-hash'] || opts['tag-version']) {
|
|
120
|
-
// e.g. `--abbrev=0` changes `v1.31.5-2-gcdde507` to `v1.31.5`
|
|
121
|
-
const describeCommand = `git describe --tags --always ${opts['tag-version'] ? '--abbrev=0' : ''}`;
|
|
122
|
-
srcTag = child_process__default["default"].execSync(describeCommand).toString().trim();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let prefix = (_opts$prefix = opts.prefix) !== null && _opts$prefix !== void 0 ? _opts$prefix : '';
|
|
126
|
-
|
|
127
|
-
if (prefix && !prefix.endsWith('/')) {
|
|
128
|
-
prefix += '/';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const link = `${prefix}${latestHash}`;
|
|
132
|
-
const title = srcTag ? `sync ${srcTag} (${link})` : `sync ${link}`;
|
|
133
|
-
const body = init ? `Initialize one-way-git-sync by replacing all the files with those of ${opts.dest}` : srcLog.all.map(l => `* ${l.message}`).join('\n\n');
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
await dstGit.commit(`${title}\n\n${body}`);
|
|
137
|
-
logger.verbose(`Created a commit: ${title}`);
|
|
138
|
-
logger.verbose(` with body: ${body}`);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
logger.error('Failed to commit changes:', e);
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const destTag = srcTag || opts.tag;
|
|
145
|
-
|
|
146
|
-
if (destTag) {
|
|
147
|
-
try {
|
|
148
|
-
await dstGit.addTag(destTag);
|
|
149
|
-
logger.verbose(`Created a tag: ${destTag}`);
|
|
150
|
-
} catch (e) {
|
|
151
|
-
logger.error('Failed to commit changes:', e);
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (opts.dry) {
|
|
157
|
-
logger.verbose('Finished dry run');
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
await dstGit.push();
|
|
163
|
-
|
|
164
|
-
if (destTag) {
|
|
165
|
-
await dstGit.push({
|
|
166
|
-
'--tags': null
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
} catch (e) {
|
|
170
|
-
logger.error('Failed to push a commit:', e);
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
logger.verbose('Pushed a commit');
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function extractCommitHash(logResult) {
|
|
179
|
-
if (logResult.all.length === 0) {
|
|
180
|
-
logger.error('No commit history');
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
for (const log of logResult.all) {
|
|
185
|
-
const [head, ...words] = log.message.replace(/[()]/g, '').split(/[\s/]/);
|
|
186
|
-
|
|
187
|
-
if (head === 'sync' && words.length) {
|
|
188
|
-
return words[words.length - 1];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
logger.error('No sync commit: ', logResult.all[0]);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const initCommand = {
|
|
197
|
-
command: 'init',
|
|
198
|
-
describe: 'Initialize a destination git repository',
|
|
199
|
-
|
|
200
|
-
async handler(argv) {
|
|
201
|
-
await sync(argv, true);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const syncCommand = {
|
|
207
|
-
command: 'sync',
|
|
208
|
-
describe: 'Synchronize a destination git repository with a source git repository',
|
|
209
|
-
|
|
210
|
-
async handler(argv) {
|
|
211
|
-
await sync(argv, false);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const yargsOptions = {
|
|
217
|
-
dest: {
|
|
218
|
-
type: 'string',
|
|
219
|
-
alias: 'd',
|
|
220
|
-
describe: 'A URL of a destination git repository.',
|
|
221
|
-
demand: true
|
|
222
|
-
},
|
|
223
|
-
prefix: {
|
|
224
|
-
type: 'string',
|
|
225
|
-
alias: 'p',
|
|
226
|
-
describe: `A prefix of a commit hash used to generate a commit title, e.g. 'sync <prefix>/<hash>'.
|
|
227
|
-
A typical value is like 'https://github.com/WillBooster/one-way-git-sync/commits'`
|
|
228
|
-
},
|
|
229
|
-
branch: {
|
|
230
|
-
type: 'string',
|
|
231
|
-
alias: 'b',
|
|
232
|
-
describe: 'Specify branch of destination repo.'
|
|
233
|
-
},
|
|
234
|
-
tag: {
|
|
235
|
-
type: 'string',
|
|
236
|
-
alias: 't',
|
|
237
|
-
describe: 'Specify tag to be created in destination repo.'
|
|
238
|
-
},
|
|
239
|
-
'tag-hash': {
|
|
240
|
-
type: 'boolean',
|
|
241
|
-
describe: 'Create version+hash tag (e.g. v1.31.5-2-gcdde507). It should be a unique tag.'
|
|
242
|
-
},
|
|
243
|
-
'tag-version': {
|
|
244
|
-
type: 'boolean',
|
|
245
|
-
describe: 'Create version tag (e.g. v1.31.5). It could be a non-unique tag.'
|
|
246
|
-
},
|
|
247
|
-
dry: {
|
|
248
|
-
type: 'boolean',
|
|
249
|
-
describe: 'Enable dry-run mode.'
|
|
250
|
-
},
|
|
251
|
-
force: {
|
|
252
|
-
type: 'boolean',
|
|
253
|
-
describe: 'Force to overwrite the destination git repository.'
|
|
254
|
-
},
|
|
255
|
-
verbose: {
|
|
256
|
-
type: 'boolean',
|
|
257
|
-
alias: 'v',
|
|
258
|
-
describe: 'Show details logs.'
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
async function cli(argv) {
|
|
263
|
-
await yargs__default["default"](helpers.hideBin(argv)).options(yargsOptions).middleware(argv => {
|
|
264
|
-
logger.level = argv.verbose ? 'verbose' : 'info';
|
|
265
|
-
}).command(initCommand).command(syncCommand).argv;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
exports.cli = cli;
|
|
269
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/index.ts","../src/initCommand.ts","../src/syncCommand.ts","../src/yargsOptions.ts","../src/cli.ts"],"sourcesContent":["import { createLogger, format, transports } from 'winston';\n\nexport const logger = createLogger({\n transports: [\n new transports.Console({\n format: format.cli({ colors: { error: 'red' } }),\n }),\n ],\n});\n","import child_process from 'child_process';\nimport fsp from 'fs/promises';\nimport path from 'path';\n\nimport fse from 'fs-extra';\nimport simpleGit, { SimpleGit } from 'simple-git';\nimport type { LogResult } from 'simple-git/typings/response';\nimport { InferredOptionTypes } from 'yargs';\n\nimport { logger } from './logger';\nimport { yargsOptions } from './yargsOptions';\n\nconst syncDirPath = path.join('node_modules', '.temp', 'sync-git-repo');\nconst ignoreNames = ['.git', 'node_modules'];\n\nexport async function sync(opts: InferredOptionTypes<typeof yargsOptions>, init: boolean): Promise<void> {\n await fsp.mkdir(syncDirPath, { recursive: true });\n const dirPath = await fsp.mkdtemp(path.join(syncDirPath, 'repo-'));\n const ret = await syncCore(dirPath, opts, init);\n await fsp.rm(dirPath, { recursive: true, force: true });\n process.exit(ret ? 0 : 1);\n}\n\nasync function syncCore(\n destRepoPath: string,\n opts: InferredOptionTypes<typeof yargsOptions>,\n init: boolean\n): Promise<boolean> {\n await simpleGit().clone(opts.dest, destRepoPath, opts.force ? undefined : { '--depth': 1 });\n logger.verbose('Cloned a destination repo');\n\n const dstGit: SimpleGit = simpleGit(destRepoPath);\n if (opts.branch) {\n try {\n await dstGit.checkout(opts.branch);\n } catch (_) {\n await dstGit.checkoutLocalBranch(opts.branch);\n }\n }\n const dstLog = await dstGit.log();\n\n let from: string | undefined;\n if (!init) {\n from = extractCommitHash(dstLog);\n if (!from) {\n logger.error('No valid commit in destination repo');\n return false;\n }\n logger.verbose(`Extracted a valid commit: ${from}`);\n }\n\n const srcGit: SimpleGit = simpleGit();\n let srcLog: LogResult;\n try {\n // '--first-parent' hides children commits of merge commits\n srcLog = await srcGit.log(from ? { from, to: 'HEAD', '--first-parent': undefined } : undefined);\n } catch (e) {\n logger.error('Failed to get source commit history:', e);\n return false;\n }\n\n const latestHash = srcLog.latest?.hash;\n if (!latestHash) {\n logger.info('No synchronizable commit');\n return true;\n }\n\n const [destFiles, srcFiles] = await Promise.all([fsp.readdir(destRepoPath), fsp.readdir('.')]);\n for (const destFile of destFiles) {\n if (ignoreNames.includes(destFile)) continue;\n await fsp.rm(path.join(destRepoPath, destFile), { recursive: true, force: true });\n }\n for (const srcFile of srcFiles) {\n if (ignoreNames.includes(srcFile)) continue;\n fse.copySync(srcFile, path.join(destRepoPath, srcFile));\n }\n await dstGit.add('-A');\n\n let srcTag = '';\n if (opts['tag-hash'] || opts['tag-version']) {\n // e.g. `--abbrev=0` changes `v1.31.5-2-gcdde507` to `v1.31.5`\n const describeCommand = `git describe --tags --always ${opts['tag-version'] ? '--abbrev=0' : ''}`;\n srcTag = child_process.execSync(describeCommand).toString().trim();\n }\n let prefix = opts.prefix ?? '';\n if (prefix && !prefix.endsWith('/')) {\n prefix += '/';\n }\n const link = `${prefix}${latestHash}`;\n const title = srcTag ? `sync ${srcTag} (${link})` : `sync ${link}`;\n const body = init\n ? `Initialize one-way-git-sync by replacing all the files with those of ${opts.dest}`\n : srcLog.all.map((l) => `* ${l.message}`).join('\\n\\n');\n try {\n await dstGit.commit(`${title}\\n\\n${body}`);\n logger.verbose(`Created a commit: ${title}`);\n logger.verbose(` with body: ${body}`);\n } catch (e) {\n logger.error('Failed to commit changes:', e);\n return false;\n }\n\n const destTag = srcTag || opts.tag;\n if (destTag) {\n try {\n await dstGit.addTag(destTag);\n logger.verbose(`Created a tag: ${destTag}`);\n } catch (e) {\n logger.error('Failed to commit changes:', e);\n return false;\n }\n }\n\n if (opts.dry) {\n logger.verbose('Finished dry run');\n return true;\n }\n\n try {\n await dstGit.push();\n if (destTag) {\n await dstGit.push({ '--tags': null });\n }\n } catch (e) {\n logger.error('Failed to push a commit:', e);\n return false;\n }\n\n logger.verbose('Pushed a commit');\n return true;\n}\n\nfunction extractCommitHash(logResult: LogResult): string | undefined {\n if (logResult.all.length === 0) {\n logger.error('No commit history');\n return;\n }\n\n for (const log of logResult.all) {\n const [head, ...words] = log.message.replace(/[()]/g, '').split(/[\\s/]/);\n if (head === 'sync' && words.length) {\n return words[words.length - 1];\n }\n }\n logger.error('No sync commit: ', logResult.all[0]);\n return;\n}\n","import type { CommandModule, InferredOptionTypes } from 'yargs';\n\nimport { yargsOptions } from './yargsOptions';\n\nimport { sync } from './index';\n\nexport const initCommand: CommandModule<unknown, InferredOptionTypes<typeof yargsOptions>> = {\n command: 'init',\n describe: 'Initialize a destination git repository',\n async handler(argv) {\n await sync(argv, true);\n },\n};\n","import type { CommandModule, InferredOptionTypes } from 'yargs';\n\nimport { yargsOptions } from './yargsOptions';\n\nimport { sync } from './index';\n\nexport const syncCommand: CommandModule<unknown, InferredOptionTypes<typeof yargsOptions>> = {\n command: 'sync',\n describe: 'Synchronize a destination git repository with a source git repository',\n async handler(argv) {\n await sync(argv, false);\n },\n};\n","export const yargsOptions = {\n dest: {\n type: 'string',\n alias: 'd',\n describe: 'A URL of a destination git repository.',\n demand: true,\n },\n prefix: {\n type: 'string',\n alias: 'p',\n describe: `A prefix of a commit hash used to generate a commit title, e.g. 'sync <prefix>/<hash>'.\n A typical value is like 'https://github.com/WillBooster/one-way-git-sync/commits'`,\n },\n branch: {\n type: 'string',\n alias: 'b',\n describe: 'Specify branch of destination repo.',\n },\n tag: {\n type: 'string',\n alias: 't',\n describe: 'Specify tag to be created in destination repo.',\n },\n 'tag-hash': {\n type: 'boolean',\n describe: 'Create version+hash tag (e.g. v1.31.5-2-gcdde507). It should be a unique tag.',\n },\n 'tag-version': {\n type: 'boolean',\n describe: 'Create version tag (e.g. v1.31.5). It could be a non-unique tag.',\n },\n dry: {\n type: 'boolean',\n describe: 'Enable dry-run mode.',\n },\n force: {\n type: 'boolean',\n describe: 'Force to overwrite the destination git repository.',\n },\n verbose: {\n type: 'boolean',\n alias: 'v',\n describe: 'Show details logs.',\n },\n} as const;\n","import { hideBin } from 'yargs/helpers';\nimport yargs from 'yargs/yargs';\n\nimport { initCommand } from './initCommand';\nimport { logger } from './logger';\nimport { syncCommand } from './syncCommand';\nimport { yargsOptions } from './yargsOptions';\n\nexport async function cli(argv: string[]): Promise<void> {\n await yargs(hideBin(argv))\n .options(yargsOptions)\n .middleware((argv) => {\n logger.level = argv.verbose ? 'verbose' : 'info';\n })\n .command(initCommand)\n .command(syncCommand).argv;\n}\n"],"names":["logger","createLogger","transports","Console","format","cli","colors","error","syncDirPath","path","join","ignoreNames","sync","opts","init","fsp","mkdir","recursive","dirPath","mkdtemp","ret","syncCore","rm","force","process","exit","destRepoPath","simpleGit","clone","dest","undefined","verbose","dstGit","branch","checkout","_","checkoutLocalBranch","dstLog","log","from","extractCommitHash","srcGit","srcLog","to","e","latestHash","latest","hash","info","destFiles","srcFiles","Promise","all","readdir","destFile","includes","srcFile","fse","copySync","add","srcTag","describeCommand","child_process","execSync","toString","trim","prefix","endsWith","link","title","body","map","l","message","commit","destTag","tag","addTag","dry","push","logResult","length","head","words","replace","split","initCommand","command","describe","handler","argv","syncCommand","yargsOptions","type","alias","demand","yargs","hideBin","options","midd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