vaderjs 1.4.1-lv56aadeg5 → 1.4.2-bml56
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/.editorconfig +11 -0
- package/.vscode/c_cpp_properties.json +21 -0
- package/.vscode/settings.json +12 -0
- package/README.md +35 -198
- package/binaries/Kalix/index.js +668 -0
- package/binaries/compiler/main.js +461 -0
- package/binaries/vader.js +74 -0
- package/binaries/watcher/hmr.js +40 -0
- package/client/index.d.ts +226 -0
- package/client/runtime/index.js +417 -0
- package/client/runtime/router.js +235 -0
- package/config/index.ts +68 -0
- package/index.ts +344 -0
- package/package.json +14 -25
- package/plugins/cloudflare/functions/index.js +98 -0
- package/plugins/cloudflare/toCopy/@server/Kalix/index.js +625 -0
- package/plugins/cloudflare/toCopy/@server/cloudflare_ssr/index.js +85 -0
- package/plugins/cloudflare/toCopy/node_modules/vaderjs/server/index.js +99 -0
- package/plugins/cloudflare/toCopy/src/client.js +432 -0
- package/plugins/cloudflare/toCopy/src/router.js +235 -0
- package/plugins/ssg/index.js +127 -0
- package/plugins/vercel/functions/index.ts +8 -0
- package/router/index.ts +181 -0
- package/server/index.js +129 -0
- package/vader_dev.js +177 -0
- package/@integrations/ssg.js +0 -163
- package/LICENSE +0 -21
- package/binaries/IPC/index.js +0 -277
- package/binaries/main.js +0 -1328
- package/binaries/readme.md +0 -4
- package/binaries/watcher.js +0 -74
- package/binaries/win32/check.ps1 +0 -7
- package/client/index.js +0 -441
- package/config/index.js +0 -36
- package/logo.png +0 -0
- package/runtime/router.js +0 -1
- package/runtime/vader.js +0 -1
- package/vader.js +0 -230
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Glob } from 'bun'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
const glob = new Glob("/**/*.{ts,tsx,js,jsx}", {
|
|
4
|
+
absolute: true,
|
|
5
|
+
});
|
|
6
|
+
/**
|
|
7
|
+
* @description This function generates cloudflare functions from the routes folder
|
|
8
|
+
*/
|
|
9
|
+
async function generate(){
|
|
10
|
+
let config = await import(process.cwd() + '/vader.config.js').then((config) => { return config.default })
|
|
11
|
+
let start = Date.now()
|
|
12
|
+
for(var i of glob.scanSync({cwd: process.cwd() + '/routes', absolute: true})){
|
|
13
|
+
let data = await Bun.file(i).text()
|
|
14
|
+
let method = ''
|
|
15
|
+
i = i.replaceAll('\\', '/').replace(process.cwd(), '')
|
|
16
|
+
if(!data.includes(data.match(new RegExp('export\\s+default')))){
|
|
17
|
+
throw new Error('File must have a default export')
|
|
18
|
+
}
|
|
19
|
+
data.split('\n').forEach((line, index) => {
|
|
20
|
+
if(line.includes('GET') || line.includes('POST') || line.includes('PUT') || line.includes('DELETE') && line.includes('function')){
|
|
21
|
+
line = line.replace(/export\s+default\s+async\s+function/g, line.includes('async') ? 'async function' : 'function')
|
|
22
|
+
method = line.split('function')[1].split('(')[0].trim()
|
|
23
|
+
data = data.replace(data.split('\n')[index], line)
|
|
24
|
+
data = data + `\nexport async function onRequest${method.toLowerCase().charAt(0).toUpperCase() + method.toLowerCase().slice(1)}(request){
|
|
25
|
+
let req = {
|
|
26
|
+
url: request.request.url,
|
|
27
|
+
method: request.request.method,
|
|
28
|
+
headers: request.request.headers,
|
|
29
|
+
}
|
|
30
|
+
let res = {
|
|
31
|
+
params: (param) => {
|
|
32
|
+
return request.params[param]
|
|
33
|
+
},
|
|
34
|
+
query: (param) => {
|
|
35
|
+
let url = new URL(request.request.url)
|
|
36
|
+
return url.searchParams.get(param)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let response = await ${method}({req, res})
|
|
40
|
+
return response
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
let env = `globalThis.env = {
|
|
47
|
+
|
|
48
|
+
${
|
|
49
|
+
Object.keys(config?.env).map((key) => {
|
|
50
|
+
return `${key}:"${config.env[key]}",`
|
|
51
|
+
} ).join('\n')
|
|
52
|
+
}
|
|
53
|
+
${Object.keys(process.env).map((key) => {
|
|
54
|
+
let value = process.env[key].replace(/"/g, '\\"')
|
|
55
|
+
value = value.replace(/\\n/g, '\\n') // remove new lines
|
|
56
|
+
value = value.replace(/\\r/g, '\\r') // remove carriage returns
|
|
57
|
+
value = value.replace(/\\t/g, '\\t') // remove tabs
|
|
58
|
+
value = value.replace('/\/g', '\\\\') // remove octal escape sequences
|
|
59
|
+
// remove octal escape sequences
|
|
60
|
+
value = value.replace(/\\[0-7]{1,3}/g, '');
|
|
61
|
+
return `${key}:"${value}"`
|
|
62
|
+
} ).join(',\n')
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
`
|
|
66
|
+
// make env all on one line
|
|
67
|
+
env = env.replace(/\n/g, '')
|
|
68
|
+
data = env + data
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
fs.mkdirSync(process.cwd() + '/build/functions' + i.split('/routes')[1].split('/').slice(0, -1).join('/'), { recursive: true })
|
|
72
|
+
fs.writeFileSync(process.cwd() + '/build/functions/' + i.split('/routes')[1].replace('.ts', '.js').replace('.tsx', '.js').replace('.jsx', '.js'), data)
|
|
73
|
+
|
|
74
|
+
let nodeModules = process.cwd() + '/node_modules/vaderjs/plugins/cloudflare/toCopy'
|
|
75
|
+
let glb = new Glob('**/*', {
|
|
76
|
+
absolute: true,
|
|
77
|
+
cwd: nodeModules
|
|
78
|
+
})
|
|
79
|
+
for(var file of glb.scanSync({cwd: nodeModules, absolute: true})){
|
|
80
|
+
file = file.replaceAll('\\', '/').replace(nodeModules, '')
|
|
81
|
+
if(fs.existsSync('build/' + file.split('/toCopy')[1])) continue
|
|
82
|
+
let data = await Bun.file(file).text()
|
|
83
|
+
let path = file.split('/toCopy')[1]
|
|
84
|
+
Bun.write(process.cwd() + '/build/' + path, data)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log(`\x1b[32msuccess \x1b[0m - Cloudflare Functions Compiled in: ${Date.now() - start}ms`)
|
|
88
|
+
}
|
|
89
|
+
export default {
|
|
90
|
+
name: 'Cloudflare Functions Plugin',
|
|
91
|
+
description: 'This plugin utilizes cloudflare functios for server side rendering',
|
|
92
|
+
version: '0.0.1',
|
|
93
|
+
type: "SSR",
|
|
94
|
+
init: async (path, options) => {
|
|
95
|
+
console.log(`\x1b[32mevent \x1b[0m - Cloudflare Functions Plugin Initialized`)
|
|
96
|
+
await generate()
|
|
97
|
+
}
|
|
98
|
+
}
|