@tothalex/nulljs 0.0.48 → 0.0.54

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.
Files changed (42) hide show
  1. package/package.json +25 -32
  2. package/scripts/install-server.js +0 -199
  3. package/src/commands/api.ts +0 -16
  4. package/src/commands/auth.ts +0 -54
  5. package/src/commands/create.ts +0 -43
  6. package/src/commands/deploy.ts +0 -160
  7. package/src/commands/dev/function/index.ts +0 -221
  8. package/src/commands/dev/function/utils.ts +0 -99
  9. package/src/commands/dev/index.tsx +0 -126
  10. package/src/commands/dev/logging-manager.ts +0 -87
  11. package/src/commands/dev/server/index.ts +0 -48
  12. package/src/commands/dev/server/utils.ts +0 -37
  13. package/src/commands/dev/ui/components/scroll-area.tsx +0 -141
  14. package/src/commands/dev/ui/components/tab-bar.tsx +0 -67
  15. package/src/commands/dev/ui/index.tsx +0 -71
  16. package/src/commands/dev/ui/logging-context.tsx +0 -76
  17. package/src/commands/dev/ui/tabs/functions-tab.tsx +0 -35
  18. package/src/commands/dev/ui/tabs/server-tab.tsx +0 -36
  19. package/src/commands/dev/ui/tabs/vite-tab.tsx +0 -35
  20. package/src/commands/dev/ui/use-logging.tsx +0 -34
  21. package/src/commands/dev/vite/index.ts +0 -54
  22. package/src/commands/dev/vite/utils.ts +0 -71
  23. package/src/commands/host.ts +0 -339
  24. package/src/commands/index.ts +0 -8
  25. package/src/commands/profile.ts +0 -189
  26. package/src/commands/secret.ts +0 -79
  27. package/src/index.ts +0 -346
  28. package/src/lib/api.ts +0 -189
  29. package/src/lib/bundle/external.ts +0 -23
  30. package/src/lib/bundle/function/index.ts +0 -46
  31. package/src/lib/bundle/index.ts +0 -2
  32. package/src/lib/bundle/react/index.ts +0 -2
  33. package/src/lib/bundle/react/spa.ts +0 -77
  34. package/src/lib/bundle/react/ssr/client.ts +0 -93
  35. package/src/lib/bundle/react/ssr/config.ts +0 -77
  36. package/src/lib/bundle/react/ssr/index.ts +0 -4
  37. package/src/lib/bundle/react/ssr/props.ts +0 -71
  38. package/src/lib/bundle/react/ssr/server.ts +0 -83
  39. package/src/lib/bundle/types.ts +0 -4
  40. package/src/lib/config.ts +0 -347
  41. package/src/lib/deployment.ts +0 -244
  42. package/src/lib/update-server.ts +0 -262
package/package.json CHANGED
@@ -1,46 +1,39 @@
1
1
  {
2
2
  "name": "@tothalex/nulljs",
3
- "module": "index.ts",
4
- "version": "0.0.48",
3
+ "module": "dist/index.js",
4
+ "version": "0.0.54",
5
5
  "type": "module",
6
6
  "bin": {
7
- "nulljs": "./src/index.ts"
7
+ "nulljs": "./dist/cli.js"
8
8
  },
9
9
  "scripts": {
10
- "postinstall": "bun scripts/install-server.js"
10
+ "dev": "bun run src/cli.ts dev",
11
+ "build": "bun build src/cli.ts --outdir dist --target bun --external @clack/prompts --external @opentui/core --external @opentui/react --external @tailwindcss/vite --external @vitejs/plugin-react --external chalk --external commander --external react --external vite --external lightningcss --external fsevents"
11
12
  },
12
- "files": [
13
- "src",
14
- "scripts"
15
- ],
16
13
  "devDependencies": {
17
- "@eslint/js": "^9.20.0",
18
- "@types/bun": "1.2.16",
19
- "@types/degit": "^2.8.6",
20
- "@types/mime-types": "^2.1.4",
21
- "@types/yargs": "^17.0.33",
22
- "eslint": "^9.20.1",
23
- "rollup": "^4.30.1",
24
- "typescript-eslint": "^8.24.0"
14
+ "@types/bun": "latest",
15
+ "@types/react": "^19.2.3"
25
16
  },
26
17
  "peerDependencies": {
27
- "typescript": "~5.7.2"
18
+ "typescript": "^5"
19
+ },
20
+ "optionalDependencies": {
21
+ "@tothalex/nulljs-darwin-arm64": "^0.0.79",
22
+ "@tothalex/nulljs-linux-arm64": "^0.0.79",
23
+ "@tothalex/nulljs-linux-x64": "^0.0.79"
28
24
  },
25
+ "files": [
26
+ "dist"
27
+ ],
29
28
  "dependencies": {
30
- "@tailwindcss/vite": "^4.1.11",
31
- "@types/react": "^19.1.11",
32
- "@vitejs/plugin-react": "^4.3.4",
33
- "@vitejs/plugin-react-swc": "^3.8.0",
34
- "chalk": "^5.4.1",
35
- "chokidar": "^4.0.3",
36
- "degit": "^2.8.4",
37
- "execa": "^9.6.0",
38
- "glob": "^11.0.3",
39
- "ink": "^6.5.1",
40
- "mime-types": "^2.1.35",
41
- "react": "^19.1.1",
42
- "tar": "^7.5.2",
43
- "vite": "^7.0.0",
44
- "yargs": "^17.7.2"
29
+ "@clack/prompts": "^0.11.0",
30
+ "@opentui/core": "^0.1.62",
31
+ "@opentui/react": "^0.1.62",
32
+ "@tailwindcss/vite": "^4.1.18",
33
+ "@vitejs/plugin-react": "^5.1.2",
34
+ "chalk": "^5.6.2",
35
+ "commander": "^14.0.2",
36
+ "react": "^19.2.3",
37
+ "vite": "^7.3.0"
45
38
  }
46
39
  }
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- const https = require('https')
4
- const fs = require('fs')
5
- const path = require('path')
6
- const { createWriteStream } = require('fs')
7
- const tar = require('tar')
8
-
9
- // --- Configuration ---
10
- const S3_BASE_URL = 'https://nulljs.s3.eu-north-1.amazonaws.com'
11
- const S3_PREFIX = 'releases/'
12
- const DOWNLOAD_BASE_URL = `${S3_BASE_URL}/${S3_PREFIX}`
13
- // ---------------------
14
-
15
- function getPlatformInfo() {
16
- const platform = process.platform
17
- const arch = process.arch
18
-
19
- const platformMap = {
20
- linux: {
21
- x64: 'x86_64-unknown-linux-gnu',
22
- arm64: 'aarch64-unknown-linux-gnu'
23
- },
24
- darwin: {
25
- x64: 'x86_64-apple-darwin',
26
- arm64: 'aarch64-apple-darwin'
27
- }
28
- }
29
-
30
- const target = platformMap[platform]?.[arch]
31
- if (!target) {
32
- throw new Error(`Unsupported platform: ${platform}-${arch}`)
33
- }
34
-
35
- const extension = '.tar.gz'
36
- const binaryName = 'server'
37
-
38
- return { target, extension, binaryName }
39
- }
40
-
41
- // Helper to fetch XML and return response data
42
- async function fetchXml(url) {
43
- return new Promise((resolve, reject) => {
44
- https
45
- .get(url, (res) => {
46
- if (res.statusCode !== 200) {
47
- reject(
48
- new Error(`S3 Request Failed: ${res.statusCode}. Check if public listing is enabled.`)
49
- )
50
- return
51
- }
52
- let data = ''
53
- res.on('data', (chunk) => (data += chunk))
54
- res.on('end', () => resolve(data))
55
- })
56
- .on('error', reject)
57
- })
58
- }
59
-
60
- /**
61
- * Lists the S3 prefix, parses the XML, and determines the latest version tag.
62
- */
63
- async function getLatestVersionFromS3() {
64
- // Query S3 for folders using delimiter and prefix
65
- const listUrl = `${S3_BASE_URL}/?delimiter=/&prefix=${S3_PREFIX}`
66
- const xmlData = await fetchXml(listUrl)
67
-
68
- // Regex to find all CommonPrefixes entries (the version folders)
69
- const prefixRegex = /<Prefix>(releases\/v[^<]+)\/<\/Prefix>/g
70
- const versionFolders = []
71
- let match
72
-
73
- while ((match = prefixRegex.exec(xmlData)) !== null) {
74
- // Extract version part: "releases/v1.0.0/" -> "v1.0.0"
75
- const fullPrefix = match[1]
76
- const version = fullPrefix.substring(S3_PREFIX.length)
77
- versionFolders.push(version)
78
- }
79
-
80
- if (versionFolders.length === 0) {
81
- throw new Error('No version folders found in S3 bucket.')
82
- }
83
-
84
- // Sort versions to find the latest (using semantic versioning logic)
85
- const sortedVersions = versionFolders.sort((a, b) => {
86
- // Strips 'v', splits by '.', and converts to number arrays for comparison
87
- const aParts = a.replace('v', '').split('.').map(Number)
88
- const bParts = b.replace('v', '').split('.').map(Number)
89
-
90
- // Compare major, minor, and patch numbers
91
- for (let i = 0; i < 3; i++) {
92
- if (aParts[i] > bParts[i]) return 1
93
- if (aParts[i] < bParts[i]) return -1
94
- }
95
- return 0
96
- })
97
-
98
- // The latest version is the last one after sorting
99
- return sortedVersions[sortedVersions.length - 1]
100
- }
101
-
102
- async function downloadFile(url, destination) {
103
- return new Promise((resolve, reject) => {
104
- const file = createWriteStream(destination)
105
-
106
- https
107
- .get(url, (response) => {
108
- if (response.statusCode === 302 || response.statusCode === 301) {
109
- // Handle redirect
110
- return downloadFile(response.headers.location, destination).then(resolve).catch(reject)
111
- }
112
-
113
- if (response.statusCode !== 200) {
114
- reject(new Error(`Failed to download: ${response.statusCode}`))
115
- return
116
- }
117
-
118
- response.pipe(file)
119
-
120
- file.on('finish', () => {
121
- file.close()
122
- resolve()
123
- })
124
-
125
- file.on('error', reject)
126
- })
127
- .on('error', reject)
128
- })
129
- }
130
-
131
- async function extractArchive(archivePath, extractPath, binaryName) {
132
- // Extract tar.gz
133
- await tar.x({
134
- file: archivePath,
135
- cwd: extractPath
136
- })
137
-
138
- // Make binary executable
139
- const binaryPath = path.join(extractPath, binaryName)
140
- if (fs.existsSync(binaryPath)) {
141
- fs.chmodSync(binaryPath, '755')
142
- }
143
- }
144
-
145
- async function installServer() {
146
- try {
147
- console.log('📦 Installing nulljs server binary...')
148
-
149
- const { target, extension, binaryName } = getPlatformInfo()
150
- const binDir = path.join(__dirname, '..', 'bin')
151
- const archivePath = path.join(binDir, `server${extension}`)
152
- const binaryPath = path.join(binDir, 'server')
153
-
154
- // Create bin directory
155
- if (!fs.existsSync(binDir)) {
156
- fs.mkdirSync(binDir, { recursive: true })
157
- }
158
-
159
- // Check if binary already exists (optional optimization)
160
- if (fs.existsSync(binaryPath)) {
161
- console.log('✅ Server binary already installed')
162
- return
163
- }
164
-
165
- // 1. Determine Version from S3
166
- console.log('🔍 Checking for latest version on S3...')
167
- const version = await getLatestVersionFromS3()
168
- console.log(` Found version: ${version}`)
169
-
170
- // 2. Construct URL
171
- // URL format: https://.../releases/VERSION/nulljs-server-TARGET.tar.gz
172
- const downloadUrl = `${DOWNLOAD_BASE_URL}${version}/nulljs-server-${target}${extension}`
173
- console.log(` Downloading from: ${downloadUrl}`)
174
-
175
- // 3. Download
176
- await downloadFile(downloadUrl, archivePath)
177
- console.log('✅ Download completed')
178
-
179
- // 4. Extract
180
- console.log('📂 Extracting binary...')
181
- await extractArchive(archivePath, binDir, binaryName)
182
-
183
- // 5. Clean up archive
184
- fs.unlinkSync(archivePath)
185
-
186
- console.log('✅ nulljs server installed successfully')
187
- } catch (error) {
188
- console.error('❌ Failed to install server binary:', error.message)
189
- console.error('⚠️ You may need to build the server manually')
190
- process.exit(0)
191
- }
192
- }
193
-
194
- // Only run if called directly
195
- if (require.main === module) {
196
- installServer()
197
- }
198
-
199
- module.exports = { installServer }
@@ -1,16 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- import { saveApiUrl } from '../lib/config'
4
-
5
- const setApiUrl = (url: string, profileName?: string) => {
6
- try {
7
- saveApiUrl(url, profileName)
8
- const profileText = profileName ? ` to profile '${profileName}'` : ''
9
- console.log(chalk.green('✓'), `API URL saved${profileText}: ${chalk.blue(url)}`)
10
- } catch (error) {
11
- console.error(chalk.red('✗'), 'Failed to save API URL:', error)
12
- process.exit(1)
13
- }
14
- }
15
-
16
- export { setApiUrl }
@@ -1,54 +0,0 @@
1
- import chalk from 'chalk'
2
- import readline from 'node:readline'
3
-
4
- import { loadConfigWithProfile, saveKeys } from '../lib/config'
5
-
6
- const askQuestion = (query: string): Promise<string> => {
7
- const rl = readline.createInterface({
8
- input: process.stdin,
9
- output: process.stdout
10
- })
11
-
12
- return new Promise((resolve) =>
13
- rl.question(query, (answer) => {
14
- rl.close()
15
- resolve(answer.trim())
16
- })
17
- )
18
- }
19
-
20
- const auth = async (profileName?: string) => {
21
- const config = loadConfigWithProfile()
22
-
23
- if (config.key) {
24
- const answer = await askQuestion(
25
- 'Keys already exist. Are you sure you want to regenerate them? (Y/n): '
26
- )
27
-
28
- if (answer.toLowerCase() === 'n') {
29
- console.log(chalk.green('Public Key:'), chalk.blue(config.key.public))
30
- return
31
- }
32
- }
33
-
34
- const keyPair = await crypto.subtle.generateKey(
35
- {
36
- name: 'Ed25519',
37
- namedCurve: 'Ed25519'
38
- },
39
- true,
40
- ['sign', 'verify']
41
- )
42
-
43
- const privateKeyBuffer = await crypto.subtle.exportKey('pkcs8', keyPair.privateKey)
44
- const publicKeyBuffer = await crypto.subtle.exportKey('spki', keyPair.publicKey)
45
-
46
- const privateKey = btoa(String.fromCharCode(...new Uint8Array(privateKeyBuffer)))
47
- const publicKey = btoa(String.fromCharCode(...new Uint8Array(publicKeyBuffer)))
48
-
49
- saveKeys(privateKey, publicKey, profileName)
50
-
51
- console.log(chalk.green('Public Key:'), chalk.blue(publicKey))
52
- }
53
-
54
- export { auth }
@@ -1,43 +0,0 @@
1
- import chalk from 'chalk'
2
- import { existsSync } from 'node:fs'
3
- import degit from 'degit'
4
- import path from 'node:path'
5
-
6
- const repo = 'tothalex/nulljs-template'
7
-
8
- const modifyName = async (newName: string, packagePath: string) => {
9
- const file = Bun.file(packagePath)
10
- const packageContent = await file.text()
11
- const packageJson = JSON.parse(packageContent)
12
-
13
- packageJson.name = newName
14
-
15
- await Bun.write(packagePath, JSON.stringify(packageJson, null, 2) + '\n')
16
- }
17
-
18
- const create = async (name: string) => {
19
- if (existsSync(name)) {
20
- console.log(chalk.red('Folder already exists: ') + chalk.bgRed(name))
21
- process.exit(0)
22
- }
23
-
24
- const targetDir = path.join(process.cwd(), name)
25
-
26
- try {
27
- const emitter = degit(repo, {
28
- cache: false,
29
- force: true,
30
- verbose: true
31
- })
32
-
33
- await emitter.clone(targetDir)
34
-
35
- await modifyName(name, targetDir + '/package.json')
36
- console.log(chalk.green('Project setup completed successfully!'))
37
- } catch (error) {
38
- console.error(chalk.red('An error occurred during project creation:'))
39
- console.error(error)
40
- }
41
- }
42
-
43
- export { create }
@@ -1,160 +0,0 @@
1
- import { resolve } from 'path'
2
- import { readdir, exists, stat } from 'node:fs/promises'
3
- import chalk from 'chalk'
4
- import chokidar from 'chokidar'
5
-
6
- import { deployFunction, deployPage, isReact, isTypescript } from '../lib/deployment'
7
- import { requireProfileConfiguration } from '../lib/config'
8
-
9
- const deployFunctionsRecursively = async (functionsPath: string, force: boolean = true) => {
10
- if (!(await exists(functionsPath))) {
11
- return
12
- }
13
-
14
- const functionsStat = await stat(functionsPath)
15
- if (!functionsStat.isDirectory()) {
16
- return
17
- }
18
-
19
- const items = await readdir(functionsPath)
20
- for (const item of items) {
21
- const fullPath = `${functionsPath}/${item}`
22
- const itemStat = await stat(fullPath)
23
-
24
- if (itemStat.isDirectory()) {
25
- // Recursively process subdirectories
26
- await deployFunctionsRecursively(fullPath, force)
27
- } else if (isTypescript(item)) {
28
- const result = await deployFunction(fullPath, console, force)
29
-
30
- if (result.error) {
31
- console.log(chalk.red(`${item} deployment failed: ${result.error.message}`))
32
- } else if (result.cached) {
33
- console.log(chalk.gray(`${item} skipped (no changes)`))
34
- } else if (result.deployed) {
35
- console.log(chalk.green(`${item} deployed successfully`))
36
- }
37
- }
38
- }
39
- }
40
-
41
- const deploy = async (path?: string, force: boolean = true) => {
42
- // Ensure a profile is selected and properly configured for deployment
43
- const { profileName, config } = requireProfileConfiguration(['api', 'key'])
44
- console.log(chalk.gray(`Using profile: ${profileName}`))
45
- console.log(config.api ? chalk.gray(`API: ${config.api}`) : '')
46
- console.log(config.key?.public ? chalk.gray(`Key: ${config.key.public}`) : '')
47
-
48
- let deployPath = path
49
-
50
- // If no path provided, look for index.tsx
51
- if (!deployPath) {
52
- const indexPath = resolve('src/index.tsx')
53
- if (await exists(indexPath)) {
54
- deployPath = indexPath
55
- } else {
56
- deployPath = resolve('.')
57
- }
58
- }
59
-
60
- if (!(await exists(deployPath))) {
61
- console.log(chalk.red("Path doesn't exists: ") + chalk.bgRed(deployPath))
62
- process.exit(0)
63
- }
64
-
65
- const pathStat = await stat(deployPath)
66
-
67
- if (pathStat.isFile()) {
68
- const file = resolve(deployPath)
69
-
70
- if (isReact(file)) {
71
- console.log(`${chalk.gray('Deploying page: ')} ${chalk.green(file)}`)
72
- await deployPage(file)
73
- }
74
-
75
- // Also deploy functions directory recursively
76
- const functionsPath = resolve('src/function')
77
- await deployFunctionsRecursively(functionsPath, force)
78
-
79
- return
80
- }
81
-
82
- const dir = await readdir(deployPath)
83
- const p = resolve(deployPath)
84
- for (const file of dir) {
85
- if (isTypescript(file)) {
86
- const result = await deployFunction(`${p}/${file}`, console, force)
87
-
88
- if (result.error) {
89
- console.log(chalk.red(`${file} deployment failed: ${result.error.message}`))
90
- } else if (result.cached) {
91
- console.log(chalk.gray(`${file} skipped (no changes)`))
92
- } else if (result.deployed) {
93
- console.log(chalk.green(`${file} deployed successfully`))
94
- }
95
- }
96
-
97
- if (isReact(file)) {
98
- await deployPage(`${p}/${file}`)
99
- }
100
- }
101
-
102
- // Also deploy functions directory recursively
103
- const functionsPath = resolve('src/function')
104
- await deployFunctionsRecursively(functionsPath, force)
105
- }
106
-
107
- const onFileChange = async (file: string) => {
108
- const absolutePath = resolve(file)
109
- console.log(`File changed: ${absolutePath}`)
110
-
111
- try {
112
- const indexPage = resolve('src/index.tsx')
113
- if (await exists(indexPage)) {
114
- if (isReact(indexPage)) {
115
- await deployPage(indexPage)
116
- }
117
- }
118
-
119
- // Deploy all files in src/functions/ directory recursively
120
- const functionsPath = resolve('src/function')
121
- await deployFunctionsRecursively(functionsPath)
122
- } catch (error) {
123
- console.error(chalk.red('Deployment failed:'), error)
124
- }
125
- }
126
-
127
- const watch = async (path: string) => {
128
- // Ensure a profile is selected and properly configured for deployment
129
- const { profileName } = requireProfileConfiguration(['api', 'key'])
130
- console.log(chalk.gray(`Using profile: ${profileName}`))
131
-
132
- if (!exists(path)) {
133
- console.log(chalk.red("Path doesn't exists: ") + chalk.bgRed(path))
134
- process.exit(0)
135
- }
136
-
137
- const watcher = chokidar.watch(`${path}`, {
138
- ignored: (path) => ['node_modules', '.git'].some((s) => path.includes(s)),
139
- persistent: true,
140
- ignoreInitial: true,
141
- cwd: process.cwd()
142
- })
143
-
144
- watcher
145
- .on('add', (filePath) => onFileChange(filePath))
146
- .on('change', (filePath) => onFileChange(filePath))
147
- .on('ready', () => {
148
- console.log('Initial scan complete. Ready for changes')
149
- })
150
-
151
- process.on('SIGINT', () => {
152
- console.log('\nShutting down file watcher...')
153
- watcher.close().then(() => {
154
- console.log('File watcher stopped')
155
- process.exit(0)
156
- })
157
- })
158
- }
159
-
160
- export { deploy, watch }