johankit 0.0.2 → 0.0.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 +0 -5
- package/Readme.md +56 -0
- package/cli/commands/paste.js +42 -0
- package/cli/commands/paste.ts +42 -0
- package/cli/commands/prompt.js +59 -0
- package/cli/commands/prompt.ts +57 -0
- package/cli/commands/sync.js +83 -0
- package/cli/commands/sync.ts +87 -0
- package/commands/paste.js +42 -0
- package/commands/paste.ts +45 -0
- package/core/config.js +44 -0
- package/core/config.ts +42 -0
- package/core/schema.js +30 -0
- package/core/schema.ts +29 -0
- package/core/vm.js +20 -0
- package/core/vm.ts +18 -0
- package/dist/cli/commands/copy.js +3 -4
- package/dist/cli/commands/paste.js +6 -2
- package/dist/cli/commands/prompt.js +2 -2
- package/dist/core/clean.js +13 -0
- package/dist/utils/cleanCodeBlock.js +12 -0
- package/package.json +4 -2
- package/src/cli/commands/copy.ts +3 -4
- package/src/cli/commands/paste.ts +3 -2
- package/src/cli/commands/prompt.ts +3 -3
- package/src/utils/cleanCodeBlock.ts +13 -0
- package/tsconfig.json +4 -0
- package/dist/tests/cli/commands/copy.test.js +0 -47
- package/dist/tests/cli/commands/paste.test.js +0 -41
- package/dist/tests/cli/commands/prompt.test.js +0 -37
- package/dist/tests/cli/commands/sync.test.js +0 -47
- package/dist/tests/core/clipboard.test.js +0 -20
- package/dist/tests/core/config.test.js +0 -23
- package/dist/tests/core/diff.test.js +0 -24
- package/dist/tests/core/git.test.js +0 -11
- package/dist/tests/core/scan.test.js +0 -16
- package/dist/tests/core/schema.test.js +0 -13
- package/dist/tests/core/validation.test.js +0 -13
- package/dist/tests/core/write.test.js +0 -41
- package/package-lock.json +0 -250
- package/src/tests/cli/commands/copy.test.ts +0 -26
- package/src/tests/cli/commands/paste.test.ts +0 -19
- package/src/tests/cli/commands/prompt.test.ts +0 -14
- package/src/tests/cli/commands/sync.test.ts +0 -26
- package/src/tests/core/clipboard.test.ts +0 -21
- package/src/tests/core/config.test.ts +0 -21
- package/src/tests/core/diff.test.ts +0 -22
- package/src/tests/core/git.test.ts +0 -11
- package/src/tests/core/scan.test.ts +0 -13
- package/src/tests/core/schema.test.ts +0 -13
- package/src/tests/core/validation.test.ts +0 -13
- package/src/tests/core/write.test.ts +0 -15
package/core/vm.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInVm = void 0;
|
|
4
|
+
// src/core/vm.ts
|
|
5
|
+
const vm2_1 = require("vm2");
|
|
6
|
+
function runInVm(code, sandbox = {}) {
|
|
7
|
+
const vm = new vm2_1.NodeVM({
|
|
8
|
+
console: 'inherit',
|
|
9
|
+
sandbox,
|
|
10
|
+
require: {
|
|
11
|
+
external: true,
|
|
12
|
+
builtin: ['*'],
|
|
13
|
+
},
|
|
14
|
+
wrapper: 'commonjs',
|
|
15
|
+
timeout: 1000
|
|
16
|
+
});
|
|
17
|
+
const script = new vm2_1.VMScript(code);
|
|
18
|
+
return vm.run(script);
|
|
19
|
+
}
|
|
20
|
+
exports.runInVm = runInVm;
|
package/core/vm.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/core/vm.ts
|
|
2
|
+
import { NodeVM, VMScript } from 'vm2';
|
|
3
|
+
|
|
4
|
+
export function runInVm(code: string, sandbox: Record<string, any> = {}) {
|
|
5
|
+
const vm = new NodeVM({
|
|
6
|
+
console: 'inherit',
|
|
7
|
+
sandbox,
|
|
8
|
+
require: {
|
|
9
|
+
external: true,
|
|
10
|
+
builtin: ['*'],
|
|
11
|
+
},
|
|
12
|
+
wrapper: 'commonjs',
|
|
13
|
+
timeout: 1000
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const script = new VMScript(code);
|
|
17
|
+
return vm.run(script);
|
|
18
|
+
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.copy = void 0;
|
|
4
4
|
const scan_1 = require("../../core/scan");
|
|
5
5
|
const clipboard_1 = require("../../core/clipboard");
|
|
6
|
-
function copy(input) {
|
|
6
|
+
async function copy(input) {
|
|
7
7
|
let snapshot;
|
|
8
8
|
if (Array.isArray(input)) {
|
|
9
9
|
snapshot = input.map(path => {
|
|
@@ -15,10 +15,9 @@ function copy(input) {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
|
|
19
|
-
snapshot = stat.length === 1 ? stat : (0, scan_1.scanDir)(input);
|
|
18
|
+
snapshot = (0, scan_1.scanDir)(input);
|
|
20
19
|
}
|
|
21
20
|
const clipboardJSON = JSON.stringify(snapshot, null, 2); // <- garante JSON válido
|
|
22
|
-
(0, clipboard_1.copyToClipboard)(clipboardJSON);
|
|
21
|
+
await (0, clipboard_1.copyToClipboard)(clipboardJSON);
|
|
23
22
|
}
|
|
24
23
|
exports.copy = copy;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.paste = void 0;
|
|
4
7
|
// src/cli/commands/paste.ts
|
|
5
8
|
const write_1 = require("../../core/write");
|
|
6
9
|
const clipboard_1 = require("../../core/clipboard");
|
|
10
|
+
const cleanCodeBlock_1 = __importDefault(require("../../utils/cleanCodeBlock"));
|
|
7
11
|
async function paste(dir) {
|
|
8
12
|
try {
|
|
9
13
|
const content = await (0, clipboard_1.readClipboard)();
|
|
@@ -12,8 +16,8 @@ async function paste(dir) {
|
|
|
12
16
|
}
|
|
13
17
|
let files;
|
|
14
18
|
try {
|
|
15
|
-
const
|
|
16
|
-
files = JSON.parse(
|
|
19
|
+
const { lang, cleaned } = (0, cleanCodeBlock_1.default)(content);
|
|
20
|
+
files = JSON.parse(cleaned);
|
|
17
21
|
}
|
|
18
22
|
catch (e) {
|
|
19
23
|
throw new Error("Clipboard content is not valid JSON");
|
|
@@ -38,8 +38,8 @@ PATCH FORMAT (STRICT)
|
|
|
38
38
|
IMPORTANT RULES
|
|
39
39
|
- Do NOT return explanations
|
|
40
40
|
- Do NOT return markdown
|
|
41
|
-
- Return ONLY valid JSON inside the "
|
|
42
|
-
- Always return within a Markdown Code Block (with "\`\`\`json" syntax highlighting)")
|
|
41
|
+
- Return ONLY valid JSON inside the \"\`\`\`\"
|
|
42
|
+
- Always return within a Markdown Code Block (with \"\`\`\`json\" syntax highlighting)\")
|
|
43
43
|
|
|
44
44
|
USER REQUEST
|
|
45
45
|
${userPrompt}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanCodeBlock = void 0;
|
|
4
|
+
function cleanCodeBlock(content) {
|
|
5
|
+
const langMatch = content.match(/^```(\w+)?/);
|
|
6
|
+
const lang = langMatch ? langMatch[1] : null;
|
|
7
|
+
let cleaned = content.replace(/^\uFEFF/, '');
|
|
8
|
+
cleaned = cleaned.replace(/^```(\w+)?\s*/, '').replace(/```$/, '');
|
|
9
|
+
cleaned = cleaned.replace(/[\u0000-\u0008\u000B-\u000C\u000E-\u001F\u007F-\u009F]/g, '');
|
|
10
|
+
cleaned = cleaned.trim();
|
|
11
|
+
return { lang, cleaned };
|
|
12
|
+
}
|
|
13
|
+
exports.cleanCodeBlock = cleanCodeBlock;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function cleanCodeBlock(content) {
|
|
4
|
+
const langMatch = content.match(/^```(\w+)?/);
|
|
5
|
+
const lang = langMatch ? langMatch[1] : null;
|
|
6
|
+
let cleaned = content.replace(/^\uFEFF/, '');
|
|
7
|
+
cleaned = cleaned.replace(/^```(\w+)?\s*/, '').replace(/```$/, '');
|
|
8
|
+
cleaned = cleaned.replace(/[\u0000-\u0008\u000B-\u000C\u000E-\u001F\u007F-\u009F]/g, '');
|
|
9
|
+
cleaned = cleaned.trim();
|
|
10
|
+
return { lang, cleaned };
|
|
11
|
+
}
|
|
12
|
+
exports.default = cleanCodeBlock;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "johankit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"clipboardy": "^5.0.2",
|
|
28
|
-
"commander": "^14.0.2"
|
|
28
|
+
"commander": "^14.0.2",
|
|
29
|
+
"js-yaml": "^4.1.1",
|
|
30
|
+
"vm2": "^3.10.0"
|
|
29
31
|
}
|
|
30
32
|
}
|
package/src/cli/commands/copy.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { scanDir } from "../../core/scan";
|
|
2
2
|
import { copyToClipboard } from "../../core/clipboard";
|
|
3
3
|
|
|
4
|
-
export function copy(input: string | string[]) {
|
|
4
|
+
export async function copy(input: string | string[]) {
|
|
5
5
|
let snapshot;
|
|
6
6
|
|
|
7
7
|
if (Array.isArray(input)) {
|
|
@@ -13,10 +13,9 @@ export function copy(input: string | string[]) {
|
|
|
13
13
|
return fileSnapshot[0];
|
|
14
14
|
});
|
|
15
15
|
} else {
|
|
16
|
-
|
|
17
|
-
snapshot = stat.length === 1 ? stat : scanDir(input);
|
|
16
|
+
snapshot = scanDir(input);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
const clipboardJSON = JSON.stringify(snapshot, null, 2); // <- garante JSON válido
|
|
21
|
-
copyToClipboard(clipboardJSON);
|
|
20
|
+
await copyToClipboard(clipboardJSON);
|
|
22
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/cli/commands/paste.ts
|
|
2
2
|
import { writeFiles } from "../../core/write";
|
|
3
3
|
import { readClipboard } from "../../core/clipboard";
|
|
4
|
+
import cleanCodeBlock from "../../utils/cleanCodeBlock";
|
|
4
5
|
|
|
5
6
|
export async function paste(dir: string) {
|
|
6
7
|
try {
|
|
@@ -12,8 +13,8 @@ export async function paste(dir: string) {
|
|
|
12
13
|
|
|
13
14
|
let files;
|
|
14
15
|
try {
|
|
15
|
-
const
|
|
16
|
-
files = JSON.parse(
|
|
16
|
+
const { lang, cleaned } = cleanCodeBlock(content)
|
|
17
|
+
files = JSON.parse(cleaned);
|
|
17
18
|
} catch (e) {
|
|
18
19
|
throw new Error("Clipboard content is not valid JSON");
|
|
19
20
|
}
|
|
@@ -37,8 +37,8 @@ PATCH FORMAT (STRICT)
|
|
|
37
37
|
IMPORTANT RULES
|
|
38
38
|
- Do NOT return explanations
|
|
39
39
|
- Do NOT return markdown
|
|
40
|
-
- Return ONLY valid JSON inside the "
|
|
41
|
-
- Always return within a Markdown Code Block (with "\`\`\`json" syntax highlighting)")
|
|
40
|
+
- Return ONLY valid JSON inside the \"\`\`\`\"
|
|
41
|
+
- Always return within a Markdown Code Block (with \"\`\`\`json\" syntax highlighting)\")
|
|
42
42
|
|
|
43
43
|
USER REQUEST
|
|
44
44
|
${userPrompt}
|
|
@@ -52,4 +52,4 @@ ${userPrompt}
|
|
|
52
52
|
process.stdout.write(template.trim());
|
|
53
53
|
process.stderr.write("\n✖ Failed to copy to clipboard (output only)\n");
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function cleanCodeBlock(content: string) {
|
|
2
|
+
const langMatch = content.match(/^```(\w+)?/);
|
|
3
|
+
const lang = langMatch ? langMatch[1] : null;
|
|
4
|
+
|
|
5
|
+
let cleaned = content.replace(/^\uFEFF/, '');
|
|
6
|
+
|
|
7
|
+
cleaned = cleaned.replace(/^```(\w+)?\s*/, '').replace(/```$/, '');
|
|
8
|
+
|
|
9
|
+
cleaned = cleaned.replace(/[\u0000-\u0008\u000B-\u000C\u000E-\u001F\u007F-\u009F]/g, '');
|
|
10
|
+
cleaned = cleaned.trim();
|
|
11
|
+
|
|
12
|
+
return { lang, cleaned };
|
|
13
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const copy_1 = require("../../../cli/commands/copy");
|
|
27
|
-
const scan = __importStar(require("../../../core/scan"));
|
|
28
|
-
const clipboard = __importStar(require("../../../core/clipboard"));
|
|
29
|
-
jest.mock('../../../core/scan');
|
|
30
|
-
jest.mock('../../../core/clipboard');
|
|
31
|
-
describe('copy', () => {
|
|
32
|
-
it('should copy single file snapshot to clipboard', () => {
|
|
33
|
-
scan.scanDir.mockReturnValue([{ path: 'file.txt', content: 'hello' }]);
|
|
34
|
-
(0, copy_1.copy)('file.txt');
|
|
35
|
-
expect(clipboard.copyToClipboard).toHaveBeenCalledWith(JSON.stringify([{ path: 'file.txt', content: 'hello' }], null, 2));
|
|
36
|
-
});
|
|
37
|
-
it('should copy multiple file snapshots to clipboard', () => {
|
|
38
|
-
scan.scanDir
|
|
39
|
-
.mockReturnValueOnce([{ path: 'file1.txt', content: 'a' }])
|
|
40
|
-
.mockReturnValueOnce([{ path: 'file2.txt', content: 'b' }]);
|
|
41
|
-
(0, copy_1.copy)(['file1.txt', 'file2.txt']);
|
|
42
|
-
expect(clipboard.copyToClipboard).toHaveBeenCalledWith(JSON.stringify([
|
|
43
|
-
{ path: 'file1.txt', content: 'a' },
|
|
44
|
-
{ path: 'file2.txt', content: 'b' }
|
|
45
|
-
], null, 2));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const paste_1 = require("../../../cli/commands/paste");
|
|
27
|
-
const clipboard = __importStar(require("../../../core/clipboard"));
|
|
28
|
-
const write = __importStar(require("../../../core/write"));
|
|
29
|
-
jest.mock('../../../core/clipboard');
|
|
30
|
-
jest.mock('../../../core/write');
|
|
31
|
-
describe('paste', () => {
|
|
32
|
-
it('should write files from clipboard JSON', async () => {
|
|
33
|
-
clipboard.readClipboard.mockResolvedValue(JSON.stringify([{ path: 'a.txt', content: 'hi' }]));
|
|
34
|
-
await (0, paste_1.paste)('dir');
|
|
35
|
-
expect(write.writeFiles).toHaveBeenCalledWith('dir', [{ path: 'a.txt', content: 'hi' }], true);
|
|
36
|
-
});
|
|
37
|
-
it('should throw on invalid JSON', async () => {
|
|
38
|
-
clipboard.readClipboard.mockResolvedValue('not json');
|
|
39
|
-
await expect((0, paste_1.paste)('dir')).rejects.toThrow('Clipboard content is not valid JSON');
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const prompt_1 = require("../../../cli/commands/prompt");
|
|
27
|
-
const scan = __importStar(require("../../../core/scan"));
|
|
28
|
-
const clipboard = __importStar(require("../../../core/clipboard"));
|
|
29
|
-
jest.mock('../../../core/scan');
|
|
30
|
-
jest.mock('../../../core/clipboard');
|
|
31
|
-
describe('prompt', () => {
|
|
32
|
-
it('should generate prompt with snapshot and copy to clipboard', async () => {
|
|
33
|
-
scan.scanDir.mockReturnValue([{ path: 'file.js', content: 'console.log(1)' }]);
|
|
34
|
-
await (0, prompt_1.prompt)('.', 'do something');
|
|
35
|
-
expect(clipboard.copyToClipboard).toHaveBeenCalled();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const sync_1 = require("../../../cli/commands/sync");
|
|
27
|
-
const scan = __importStar(require("../../../core/scan"));
|
|
28
|
-
const clipboard = __importStar(require("../../../core/clipboard"));
|
|
29
|
-
const diff = __importStar(require("../../../core/diff"));
|
|
30
|
-
const validation = __importStar(require("../../../core/validation"));
|
|
31
|
-
jest.mock('../../../core/scan');
|
|
32
|
-
jest.mock('../../../core/clipboard');
|
|
33
|
-
jest.mock('../../../core/diff');
|
|
34
|
-
jest.mock('../../../core/validation');
|
|
35
|
-
describe('sync', () => {
|
|
36
|
-
it('should apply patches and update clipboard', async () => {
|
|
37
|
-
scan.scanDir.mockReturnValue([]);
|
|
38
|
-
clipboard.copyToClipboard.mockResolvedValue(undefined);
|
|
39
|
-
validation.validatePatches.mockImplementation(p => p);
|
|
40
|
-
const input = JSON.stringify([{ type: 'create', path: 'a.txt', content: 'x' }]);
|
|
41
|
-
process.stdin.push(input);
|
|
42
|
-
process.stdin.push(null);
|
|
43
|
-
await (0, sync_1.sync)('.');
|
|
44
|
-
expect(diff.applyDiff).toHaveBeenCalled();
|
|
45
|
-
expect(clipboard.copyToClipboard).toHaveBeenCalledTimes(2);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const clipboard_1 = require("../../../core/clipboard");
|
|
4
|
-
jest.mock('child_process', () => ({
|
|
5
|
-
spawn: jest.fn(() => ({
|
|
6
|
-
stdin: { write: jest.fn(), end: jest.fn() },
|
|
7
|
-
stdout: { on: jest.fn() },
|
|
8
|
-
stderr: { on: jest.fn() },
|
|
9
|
-
on: jest.fn((event, cb) => { if (event === 'close')
|
|
10
|
-
cb(0); })
|
|
11
|
-
}))
|
|
12
|
-
}));
|
|
13
|
-
describe('clipboard', () => {
|
|
14
|
-
it('should copy to clipboard', async () => {
|
|
15
|
-
await expect((0, clipboard_1.copyToClipboard)('hi')).resolves.toBeUndefined();
|
|
16
|
-
});
|
|
17
|
-
it('should read from clipboard', async () => {
|
|
18
|
-
await expect((0, clipboard_1.readClipboard)()).resolves.toBe('');
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const config_1 = require("../../../core/config");
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const js_yaml_1 = require("js-yaml");
|
|
9
|
-
jest.mock('fs');
|
|
10
|
-
jest.mock('js-yaml');
|
|
11
|
-
describe('loadConfig', () => {
|
|
12
|
-
it('should return defaults if file missing', () => {
|
|
13
|
-
fs_1.default.readFileSync.mockImplementation(() => { throw { code: 'ENOENT' }; });
|
|
14
|
-
const config = (0, config_1.loadConfig)('.');
|
|
15
|
-
expect(config.ignore).toContain('.git');
|
|
16
|
-
});
|
|
17
|
-
it('should merge user ignore', () => {
|
|
18
|
-
fs_1.default.readFileSync.mockReturnValue('ignore:\n - test');
|
|
19
|
-
js_yaml_1.load.mockReturnValue({ ignore: ['test'] });
|
|
20
|
-
const config = (0, config_1.loadConfig)('.');
|
|
21
|
-
expect(config.ignore).toContain('test');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const diff_1 = require("../../../core/diff");
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
jest.mock('fs');
|
|
9
|
-
describe('applyDiff', () => {
|
|
10
|
-
it('should handle create and modify', () => {
|
|
11
|
-
const patches = [
|
|
12
|
-
{ type: 'create', path: 'a.txt', content: 'x' },
|
|
13
|
-
{ type: 'modify', path: 'b.txt', content: 'y' }
|
|
14
|
-
];
|
|
15
|
-
(0, diff_1.applyDiff)('.', patches);
|
|
16
|
-
expect(fs_1.default.writeFileSync).toHaveBeenCalledTimes(2);
|
|
17
|
-
});
|
|
18
|
-
it('should handle delete', () => {
|
|
19
|
-
fs_1.default.existsSync.mockReturnValue(true);
|
|
20
|
-
const patches = [{ type: 'delete', path: 'c.txt' }];
|
|
21
|
-
(0, diff_1.applyDiff)('.', patches);
|
|
22
|
-
expect(fs_1.default.unlinkSync).toHaveBeenCalledWith('./c.txt');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const git_1 = require("../../../core/git");
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
jest.mock('child_process');
|
|
6
|
-
describe('ensureGitCommit', () => {
|
|
7
|
-
it('should call git commands without crashing', () => {
|
|
8
|
-
child_process_1.execSync.mockImplementation(() => '');
|
|
9
|
-
expect(() => (0, git_1.ensureGitCommit)()).not.toThrow();
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const scan_1 = require("../../../core/scan");
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
jest.mock('fs');
|
|
9
|
-
describe('scanDir', () => {
|
|
10
|
-
it('should scan files with default ignores', () => {
|
|
11
|
-
fs_1.default.readdirSync.mockReturnValue([{ name: 'a.txt', isDirectory: () => false }]);
|
|
12
|
-
fs_1.default.readFileSync.mockReturnValue('content');
|
|
13
|
-
const files = (0, scan_1.scanDir)('.');
|
|
14
|
-
expect(files[0].path).toBe('a.txt');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schema_1 = require("../../../core/schema");
|
|
4
|
-
describe('validatePatches', () => {
|
|
5
|
-
it('should validate correct patches', () => {
|
|
6
|
-
const patches = [{ type: 'create', path: 'a.txt', content: 'x' }];
|
|
7
|
-
expect((0, schema_1.validatePatches)(patches)).toEqual(patches);
|
|
8
|
-
});
|
|
9
|
-
it('should throw on invalid patches', () => {
|
|
10
|
-
const patches = [{ type: 'invalid', path: 'a.txt', content: 'x' }];
|
|
11
|
-
expect(() => (0, schema_1.validatePatches)(patches)).toThrow();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const validation_1 = require("../../../core/validation");
|
|
4
|
-
describe('validation', () => {
|
|
5
|
-
it('validates correct array', () => {
|
|
6
|
-
const input = [{ type: 'create', path: 'a.txt', content: 'x' }];
|
|
7
|
-
expect((0, validation_1.validatePatches)(input)).toEqual(input);
|
|
8
|
-
});
|
|
9
|
-
it('throws on missing content', () => {
|
|
10
|
-
const input = [{ type: 'create', path: 'a.txt' }];
|
|
11
|
-
expect(() => (0, validation_1.validatePatches)(input)).toThrow();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const write_1 = require("../../../core/write");
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const git = __importStar(require("../../../core/git"));
|
|
32
|
-
jest.mock('fs');
|
|
33
|
-
jest.mock('../../../core/git');
|
|
34
|
-
describe('writeFiles', () => {
|
|
35
|
-
it('should write files and commit', () => {
|
|
36
|
-
const files = [{ path: 'a.txt', content: 'x' }];
|
|
37
|
-
(0, write_1.writeFiles)('.', files, true);
|
|
38
|
-
expect(fs_1.default.writeFileSync).toHaveBeenCalledWith('./a.txt', 'x', 'utf8');
|
|
39
|
-
expect(git.ensureGitCommit).toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
});
|