@surmrf/icloud-surge-sync 1.0.0 → 1.0.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/bin/cli.js CHANGED
@@ -4,13 +4,13 @@ const fs = require('node:fs');
4
4
  const os = require('node:os');
5
5
  const path = require('node:path');
6
6
  const readline = require('node:readline/promises');
7
- const simpleGit = require('simple-git');
8
7
  const { stdin, stdout } = require('node:process');
9
8
  const packageJson = require('../package.json');
10
9
  const { loadConfig, resolveConfigPath, saveConfig } = require('../src/config');
11
10
  const { daemonStatus, followLogs, installDaemon, restartDaemon, uninstallDaemon } = require('../src/daemon');
12
11
  const { runPull } = require('../src/pull');
13
12
  const { runPush } = require('../src/push');
13
+ const { createGit } = require('../src/utils/git');
14
14
  const {
15
15
  isInside,
16
16
  validateForPull,
@@ -104,7 +104,7 @@ async function isGitRepository(folder) {
104
104
  return false;
105
105
  }
106
106
  try {
107
- return await simpleGit(folder).checkIsRepo();
107
+ return await createGit(folder).checkIsRepo();
108
108
  } catch {
109
109
  return false;
110
110
  }
@@ -112,7 +112,7 @@ async function isGitRepository(folder) {
112
112
 
113
113
  async function prepareGitFolder(gitFolder, remote, branch) {
114
114
  if (await isGitRepository(gitFolder)) {
115
- const git = simpleGit(gitFolder);
115
+ const git = createGit(gitFolder);
116
116
  const remotes = await git.getRemotes();
117
117
  if (remote && !remotes.some((item) => item.name === 'origin')) {
118
118
  await git.addRemote('origin', remote);
@@ -128,7 +128,7 @@ async function prepareGitFolder(gitFolder, remote, branch) {
128
128
  }
129
129
  fs.mkdirSync(path.dirname(gitFolder), { recursive: true });
130
130
  const cloneOptions = branch ? ['--branch', branch] : [];
131
- await simpleGit().clone(remote, gitFolder, cloneOptions);
131
+ await createGit().clone(remote, gitFolder, cloneOptions);
132
132
  }
133
133
 
134
134
  async function initialize(flags) {
@@ -211,10 +211,7 @@ async function runConfigured(configPath, requestedRole) {
211
211
  async function doctor(configPath) {
212
212
  const role = getConfiguredRole(configPath);
213
213
  const config = role === 'push' ? validateForPush(configPath) : validateForPull(configPath);
214
- const git = simpleGit({ baseDir: config.gitFolder, timeout: { block: 60 * 1000 } }).env({
215
- ...process.env,
216
- GIT_TERMINAL_PROMPT: '0',
217
- });
214
+ const git = createGit({ baseDir: config.gitFolder, timeout: { block: 60 * 1000 } });
218
215
  const remotes = await git.getRemotes(true);
219
216
  const origin = remotes.find((remote) => remote.name === 'origin');
220
217
  if (!origin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surmrf/icloud-surge-sync",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "One-way Surge configuration distribution from iCloud through Git.",
5
5
  "bin": {
6
6
  "icloud-surge-sync": "bin/cli.js",
package/src/pull.js CHANGED
@@ -1,21 +1,14 @@
1
- const simpleGit = require('simple-git');
2
1
  const logger = require('./utils/logger');
3
2
  const { validateForPull } = require('./utils/config-validator');
3
+ const { createGit } = require('./utils/git');
4
4
 
5
- function createGit(gitFolder) {
6
- return simpleGit({
7
- baseDir: gitFolder,
5
+ async function runPull(options = {}) {
6
+ const config = options.config || validateForPull(options.configPath);
7
+ const git = createGit({
8
+ baseDir: config.gitFolder,
8
9
  maxConcurrentProcesses: 1,
9
10
  timeout: { block: 60 * 1000 },
10
- }).env({
11
- ...process.env,
12
- GIT_TERMINAL_PROMPT: '0',
13
11
  });
14
- }
15
-
16
- async function runPull(options = {}) {
17
- const config = options.config || validateForPull(options.configPath);
18
- const git = createGit(config.gitFolder);
19
12
  const pollInterval = options.pollInterval || config.pollInterval || 10 * 1000;
20
13
  let pollTimer = null;
21
14
  let stopped = false;
package/src/push.js CHANGED
@@ -1,26 +1,19 @@
1
1
  const chokidar = require('chokidar');
2
2
  const fs = require('fs-extra');
3
3
  const path = require('node:path');
4
- const simpleGit = require('simple-git');
5
4
  const logger = require('./utils/logger');
6
5
  const { validateForPush } = require('./utils/config-validator');
7
-
8
- function createGit(gitFolder) {
9
- return simpleGit({
10
- baseDir: gitFolder,
11
- maxConcurrentProcesses: 1,
12
- timeout: { block: 60 * 1000 },
13
- }).env({
14
- ...process.env,
15
- GIT_TERMINAL_PROMPT: '0',
16
- });
17
- }
6
+ const { createGit } = require('./utils/git');
18
7
 
19
8
  async function runPush(options = {}) {
20
9
  const config = options.config || validateForPush(options.configPath);
21
10
  const icloudFolder = config.icloudFolder;
22
11
  const gitFolder = config.gitFolder;
23
- const git = createGit(gitFolder);
12
+ const git = createGit({
13
+ baseDir: gitFolder,
14
+ maxConcurrentProcesses: 1,
15
+ timeout: { block: 60 * 1000 },
16
+ });
24
17
 
25
18
  const copyChangedFile = async (filePath) => {
26
19
  const relative = path.relative(icloudFolder, filePath);
@@ -0,0 +1,15 @@
1
+ const simpleGit = require('simple-git');
2
+
3
+ function createGitEnvironment(environment = process.env) {
4
+ const gitEnvironment = { ...environment };
5
+ delete gitEnvironment.PAGER;
6
+ delete gitEnvironment.GIT_PAGER;
7
+ gitEnvironment.GIT_TERMINAL_PROMPT = '0';
8
+ return gitEnvironment;
9
+ }
10
+
11
+ function createGit(options) {
12
+ return simpleGit(options).env(createGitEnvironment());
13
+ }
14
+
15
+ module.exports = { createGit, createGitEnvironment };