Skip to content

Commit

Permalink
feat: add router plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed May 6, 2021
1 parent 7618ec6 commit 1ab5bcc
Show file tree
Hide file tree
Showing 17 changed files with 1,069 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/plugins/browser-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@garfish/garfish-sp-sandbox",
"name": "@garfish/browser-snapshot",
"version": "0.0.2",
"description": "sp-sandbox module.",
"keywords": [
Expand Down
34 changes: 3 additions & 31 deletions packages/runtime/plugins/esm-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import Garfish, { Plugin } from '@garfish/core';
import Garfish, { interfaces } from '@garfish/core';
import { assert, warn } from '@garfish/utils';

declare module '@garfish/core' {
export default interface Garfish {
// loadApp: () => void;
}
}

export default function addCjsExternalPlugin(Garfish: Garfish): Plugin {
Garfish.setExternal = setExternal;

function setExternal(
nameOrExtObj: string | Record<string, any>,
value?: any,
) {
assert(nameOrExtObj, 'Invalid parameter.');
if (typeof nameOrExtObj === 'object') {
for (const key in nameOrExtObj) {
if (Garfish.externals[key]) {
__DEV__ && warn(`The "${key}" will be overwritten in external.`);
}
Garfish.externals[key] = nameOrExtObj[key];
}
} else {
Garfish.externals[nameOrExtObj] = value;
}
}

export default function esmApp(_Garfish: Garfish): interfaces.Plugin {
return {
name: 'bb',
beforeEval(appInfo, code, env) {
env.require = (name) => Garfish.externals[name];
},
name: 'esm-app',
};
}
5 changes: 5 additions & 0 deletions packages/runtime/plugins/router/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/
node_modules/
__tests__/
api-extractor.json
.npmignore
11 changes: 11 additions & 0 deletions packages/runtime/plugins/router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `@garfish/sp-sandbox`

> TODO: description
## Usage

```
import spSandbox from '@garfish/sp-sandbox';
// TODO: DEMONSTRATE API
```
5 changes: 5 additions & 0 deletions packages/runtime/plugins/router/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import toolApp from '../src/index';

describe('sp-sandbox', () => {
it('needs tests');
});
7 changes: 7 additions & 0 deletions packages/runtime/plugins/router/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/runtime/sp-sandbox/src/index.d.ts",
"dtsRollup": {
"publicTrimmedFilePath": "./dist/sp-sandbox.d.ts"
}
}
29 changes: 29 additions & 0 deletions packages/runtime/plugins/router/dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>GarfishRouter dev</title>
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script src="./router.umd.js"></script>
<script type="text/babel">
console.log('GarfishRouter', GarfishRouter);
const { useState } = React;

function App() {
const [count, setCount] = useState(0)
return (
<div>
<p>Clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}
ReactDOM.render(<App />, document.getElementById('root'));
</script>
</body>
</html>
Loading

0 comments on commit 1ab5bcc

Please sign in to comment.