Skip to content

Commit

Permalink
feat(browser): add git plugin to @slangroom/browser
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino committed Aug 27, 2024
1 parent f6ea21c commit 5e3f8b6
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"dependencies": {
"@slangroom/core": "workspace:*",
"@slangroom/deps": "workspace:*",
"@slangroom/git": "workspace:*",
"@slangroom/helpers": "workspace:*",
"@slangroom/http": "workspace:*",
"@slangroom/json-schema": "workspace:*",
"@slangroom/pocketbase": "workspace:*",
"@slangroom/qrcode": "workspace:*"
"@slangroom/qrcode": "workspace:*",
"buffer": "^6.0.3"
},
"version": "1.39.0",
"repository": "https://github.com/dyne/slangroom",
Expand Down Expand Up @@ -40,10 +42,13 @@
"devDependencies": {
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.4",
"esbuild": "^0.21.4"
"@types/path-browserify": "^1.0.3",
"@zenfs/core": "^0.16.4",
"esbuild": "^0.21.4",
"path-browserify": "^1.0.1"
},
"scripts": {
"build": "pnpm exec esbuild --bundle src/index.ts --outfile=build/slangroom.js --target=es2016 --external:fs --external:path --external:crypto && cp build/slangroom.js public"
"build": "pnpm exec esbuild --bundle src/index.ts --outfile=build/slangroom.js --target=ESNext --external:crypto --alias:fs=@zenfs/core --alias:path=path-browserify && cp build/slangroom.js public"
},
"engines": {
"node": "^18.20.0 || ^20.10.0 || ^22"
Expand Down
25 changes: 25 additions & 0 deletions pkg/browser/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h1>Test http</h1>
<div id="test-json-schema"></div>
<div id="test-pocketbase"></div>
<div id="test-pocketbase-2"></div>
<div id="test-git"></div>
<script>
const script = `
Rule unknown ignore
Expand Down Expand Up @@ -117,6 +118,30 @@ <h1>Test http</h1>
.then((r) => {
Pocketbase2ResDiv.innerText = JSON.stringify(r.result);
})}, 3000);

//
const scriptGit = `
Rule unknown ignore
Given I connect to 'url' and send path 'path' and clone repository
Given I open 'path' and verify git repository
Given I have a 'string' named 'checked'
Then print the data
`

const GitResDiv = document.getElementById('test-git');

slangroom
.execute(scriptGit, {
data:{
url: "https://cors.isomorphic-git.org/github.com/srfsh/dumb",
path: "slangroom",
checked: "true"
}
})
.then((r) => {
GitResDiv.innerText = JSON.stringify(r.result);
});
</script>
</body>
</html>
10 changes: 10 additions & 0 deletions pkg/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@

import { Slangroom, version as coreVersion } from '@slangroom/core';
import { qrcode, version as qrcodeVersion } from '@slangroom/qrcode';
import { git, version as gitVersion } from '@slangroom/git';
import { http, version as httpVersion } from '@slangroom/http';
import { pocketbase, version as pocketbaseVersion } from '@slangroom/pocketbase';
import { helpers, version as helpersVersion } from '@slangroom/helpers';
import { JSONSchema, version as jsonSchemaVersion } from '@slangroom/json-schema';
import { zenroomVersion } from '@slangroom/deps/zenroom';
import packageJson from '@slangroom/browser/package.json' with { type: 'json' };

// web dependencies
import { Buffer } from 'buffer';

export const version = packageJson.version;

const plugins_dict = {
git: {
plugin: git,
version: gitVersion
},
http: {
plugin: http,
version: httpVersion
Expand Down Expand Up @@ -51,4 +59,6 @@ const slangroom = new Slangroom(plugins);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).slangroom = slangroom; // instead of casting window to any, you can extend the Window interface: https://stackoverflow.com/a/43513740/5433572

window.Buffer = Buffer;

console.log(welcome_message);
4 changes: 4 additions & 0 deletions pkg/browser/tests/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ test('check results of slangroom', async ({ page }) => {
await expect(page.locator('#test-pocketbase-2')).toContainText(
"{\"output\":{\"name\":\"test organization\"}}"
);

await expect(page.locator('#test-git')).toContainText(
"{\"checked\":\"true\"}"
);
});
Loading

0 comments on commit 5e3f8b6

Please sign in to comment.