-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
2,897 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defaultConfig } from "@caido/eslint-config"; | ||
|
||
export default [ | ||
...defaultConfig({ | ||
vue: false, | ||
stylistic: false, | ||
compat: false, | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import path from "path"; | ||
|
||
import { getZipFileContent } from '../../utils'; | ||
import path from 'path'; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe('build-backend', () => { | ||
import { getZipFileContent } from "../../utils"; | ||
|
||
describe("build-backend", () => { | ||
it("should have manifest.json file", async () => { | ||
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip'); | ||
|
||
const manifestJsonContent = await getZipFileContent(zipPath, 'manifest.json'); | ||
|
||
expect(manifestJsonContent).toEqual(JSON.stringify({ | ||
"id": "build-backend", | ||
"name": "Backend", | ||
"version": "1.0.0", | ||
"description": "Backend plugin", | ||
"author": { | ||
"name": "John Doe", | ||
"email": "[email protected]", | ||
"url": "https://example.com" | ||
}, | ||
"plugins": [ | ||
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip"); | ||
|
||
const manifestJsonContent = await getZipFileContent( | ||
zipPath, | ||
"manifest.json", | ||
); | ||
|
||
expect(manifestJsonContent).toEqual( | ||
JSON.stringify( | ||
{ | ||
"id": "backend", | ||
"kind": "backend", | ||
"name": "backend", | ||
"entrypoint": "backend/index.js", | ||
"runtime": "javascript" | ||
} | ||
] | ||
}, undefined, 2)); | ||
id: "build-backend", | ||
name: "Backend", | ||
version: "1.0.0", | ||
description: "Backend plugin", | ||
author: { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
url: "https://example.com", | ||
}, | ||
plugins: [ | ||
{ | ||
id: "backend", | ||
kind: "backend", | ||
name: "backend", | ||
entrypoint: "backend/index.js", | ||
runtime: "javascript", | ||
}, | ||
], | ||
}, | ||
undefined, | ||
2, | ||
), | ||
); | ||
}); | ||
|
||
it("should have index.js file", async () => { | ||
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip'); | ||
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip"); | ||
|
||
const indexJsContent = (await getZipFileContent(zipPath, 'backend/index.js'))?.replace(/\s+/g, ''); | ||
const indexJsContent = ( | ||
await getZipFileContent(zipPath, "backend/index.js") | ||
)?.replace(/\s+/g, ""); | ||
|
||
const expectedContent = ` | ||
//packages/backend/src/index.ts | ||
|
@@ -43,7 +55,7 @@ describe('build-backend', () => { | |
export { | ||
init | ||
}; | ||
`.replace(/\s+/g, ''); | ||
`.replace(/\s+/g, ""); | ||
|
||
expect(indexJsContent).toEqual(expectedContent); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ export default { | |
kind: "backend", | ||
id: "backend", | ||
root: "./packages/backend", | ||
} | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import path from "path"; | ||
|
||
import { getZipFileContent } from '../../../playgrounds/utils'; | ||
import path from 'path'; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe('build-frontend', () => { | ||
import { getZipFileContent } from "../../../playgrounds/utils"; | ||
|
||
describe("build-frontend", () => { | ||
it("should have manifest.json file", async () => { | ||
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip'); | ||
|
||
const manifestJsonContent = await getZipFileContent(zipPath, 'manifest.json'); | ||
|
||
expect(manifestJsonContent).toEqual(JSON.stringify({ | ||
"id": "build-frontend", | ||
"name": "Frontend", | ||
"version": "1.0.0", | ||
"description": "Frontend plugin", | ||
"author": { | ||
"name": "John Doe", | ||
"email": "[email protected]", | ||
"url": "https://example.com" | ||
}, | ||
"plugins": [ | ||
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip"); | ||
|
||
const manifestJsonContent = await getZipFileContent( | ||
zipPath, | ||
"manifest.json", | ||
); | ||
|
||
expect(manifestJsonContent).toEqual( | ||
JSON.stringify( | ||
{ | ||
"id": "frontend", | ||
"kind": "frontend", | ||
"name": "frontend", | ||
"entrypoint": "frontend/index.js", | ||
"style": "frontend/index.css", | ||
"backend": null | ||
} | ||
] | ||
}, undefined, 2)); | ||
id: "build-frontend", | ||
name: "Frontend", | ||
version: "1.0.0", | ||
description: "Frontend plugin", | ||
author: { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
url: "https://example.com", | ||
}, | ||
plugins: [ | ||
{ | ||
id: "frontend", | ||
kind: "frontend", | ||
name: "frontend", | ||
entrypoint: "frontend/index.js", | ||
style: "frontend/index.css", | ||
backend: null, | ||
}, | ||
], | ||
}, | ||
undefined, | ||
2, | ||
), | ||
); | ||
}); | ||
|
||
it("should have index.js file", async () => { | ||
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip'); | ||
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip"); | ||
|
||
const indexJsContent = (await getZipFileContent(zipPath, 'frontend/index.js'))?.replace(/\s+/g, ''); | ||
const indexJsContent = ( | ||
await getZipFileContent(zipPath, "frontend/index.js") | ||
)?.replace(/\s+/g, ""); | ||
|
||
const expectedContent = ` | ||
const o = () => { | ||
|
@@ -44,16 +56,19 @@ describe('build-frontend', () => { | |
export { | ||
o as init | ||
}; | ||
`.replace(/\s+/g, ''); | ||
`.replace(/\s+/g, ""); | ||
|
||
expect(indexJsContent).toEqual(expectedContent); | ||
}); | ||
|
||
it("should have index.css file", async () => { | ||
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip'); | ||
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip"); | ||
|
||
const indexCssContent = await getZipFileContent(zipPath, 'frontend/index.css'); | ||
const indexCssContent = await getZipFileContent( | ||
zipPath, | ||
"frontend/index.css", | ||
); | ||
|
||
expect(indexCssContent).toEqual('body{background-color:red}\n'); | ||
expect(indexCssContent).toEqual("body{background-color:red}\n"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ export default { | |
kind: "frontend", | ||
id: "frontend", | ||
root: "./packages/frontend", | ||
} | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import './index.css'; | ||
import "./index.css"; | ||
|
||
export const init = () => { | ||
console.log('init'); | ||
}; | ||
console.log("init"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import JSZip from 'jszip'; | ||
import fs from 'fs/promises'; | ||
import fs from "fs/promises"; | ||
|
||
import JSZip from "jszip"; | ||
|
||
/** | ||
* Extracts the content of a specific file from a zip archive | ||
* @param zipPath - Path to the zip file | ||
* @param filePath - The internal path of the file to extract | ||
* @returns Promise resolving to the file content as a string or null if not found | ||
*/ | ||
export async function getZipFileContent(zipPath: string, filePath: string): Promise<string | null> { | ||
try { | ||
const zipBuffer = await fs.readFile(zipPath); | ||
const zip = new JSZip(); | ||
const loadedZip = await zip.loadAsync(zipBuffer); | ||
const file = loadedZip.file(filePath); | ||
|
||
if (!file) { | ||
return null; | ||
} | ||
|
||
return await file.async('string'); | ||
} catch (error) { | ||
console.error('Error extracting file from zip:', error); | ||
return null; | ||
export async function getZipFileContent( | ||
zipPath: string, | ||
filePath: string, | ||
): Promise<string | undefined> { | ||
try { | ||
const zipBuffer = await fs.readFile(zipPath); | ||
const zip = new JSZip(); | ||
const loadedZip = await zip.loadAsync(zipBuffer); | ||
const file = loadedZip.file(filePath); | ||
|
||
if (!file) { | ||
return undefined; | ||
} | ||
|
||
return await file.async("string"); | ||
} catch (error) { | ||
console.error("Error extracting file from zip:", error); | ||
return undefined; | ||
} | ||
} |
Oops, something went wrong.