Skip to content

Commit 40dba40

Browse files
author
SPRINX0\prochazka
committed
Merge branch 'master' of https://github.com/dbgate/diflow
2 parents 24d6ac7 + 50032cb commit 40dba40

File tree

5 files changed

+113
-7
lines changed

5 files changed

+113
-7
lines changed

.github/workflows/build-npm.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: NPM package
2+
'on':
3+
push:
4+
tags:
5+
- v[0-9]+.[0-9]+.[0-9]+
6+
jobs:
7+
build:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os:
12+
- ubuntu-22.04
13+
steps:
14+
- name: Context
15+
env:
16+
GITHUB_CONTEXT: ${{ toJson(github) }}
17+
run: echo "$GITHUB_CONTEXT"
18+
- uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 1
21+
- name: Use Node.js 22.x
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 22.x
25+
- name: Configure NPM token
26+
env:
27+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
28+
run: |
29+
npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
30+
- name: npm install
31+
run: |
32+
npm install
33+
- name: Publish
34+
run: |
35+
npm publish

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2-
"name": "gitdiff",
3-
"version": "1.0.0",
2+
"name": "diflow",
3+
"version": "1.0.1",
4+
"bin": {
5+
"diflow": "./dist/diflow.js"
6+
},
47
"scripts": {
58
"build": "tsc",
69
"test": "npm run build && jest --runInBand",
@@ -10,18 +13,23 @@
1013
"test:dbgate": "yarn tsc && node dist/diflow sync -r https://github.com/dbgate/dbgate-diflow-config.git -b master --skip-push --clear",
1114
"test:dbgate:push": "yarn tsc && node dist/diflow sync -r https://github.com/dbgate/dbgate-diflow-config.git -b master --clear"
1215
},
16+
"files": [
17+
"LICENSE",
18+
"README.md",
19+
"dist"
20+
],
1321
"devDependencies": {
1422
"@types/fs-extra": "^11.0.4",
1523
"@types/jest": "^29.5.12",
1624
"@types/node": "^20.11.19",
17-
"fs-extra": "^11.2.0",
1825
"jest": "^29.7.0",
1926
"ts-node": "^10.9.2",
2027
"typescript": "^5.3.3"
2128
},
2229
"dependencies": {
2330
"@types/lodash": "^4.17.15",
2431
"commander": "^13.1.0",
32+
"fs-extra": "^11.2.0",
2533
"lodash": "^4.17.21",
2634
"minimatch": "^10.0.1",
2735
"rimraf": "^6.0.1"

src/diflow.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22
import { Processor } from './processor';
33
import { Command } from 'commander';
4+
import { filesystemMerge } from './fsmerge';
45

56
const program = new Command();
67

@@ -20,7 +21,7 @@ program
2021
'secret for accessing repo. URLs of git repos should be in shape https://DIFLOW_GIT_SECRET@<url>. You could also use DIFLOW_GIT_SECRET env variable.'
2122
)
2223
.option('--clear', 'clear work repos before running')
23-
.action(options => {
24+
.action(async options => {
2425
// console.log('repo:', options.repo);
2526
// console.log('branch:', options.branch);
2627
// return;
@@ -29,7 +30,18 @@ program
2930
clear: options.clear,
3031
secret: options.secret ?? process.env.DIFLOW_GIT_SECRET,
3132
});
32-
processor.process();
33+
await processor.process();
34+
console.log('Processing complete.');
35+
});
36+
37+
program
38+
.command('fsmerge')
39+
.description('Run simple merge between directories (base+diff=merged)')
40+
.requiredOption('-b, --base <string>', 'Foder with base repository')
41+
.requiredOption('-d, --diff <string>', 'Foder with diff repository')
42+
.requiredOption('-m, --merged <string>', 'Foder with merged repository (output folder)')
43+
.action(async options => {
44+
await filesystemMerge(options.base, options.diff, options.merged);
3345
console.log('Processing complete.');
3446
});
3547

src/fsmerge.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const fs = require('fs-extra');
2+
const path = require('path');
3+
4+
function skipPath(src: string) {
5+
if (src.includes('/node_modules/')) return true;
6+
if (src.includes('\\node_modules\\')) return true;
7+
8+
if (src.includes('/.git/')) return true;
9+
if (src.includes('\\.git\\')) return true;
10+
11+
return false;
12+
}
13+
14+
async function copyDir(src: string, dest: string) {
15+
// Check if the source directory exists
16+
if (!await fs.exists(src)) {
17+
console.error(`Source directory "${src}" does not exist.`);
18+
return;
19+
}
20+
21+
// Create the destination directory if it does not exist
22+
if (!await fs.exists(dest)) {
23+
await fs.mkdir(dest, { recursive: true });
24+
}
25+
26+
// Read the contents of the source directory
27+
const entries = fs.readdirSync(src, { withFileTypes: true });
28+
29+
for (let entry of entries) {
30+
const srcPath = path.join(src, entry.name);
31+
const destPath = path.join(dest, entry.name);
32+
33+
if (skipPath(srcPath)) continue;
34+
if (skipPath(destPath)) continue;
35+
36+
if (entry.isDirectory()) {
37+
await copyDir(srcPath, destPath);
38+
} else {
39+
await fs.copy(destPath, srcPath);
40+
}
41+
}
42+
}
43+
44+
export async function filesystemMerge(base: string, diff: string, merged: string) {
45+
await fs.ensureDir(merged);
46+
console.log('Copying:', base, '=>', merged);
47+
await copyDir(base, merged);
48+
console.log('Copying:', diff, '=>', merged);
49+
await copyDir(diff, merged);
50+
console.log('Directories merged successfully');
51+
}

src/processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class CommitProcessor {
283283
let target = this.processor.config?.newFilesTargetDefault ?? 'diff';
284284
if (
285285
await this.matchIdentifiers(
286-
this.processor.repoPaths.diff,
286+
this.processor.repoPaths.merged,
287287
file.file,
288288
this.processor.config?.repos.base.identifiers
289289
)
@@ -292,7 +292,7 @@ class CommitProcessor {
292292
}
293293
if (
294294
await this.matchIdentifiers(
295-
this.processor.repoPaths.diff,
295+
this.processor.repoPaths.merged,
296296
file.file,
297297
this.processor.config?.repos.diff.identifiers
298298
)

0 commit comments

Comments
 (0)