epos 1.1.2 → 1.1.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/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "epos",
3
- "type": "module",
4
- "version": "1.1.2",
5
- "description": "epos",
6
- "main": "index.js",
7
- "keywords": [],
3
+ "version": "1.1.3",
8
4
  "author": "imkost",
5
+ "description": "",
6
+ "keywords": [],
9
7
  "license": "MIT",
8
+ "type": "module",
9
+ "types": "./types.d.ts",
10
10
  "exports": {
11
- "./plugin-esbuild": "./src/plugin/plugin-esbuild.js",
12
- "./plugin-vite": "./src/plugin/plugin-vite.js"
11
+ "./plugin-esbuild": "./src/plugin-esbuild.js",
12
+ "./plugin-vite": "./src/plugin-vite.js"
13
+ },
14
+ "bin": {
15
+ "epos/kit": "./src/kit/kit-bin.js"
13
16
  },
14
17
  "devDependencies": {
15
- "prettier": "3.4.2"
18
+ "chokidar": "^4.0.3",
19
+ "js-yaml": "^4.1.0",
20
+ "mime": "^4.0.6",
21
+ "prettier": "^3.4.2",
22
+ "ws": "^8.18.0"
16
23
  }
17
24
  }
@@ -0,0 +1,7 @@
1
+ export default {
2
+ semi: false,
3
+ singleQuote: true,
4
+ arrowParens: 'avoid',
5
+ quoteProps: 'preserve',
6
+ printWidth: 87,
7
+ }
@@ -0,0 +1,105 @@
1
+ console.log('EPOS/KIT BIN')
2
+ // import $fs from 'node:fs/promises'
3
+ // import $path from 'path'
4
+ // import $http from 'node:http'
5
+ // import $mime from 'mime'
6
+ // import $yaml from 'js-yaml'
7
+ // import $chokidar from 'chokidar'
8
+ // import * as $ws from 'ws'
9
+
10
+ // const $server = {
11
+ // async init() {
12
+ // const webDir = $path.resolve(import.meta.dirname, '../../../web')
13
+ // const dirs = await this._findManifestDirs(webDir)
14
+ // await this._start(dirs)
15
+
16
+ // const server = $http.createServer(async (req, res) => {
17
+ // const pkgName = req.url.split('/')[1]
18
+ // const dir = dirs.find(({ name }) => name === pkgName)
19
+ // if (!dir) {
20
+ // res.writeHead(404, { 'Content-Type': 'text/plain' })
21
+ // res.end('404: File Not Found')
22
+ // return
23
+ // }
24
+ // const path = req.url.split('/').slice(2).join('/')
25
+ // const filePath = $path.join(dir.dir, path)
26
+ // const contentType = $mime.getType(filePath) || 'application/octet-stream'
27
+
28
+ // try {
29
+ // const data = await $fs.readFile(filePath)
30
+ // res.writeHead(200, { 'Content-Type': contentType })
31
+ // res.end(data)
32
+ // } catch (e) {
33
+ // if (e.code === 'ENOENT') {
34
+ // res.writeHead(404, { 'Content-Type': 'text/plain' })
35
+ // res.end('404: File Not Found')
36
+ // } else {
37
+ // res.writeHead(500, { 'Content-Type': 'text/plain' })
38
+ // res.end('500: Internal Server Error')
39
+ // }
40
+ // }
41
+ // })
42
+
43
+ // const PORT = 3098
44
+ // server.listen(PORT, () => {
45
+ // console.log(`Server running at http://localhost:${PORT}/`)
46
+ // })
47
+ // },
48
+
49
+ // async _findManifestDirs(dir) {
50
+ // const results = []
51
+ // const variants = ['epos.json', 'epos.yaml', 'epos.yml']
52
+ // const entries = await $fs.readdir(dir, { withFileTypes: true })
53
+
54
+ // const manifestEntry = entries.find(e => e.isFile() && variants.includes(e.name))
55
+ // if (manifestEntry) {
56
+ // const path = $path.join(dir, manifestEntry.name)
57
+ // const content = await $fs.readFile(path, 'utf-8')
58
+ // const isJson = path.endsWith('.json')
59
+ // const manifest = isJson ? JSON.parse(content) : $yaml.load(content)
60
+ // if (!manifest.name) throw new Error(`no name in ${path}`)
61
+ // results.push({ name: manifest.name, dir })
62
+ // }
63
+
64
+ // for (const entry of entries) {
65
+ // if (!entry.isDirectory()) continue
66
+ // if (entry.name.startsWith('.')) continue
67
+ // if (entry.name === 'node_modules') continue
68
+ // const subDir = $path.join(dir, entry.name)
69
+ // const subResults = await this._findManifestDirs(subDir)
70
+ // results.push(...subResults)
71
+ // }
72
+
73
+ // return results
74
+ // },
75
+
76
+ // async _start(dirs, port = 3099) {
77
+ // const wss = new $ws.WebSocketServer({ port }, () => {
78
+ // console.log(`WebSocket server started on ws://localhost:${port}`)
79
+ // })
80
+
81
+ // const manifestDirs = dirs
82
+
83
+ // manifestDirs.forEach(({ dir, name }) => {
84
+ // const watcher = $chokidar.watch(dir, {
85
+ // ignored: /(node_modules|\.git)/,
86
+ // ignoreInitial: true,
87
+ // })
88
+
89
+ // const broadcast = path => {
90
+ // console.log('change', path)
91
+ // const data = JSON.stringify({ name, path: $path.relative(dir, path) })
92
+ // for (const client of wss.clients) {
93
+ // if (client.readyState !== 1) continue
94
+ // client.send(data)
95
+ // }
96
+ // }
97
+
98
+ // watcher.on('add', p => broadcast(p))
99
+ // watcher.on('change', p => broadcast(p))
100
+ // watcher.on('unlink', p => broadcast(p))
101
+ // })
102
+ // },
103
+ // }
104
+
105
+ // $server.init()
@@ -2,7 +2,7 @@ import $path from 'path'
2
2
  const dirname = import.meta.dirname
3
3
 
4
4
  export default {
5
- name: 'epos/esbuild-plugin',
5
+ name: 'epos-plugin/esbuild',
6
6
  setup(build) {
7
7
  // react
8
8
  build.onResolve({ filter: /^react$/ }, () => ({
@@ -2,7 +2,7 @@ import $path from 'path'
2
2
  const dirname = import.meta.dirname
3
3
 
4
4
  export default {
5
- name: 'epos/vite-plugin',
5
+ name: 'epos-plugin/vite',
6
6
  enforce: 'pre',
7
7
  resolveId(source) {
8
8
  // react
package/types.d.ts ADDED
@@ -0,0 +1,112 @@
1
+ declare var Self: {
2
+ // base
3
+ name: string
4
+ state: { [key: string]: any }
5
+ storage: EposStorage
6
+ on: (event: string, callback: (...args: any[]) => any) => void
7
+ off: (event: string, callback?: (...args: any[]) => any) => void
8
+ send: (event: string, ...args: any[]) => Promise<any>
9
+ call: (event: string, ...args: any[]) => Promise<any>
10
+ is: { tab: boolean; popup: boolean; sidePanel: boolean; background: boolean }
11
+ use: (packageName: string) => any
12
+
13
+ // ui
14
+ render: (what: any, container?: HTMLElement | ShadowRoot) => void
15
+ portal: (vnode: Object, container: HTMLElement | ShadowRoot) => void
16
+ component: EposComponent
17
+ root: HTMLElement
18
+ shadow: ShadowRoot
19
+
20
+ // unit
21
+ unit: (name: string, schema: EposUnitSchema) => Function
22
+ hydrate: (target: any) => void
23
+
24
+ // files
25
+ files: EposFiles
26
+
27
+ // fetcher
28
+ fetcher: EposFetcher
29
+
30
+ // libs
31
+ react: Object
32
+ reactJsxRuntime: Object
33
+ reactDom: Object
34
+ reactDomClient: Object
35
+ mobx: Object
36
+ mobxReact: Object
37
+ }
38
+
39
+ // base
40
+ declare var state: typeof Self.state
41
+ declare var storage: typeof Self.storage
42
+ declare var on: typeof Self.on
43
+ declare var off: typeof Self.off
44
+ declare var send: typeof Self.send
45
+ declare var call: typeof Self.call
46
+ declare var is: typeof Self.is
47
+ declare var use: typeof Self.use
48
+
49
+ // ui
50
+ declare var render: typeof Self.render
51
+ declare var portal: typeof Self.portal
52
+ declare var component: typeof Self.component
53
+ declare var root: typeof Self.root
54
+ declare var shadow: typeof Self.shadow
55
+
56
+ // unit
57
+ declare var unit: typeof Self.unit
58
+ declare var hydrate: typeof Self.hydrate
59
+
60
+ // files
61
+ declare var files: typeof Self.files
62
+
63
+ // fetcher
64
+ declare var fetcher: typeof Self.fetcher
65
+
66
+ // libs
67
+ declare var react: typeof Self.react
68
+ declare var reactJsxRuntime: typeof Self.reactJsxRuntime
69
+ declare var reactDom: typeof Self.reactDom
70
+ declare var reactDomClient: typeof Self.reactDomClient
71
+ declare var mobx: typeof Self.mobx
72
+ declare var mobxReact: typeof Self.mobxReact
73
+
74
+ type EposStorage = EposStorageBase & {
75
+ connect: (name: string) => EposStorageBase
76
+ }
77
+
78
+ type EposStorageBase = {
79
+ get: (key: string) => Promise<any>
80
+ set: (key: string, value: any) => Promise<void>
81
+ keys: () => Promise<string[]>
82
+ remove: (key: string) => Promise<void>
83
+ clear: () => Promise<void>
84
+ }
85
+
86
+ type EposComponent = {
87
+ (name: string, schema: EposComponentSchema): any
88
+ (name: string, render: Function): any
89
+ (schema: EposComponentSchema): any
90
+ (render: Function): any
91
+ }
92
+
93
+ type EposComponentSchema = {}
94
+
95
+ type EposUnitSchema = {}
96
+
97
+ type EposFiles = {
98
+ get: (name: string) => Promise<Blob>
99
+ url: (name: string) => Promise<string>
100
+ text: (name: string) => Promise<string>
101
+ }
102
+
103
+ type EposFetcher = {
104
+ text: (url: string, opts?: RequestInit) => Promise<string>
105
+ json: (url: string, opts?: RequestInit) => Promise<string>
106
+ blob: (url: string, opts?: RequestInit) => Promise<Blob>
107
+ }
108
+
109
+ // declare function unit<T extends { constructor: (...args: any[]) => void }>(
110
+ // name: string,
111
+ // definition: T & ThisType<T>,
112
+ // ): (...args: Parameters<T['constructor']>) => T
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "semi": false,
3
- "singleQuote": true,
4
- "arrowParens": "avoid",
5
- "quoteProps": "preserve",
6
- "printWidth": 87
7
- }