@owear/cli 0.1.0
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/LICENSE +201 -0
- package/package.json +33 -0
- package/src/ow.js +443 -0
- package/src/owear-build-native.js +131 -0
- package/template/app/main.ts +29 -0
- package/template/index.html +24 -0
- package/template/native/files.cpp +42 -0
- package/template/package.json +20 -0
- package/template/src/renderer.ts +30 -0
- package/template/tsconfig.json +12 -0
- package/template/vite.config.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owear/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI de Owear: create, dev, build",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ow": "./src/ow.js",
|
|
8
|
+
"owear-build-native": "./src/owear-build-native.js"
|
|
9
|
+
},
|
|
10
|
+
"optionalDependencies": {
|
|
11
|
+
"@owear/linux-x64-gnu": "0.1.0"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"template"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"homepage": "https://owear.dev",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/owear/owear.git",
|
|
22
|
+
"directory": "packages/cli"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "node --check src/ow.js && node --check src/owear-build-native.js"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/ow.js
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Owear Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// ow — CLI del framework Owear.
|
|
6
|
+
// ow create <dir> scaffoldea una app
|
|
7
|
+
// ow dev kernel nativo + vite dev server + sidecar Node
|
|
8
|
+
// ow build build de producción (vite build + módulos .owm)
|
|
9
|
+
//
|
|
10
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
11
|
+
import * as fs from 'node:fs'
|
|
12
|
+
import * as path from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
import { createRequire } from 'node:module'
|
|
15
|
+
|
|
16
|
+
const require = createRequire(import.meta.url)
|
|
17
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
|
|
19
|
+
const C = {
|
|
20
|
+
reset: '\x1b[0m',
|
|
21
|
+
dim: '\x1b[2m',
|
|
22
|
+
green: '\x1b[32m',
|
|
23
|
+
yellow: '\x1b[33m',
|
|
24
|
+
red: '\x1b[31m',
|
|
25
|
+
cyan: '\x1b[36m',
|
|
26
|
+
}
|
|
27
|
+
const log = (msg) => console.log(`${C.dim}[ow]${C.reset} ${msg}`)
|
|
28
|
+
const die = (msg) => {
|
|
29
|
+
console.error(`${C.red}[ow] ✗${C.reset} ${msg}`)
|
|
30
|
+
process.exit(1)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function platformPreset() {
|
|
34
|
+
switch (process.platform) {
|
|
35
|
+
case 'linux': return 'linux-release'
|
|
36
|
+
case 'win32': return 'windows-release'
|
|
37
|
+
case 'darwin': return 'macos-release'
|
|
38
|
+
default: die(`plataforma no soportada: ${process.platform}`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Nombre del paquete de runtime para la plataforma actual (null si no hay). */
|
|
43
|
+
function runtimePackageName() {
|
|
44
|
+
if (process.platform === 'linux' && process.arch === 'x64') return '@owear/linux-x64-gnu'
|
|
45
|
+
if (process.platform === 'win32' && process.arch === 'x64') return '@owear/win32-x64'
|
|
46
|
+
if (process.platform === 'darwin' && process.arch === 'arm64') return '@owear/darwin-arm64'
|
|
47
|
+
if (process.platform === 'darwin' && process.arch === 'x64') return '@owear/darwin-x64'
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Directorio del paquete de runtime instalado (o null). */
|
|
52
|
+
function runtimePackageDir() {
|
|
53
|
+
const name = runtimePackageName()
|
|
54
|
+
if (!name) return null
|
|
55
|
+
try {
|
|
56
|
+
return path.dirname(require.resolve(name + '/package.json'))
|
|
57
|
+
} catch {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Ruta(s) de los módulos stock, separadas por `path.delimiter`.
|
|
64
|
+
* - runtime npm: <pkg>/bin/modules (plano)
|
|
65
|
+
* - monorepo: cada build/<preset>/api/<nombre>/ (el loader NO recursiona)
|
|
66
|
+
*/
|
|
67
|
+
function stockModulesPath() {
|
|
68
|
+
const rt = runtimePackageDir()
|
|
69
|
+
if (rt) {
|
|
70
|
+
const m = path.join(rt, 'bin', 'modules')
|
|
71
|
+
if (fs.existsSync(m)) return m
|
|
72
|
+
}
|
|
73
|
+
const api = path.resolve(__dirname, '../../../build', platformPreset(), 'api')
|
|
74
|
+
if (fs.existsSync(api)) {
|
|
75
|
+
const dirs = fs
|
|
76
|
+
.readdirSync(api, { withFileTypes: true })
|
|
77
|
+
.filter((d) => d.isDirectory() && d.name !== 'CMakeFiles')
|
|
78
|
+
.map((d) => path.join(api, d.name))
|
|
79
|
+
if (dirs.length) return dirs.join(path.delimiter)
|
|
80
|
+
}
|
|
81
|
+
return ''
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Localiza el binario del kernel. Orden: OW_KERNEL_BIN → local → runtime npm → monorepo. */
|
|
85
|
+
function findKernelBin(cwd = process.cwd()) {
|
|
86
|
+
if (process.env.OW_KERNEL_BIN && fs.existsSync(process.env.OW_KERNEL_BIN)) {
|
|
87
|
+
return process.env.OW_KERNEL_BIN
|
|
88
|
+
}
|
|
89
|
+
const exe = process.platform === 'win32' ? 'owear.exe' : 'owear'
|
|
90
|
+
const rt = runtimePackageDir()
|
|
91
|
+
const candidates = [
|
|
92
|
+
path.join(cwd, '.owear', 'bin', exe),
|
|
93
|
+
...(rt ? [path.join(rt, 'bin', exe)] : []),
|
|
94
|
+
// monorepo en desarrollo
|
|
95
|
+
path.resolve(__dirname, '../../../build', platformPreset(), 'src', exe),
|
|
96
|
+
]
|
|
97
|
+
for (const c of candidates) if (fs.existsSync(c)) return c
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Compila el kernel si hay fuentes disponibles (repo hermano o checkout). */
|
|
102
|
+
function ensureKernelBuilt(cwd) {
|
|
103
|
+
const existing = findKernelBin(cwd)
|
|
104
|
+
if (existing) return existing
|
|
105
|
+
|
|
106
|
+
const repoRoot = path.resolve(__dirname, '../../..')
|
|
107
|
+
const hasSources = fs.existsSync(path.join(repoRoot, 'CMakeLists.txt'))
|
|
108
|
+
if (!hasSources) {
|
|
109
|
+
// El binario del kernel todavía no se distribuye como paquete npm, así que
|
|
110
|
+
// no prometemos `@owear/runtime-<platform>`: damos las salidas reales.
|
|
111
|
+
const exe = process.platform === 'win32' ? 'owear.exe' : 'owear'
|
|
112
|
+
die(
|
|
113
|
+
`no encuentro el kernel owear. Opciones:
|
|
114
|
+
· compílalo desde un checkout: cmake --preset ${platformPreset()} && cmake --build --preset ${platformPreset()}
|
|
115
|
+
· copia el binario en ${path.join(process.cwd(), '.owear', 'bin', exe)}
|
|
116
|
+
· o define OW_KERNEL_BIN=/ruta/al/owear
|
|
117
|
+
(el binario precompilado por plataforma aún no se publica en npm)`)
|
|
118
|
+
}
|
|
119
|
+
log('compilando kernel nativo (primera vez)…')
|
|
120
|
+
const preset = platformPreset()
|
|
121
|
+
for (const args of [['--preset', preset], ['--build', '--preset', preset]]) {
|
|
122
|
+
const r = spawnSync('cmake', args, { cwd: repoRoot, stdio: 'inherit' })
|
|
123
|
+
if (r.status !== 0) die('fallo al compilar el kernel')
|
|
124
|
+
}
|
|
125
|
+
return findKernelBin(cwd)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── comandos ────────────────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
async function main() {
|
|
131
|
+
const [, , cmd, ...rest] = process.argv
|
|
132
|
+
|
|
133
|
+
if (!cmd || cmd === '-h' || cmd === '--help') {
|
|
134
|
+
printHelp(); return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
switch (cmd) {
|
|
138
|
+
case 'create': return cmdCreate(rest)
|
|
139
|
+
case 'dev': return cmdDev(rest)
|
|
140
|
+
case 'build': return cmdBuild(rest)
|
|
141
|
+
case 'api': return cmdApi(rest)
|
|
142
|
+
default:
|
|
143
|
+
die(`comando desconocido: ${cmd} (usa --help)`)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function printHelp() {
|
|
148
|
+
console.log(`
|
|
149
|
+
${C.cyan}owear${C.reset} — framework desktop nativo
|
|
150
|
+
|
|
151
|
+
${C.green}ow create <dir>${C.reset} crea una app nueva
|
|
152
|
+
${C.green}ow dev${C.reset} desarrollo: vite + kernel + sidecar node
|
|
153
|
+
${C.green}ow build${C.reset} build de producción
|
|
154
|
+
${C.green}ow api list${C.reset} lista las APIs del repo y sus manifiestos
|
|
155
|
+
${C.green}ow api new <nombre>${C.reset} scaffoldea una API (api/<nombre>/ + manifiesto)
|
|
156
|
+
|
|
157
|
+
Variables útiles:
|
|
158
|
+
OW_KERNEL_BIN ruta al binario owear
|
|
159
|
+
`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function cmdCreate(args) {
|
|
163
|
+
const dir = args[0]
|
|
164
|
+
if (!dir) die('uso: ow create <dir>')
|
|
165
|
+
const target = path.resolve(dir)
|
|
166
|
+
if (fs.existsSync(target) && fs.readdirSync(target).length) {
|
|
167
|
+
die(`el directorio ya existe y no está vacío: ${target}`)
|
|
168
|
+
}
|
|
169
|
+
const templateDir = path.resolve(__dirname, '../template')
|
|
170
|
+
if (!fs.existsSync(templateDir)) {
|
|
171
|
+
die(`template no encontrado en ${templateDir} (instala @owear/cli completo)`)
|
|
172
|
+
}
|
|
173
|
+
fs.cpSync(templateDir, target, { recursive: true })
|
|
174
|
+
log(`app creada en ${target}`)
|
|
175
|
+
log('siguientes pasos:')
|
|
176
|
+
console.log(` cd ${path.basename(target)}`)
|
|
177
|
+
console.log(' pnpm install')
|
|
178
|
+
console.log(' pnpm dev')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── ow api — gestión de las APIs del framework ──────────────────────────────
|
|
182
|
+
// Fuente única de verdad: api/<nombre>/owear.module.json. `ow api new` crea la
|
|
183
|
+
// carpeta + manifiesto + esqueleto C++ y regenera el descubrimiento.
|
|
184
|
+
|
|
185
|
+
/** Raíz del repo de Owear (para `ow api`, que no vive en la app). */
|
|
186
|
+
function owearRepoRoot() {
|
|
187
|
+
const root = path.resolve(__dirname, '../../..')
|
|
188
|
+
return fs.existsSync(path.join(root, 'CMakeLists.txt')) ? root : null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function cmdApi(args) {
|
|
192
|
+
const root = owearRepoRoot()
|
|
193
|
+
if (!root) die('`ow api` solo funciona dentro del repo de Owear (no encuentro api/ desde el CLI)')
|
|
194
|
+
const sub = args[0]
|
|
195
|
+
if (sub === 'list') return cmdApiList(root)
|
|
196
|
+
if (sub === 'new') return cmdApiNew(root, args[1])
|
|
197
|
+
die('uso: ow api <list | new <nombre>>')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function readApiManifests(root) {
|
|
201
|
+
const apiDir = path.join(root, 'api')
|
|
202
|
+
const out = []
|
|
203
|
+
for (const d of fs.readdirSync(apiDir, { withFileTypes: true })) {
|
|
204
|
+
if (!d.isDirectory()) continue
|
|
205
|
+
const file = path.join(apiDir, d.name, 'owear.module.json')
|
|
206
|
+
if (!fs.existsSync(file)) continue
|
|
207
|
+
out.push(JSON.parse(fs.readFileSync(file, 'utf8')))
|
|
208
|
+
}
|
|
209
|
+
return out
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function cmdApiList(root) {
|
|
213
|
+
const manifests = readApiManifests(root).sort((a, b) => a.name.localeCompare(b.name))
|
|
214
|
+
const fnCount = (m) =>
|
|
215
|
+
m.kind === 'module'
|
|
216
|
+
? (m.functions?.length ?? 0)
|
|
217
|
+
: (m.descriptors ?? []).reduce((a, d) => a + (d.functions?.length ?? 0), 0)
|
|
218
|
+
const w = Math.max(4, ...manifests.map((m) => m.name.length))
|
|
219
|
+
console.log(`\n${'API'.padEnd(w)} KIND VER FNS PLATAFORMAS`)
|
|
220
|
+
console.log(`${'─'.repeat(w)} ─────── ───── ─── ────────────`)
|
|
221
|
+
for (const m of manifests) {
|
|
222
|
+
const fns = String(fnCount(m)).padStart(3)
|
|
223
|
+
const plats = (m.platforms ?? [...new Set((m.descriptors ?? []).flatMap((d) => d.platforms ?? []))]).join('/') || '—'
|
|
224
|
+
console.log(`${m.name.padEnd(w)} ${m.kind.padEnd(7)} ${m.version.padEnd(5)} ${fns} ${plats}`)
|
|
225
|
+
}
|
|
226
|
+
const mods = manifests.filter((m) => m.kind === 'module').length
|
|
227
|
+
console.log(`\n${manifests.length} APIs — ${mods} módulos (.owm), ${manifests.length - mods} builtins\n`)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function cmdApiNew(root, name) {
|
|
231
|
+
if (!name) die('uso: ow api new <nombre>')
|
|
232
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) die('nombre inválido (minúsculas, dígitos y guiones; debe empezar por letra)')
|
|
233
|
+
const dir = path.join(root, 'api', name)
|
|
234
|
+
if (fs.existsSync(dir) && fs.readdirSync(dir).length) die(`api/${name}/ ya existe y no está vacío`)
|
|
235
|
+
|
|
236
|
+
fs.mkdirSync(path.join(dir, 'src'), { recursive: true })
|
|
237
|
+
|
|
238
|
+
const manifest = {
|
|
239
|
+
$schema: '../owear.module.schema.json',
|
|
240
|
+
name,
|
|
241
|
+
kind: 'module',
|
|
242
|
+
version: '0.1.0',
|
|
243
|
+
description: `${name} — API de Owear.`,
|
|
244
|
+
platforms: ['linux', 'win', 'mac'],
|
|
245
|
+
functions: ['ping'],
|
|
246
|
+
}
|
|
247
|
+
fs.writeFileSync(path.join(dir, 'owear.module.json'), JSON.stringify(manifest, null, 2) + '\n')
|
|
248
|
+
|
|
249
|
+
fs.writeFileSync(
|
|
250
|
+
path.join(dir, 'CMakeLists.txt'),
|
|
251
|
+
`# ── API ${name} ────────────────────────────────────────────────────────────────\n` +
|
|
252
|
+
`# Manifiesto: owear.module.json (fuente única de verdad).\n` +
|
|
253
|
+
`ow_add_module(${name} SOURCES src/${name}.cpp)\n`
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
fs.writeFileSync(
|
|
257
|
+
path.join(dir, 'src', `${name}.cpp`),
|
|
258
|
+
`// Copyright 2026 Owear Contributors\n` +
|
|
259
|
+
`// SPDX-License-Identifier: Apache-2.0\n` +
|
|
260
|
+
`//\n` +
|
|
261
|
+
`// api/${name}/src/${name}.cpp — implementación de la API ${name}.\n` +
|
|
262
|
+
`// Se compila a ${name}.owm y se invoca desde el renderer con:\n` +
|
|
263
|
+
`// await ow.invoke('${name}', 'ping')\n` +
|
|
264
|
+
`\n` +
|
|
265
|
+
`#include <ow/Json.h>\n` +
|
|
266
|
+
`#include <ow/Module.h>\n` +
|
|
267
|
+
`#include "ow_api.h"\n` +
|
|
268
|
+
`\n` +
|
|
269
|
+
`static void ping(const ow_request_t*, ow_response_t* res) {\n` +
|
|
270
|
+
` ow::Module::RespondOk(res, "\\"pong\\"");\n` +
|
|
271
|
+
`}\n` +
|
|
272
|
+
`\n` +
|
|
273
|
+
`OW_MODULE_BEGIN(${name}, "1.0.0")\n` +
|
|
274
|
+
`OW_FN(ping)\n` +
|
|
275
|
+
`OW_MODULE_END()\n`
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
fs.writeFileSync(
|
|
279
|
+
path.join(dir, 'README.md'),
|
|
280
|
+
`# ${name}\n\n` +
|
|
281
|
+
`API de Owear. Manifiesto: [\`owear.module.json\`](./owear.module.json).\n\n` +
|
|
282
|
+
`Desde el renderer:\n\n\`\`\`ts\nawait ow.invoke('${name}', 'ping') // → "pong"\n\`\`\`\n`
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
log(`API creada en api/${name}/`)
|
|
286
|
+
log('regenerando descubrimiento (api/generated.cmake + builtins)…')
|
|
287
|
+
const r = spawnSync(process.execPath, [path.join(root, 'tools', 'gen-apis.mjs')], { stdio: 'inherit' })
|
|
288
|
+
if (r.status !== 0) die('falló tools/gen-apis.mjs')
|
|
289
|
+
log(`listo. En el renderer: ow.invoke('${name}', 'ping')`)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function runProc(cmd, args, opts = {}) {
|
|
293
|
+
return new Promise((resolve) => {
|
|
294
|
+
const p = spawn(cmd, args, { stdio: 'inherit', ...opts })
|
|
295
|
+
p.on('exit', (code) => resolve(code ?? 1))
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function waitForServer(url, timeoutMs = 30000) {
|
|
300
|
+
const start = Date.now()
|
|
301
|
+
while (Date.now() - start < timeoutMs) {
|
|
302
|
+
try {
|
|
303
|
+
const r = await fetch(url)
|
|
304
|
+
if (r.ok) return true
|
|
305
|
+
} catch { /* aún no */ }
|
|
306
|
+
await new Promise((r) => setTimeout(r, 250))
|
|
307
|
+
}
|
|
308
|
+
return false
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Entry del proceso principal: app/main.{ts,mts,js,mjs}. */
|
|
312
|
+
function findMainEntry(cwd) {
|
|
313
|
+
for (const name of ['main.ts', 'main.mts', 'main.js', 'main.mjs']) {
|
|
314
|
+
const p = path.join(cwd, 'app', name)
|
|
315
|
+
if (fs.existsSync(p)) return p
|
|
316
|
+
}
|
|
317
|
+
return null
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Prepara el entry del sidecar para que lo ejecute CUALQUIER node instalado.
|
|
322
|
+
* Node no ejecuta TypeScript hasta la 22.6 (y hasta la 23.6 sólo con un flag),
|
|
323
|
+
* así que compilamos con esbuild (viene con vite). De este modo el runtime del
|
|
324
|
+
* sistema sirve y el arranque no depende de la versión que tenga el usuario.
|
|
325
|
+
*/
|
|
326
|
+
function prepareMain(cwd, outDir) {
|
|
327
|
+
const entry = findMainEntry(cwd)
|
|
328
|
+
if (!entry) return null
|
|
329
|
+
if (entry.endsWith('.js') || entry.endsWith('.mjs')) return entry
|
|
330
|
+
|
|
331
|
+
const out = path.join(outDir, 'main.js')
|
|
332
|
+
fs.mkdirSync(outDir, { recursive: true })
|
|
333
|
+
log(`compilando ${path.relative(cwd, entry)}…`)
|
|
334
|
+
const r = spawnSync(
|
|
335
|
+
'npx',
|
|
336
|
+
[
|
|
337
|
+
'esbuild', entry,
|
|
338
|
+
'--bundle', '--platform=node', '--format=esm',
|
|
339
|
+
'--packages=external', `--outfile=${out}`, '--log-level=warning',
|
|
340
|
+
],
|
|
341
|
+
{ cwd, stdio: 'inherit', shell: process.platform === 'win32' }
|
|
342
|
+
)
|
|
343
|
+
if (r.status !== 0) {
|
|
344
|
+
die(`no se pudo compilar ${path.relative(cwd, entry)} — esbuild viene con vite, revisa que esté instalado`)
|
|
345
|
+
}
|
|
346
|
+
return out
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function cmdDev() {
|
|
350
|
+
const cwd = process.cwd()
|
|
351
|
+
if (!fs.existsSync(path.join(cwd, 'package.json'))) die('ejecuta dentro de tu app')
|
|
352
|
+
|
|
353
|
+
const kernelBin = ensureKernelBuilt(cwd)
|
|
354
|
+
|
|
355
|
+
log('arrancando vite…')
|
|
356
|
+
const vite = spawn('npx', ['vite', '--port', '5173', '--strictPort'], {
|
|
357
|
+
cwd,
|
|
358
|
+
stdio: 'inherit',
|
|
359
|
+
shell: process.platform === 'win32',
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
const up = await waitForServer('http://localhost:5173/')
|
|
363
|
+
if (!up) { vite.kill(); die('vite no arrancó') }
|
|
364
|
+
log('dev server listo en http://localhost:5173')
|
|
365
|
+
|
|
366
|
+
// compila módulos nativos de la app (native/*.cpp → .owm)
|
|
367
|
+
const nativeDir = path.join(cwd, 'native')
|
|
368
|
+
let modulesDir = ''
|
|
369
|
+
if (fs.existsSync(nativeDir)) {
|
|
370
|
+
modulesDir = path.join(cwd, '.owear', 'modules')
|
|
371
|
+
fs.mkdirSync(modulesDir, { recursive: true })
|
|
372
|
+
const r = spawnSync('npx', ['owear-build-native'], {
|
|
373
|
+
cwd,
|
|
374
|
+
stdio: 'inherit',
|
|
375
|
+
shell: process.platform === 'win32',
|
|
376
|
+
env: { ...process.env, OW_MODULES_OUT: modulesDir },
|
|
377
|
+
})
|
|
378
|
+
if (r.status !== 0) die('falló la compilación de native/*.cpp')
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const mainJs = prepareMain(cwd, path.join(cwd, '.owear'))
|
|
382
|
+
if (mainJs) log(`proceso principal: ${path.relative(cwd, mainJs)}`)
|
|
383
|
+
|
|
384
|
+
log(`lanzando kernel: ${kernelBin}`)
|
|
385
|
+
const kernel = spawn(kernelBin, [], {
|
|
386
|
+
stdio: 'inherit',
|
|
387
|
+
env: {
|
|
388
|
+
...process.env,
|
|
389
|
+
OW_APP_NAME: JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')).name ?? 'Owear App',
|
|
390
|
+
OW_DEV_SERVER_URL: 'http://localhost:5173/',
|
|
391
|
+
...(mainJs ? { OW_APP_MAIN: mainJs } : {}),
|
|
392
|
+
...(() => {
|
|
393
|
+
// módulos stock (fs/path/…) + los nativos de la app, si los hay
|
|
394
|
+
const dirs = [stockModulesPath(), modulesDir].filter(Boolean)
|
|
395
|
+
return dirs.length ? { OW_MODULES_DIR: dirs.join(path.delimiter) } : {}
|
|
396
|
+
})(),
|
|
397
|
+
},
|
|
398
|
+
})
|
|
399
|
+
kernel.on('exit', (code) => {
|
|
400
|
+
log(`kernel terminó (${code})`)
|
|
401
|
+
vite.kill('SIGTERM')
|
|
402
|
+
process.exit(code ?? 0)
|
|
403
|
+
})
|
|
404
|
+
process.on('SIGINT', () => {
|
|
405
|
+
kernel.kill('SIGTERM')
|
|
406
|
+
vite.kill('SIGTERM')
|
|
407
|
+
process.exit(0)
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function cmdBuild() {
|
|
412
|
+
const cwd = process.cwd()
|
|
413
|
+
log('vite build…')
|
|
414
|
+
const code = await runProc('npx', ['vite', 'build'], { cwd, shell: process.platform === 'win32' })
|
|
415
|
+
if (code !== 0) die('vite build falló')
|
|
416
|
+
|
|
417
|
+
const mainJs = prepareMain(cwd, path.join(cwd, 'dist'))
|
|
418
|
+
|
|
419
|
+
const nativeDir = path.join(cwd, 'native')
|
|
420
|
+
if (fs.existsSync(nativeDir)) {
|
|
421
|
+
const out = path.join(cwd, 'dist', 'modules')
|
|
422
|
+
const r = spawnSync('npx', ['owear-build-native'], {
|
|
423
|
+
cwd,
|
|
424
|
+
stdio: 'inherit',
|
|
425
|
+
shell: process.platform === 'win32',
|
|
426
|
+
env: { ...process.env, OW_MODULES_OUT: out },
|
|
427
|
+
})
|
|
428
|
+
if (r.status !== 0) die('falló la compilación de native/*.cpp')
|
|
429
|
+
}
|
|
430
|
+
log('build lista en dist/')
|
|
431
|
+
const runMods = [
|
|
432
|
+
stockModulesPath(),
|
|
433
|
+
fs.existsSync(path.join(cwd, 'dist', 'modules')) ? path.join(cwd, 'dist', 'modules') : '',
|
|
434
|
+
]
|
|
435
|
+
.filter(Boolean)
|
|
436
|
+
.join(path.delimiter)
|
|
437
|
+
console.log(
|
|
438
|
+
` OW_ASSETS_DIR=dist${mainJs ? ' OW_APP_MAIN=dist/main.js' : ''}` +
|
|
439
|
+
`${runMods ? ` OW_MODULES_DIR="${runMods}"` : ''} ./owear`
|
|
440
|
+
)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
main().catch((e) => die(e?.stack ?? String(e)))
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Owear Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// owear-build-native — compila native/*.cpp de una app a .owm.
|
|
6
|
+
// Cero configuración: detecta el compilador del sistema y compila como librería
|
|
7
|
+
// dinámica exportando ow_module_descriptor.
|
|
8
|
+
//
|
|
9
|
+
import { spawnSync } from 'node:child_process'
|
|
10
|
+
import * as fs from 'node:fs'
|
|
11
|
+
import * as path from 'node:path'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
import { createRequire } from 'node:module'
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url)
|
|
16
|
+
|
|
17
|
+
const out = process.env.OW_MODULES_OUT ?? path.join(process.cwd(), '.owear', 'modules')
|
|
18
|
+
const nativeDir = path.join(process.cwd(), 'native')
|
|
19
|
+
|
|
20
|
+
if (!fs.existsSync(nativeDir)) {
|
|
21
|
+
console.log('[ow-build-native] sin directorio native/ — nada que hacer')
|
|
22
|
+
process.exit(0)
|
|
23
|
+
}
|
|
24
|
+
fs.mkdirSync(out, { recursive: true })
|
|
25
|
+
|
|
26
|
+
// incluye headers públicos del framework si están instalados junto al kernel
|
|
27
|
+
function frameworkIncludes() {
|
|
28
|
+
const incs = []
|
|
29
|
+
let runtimeInclude = null
|
|
30
|
+
// paquete de runtime de npm (@owear/<plataforma>): trae include/
|
|
31
|
+
const rtName =
|
|
32
|
+
process.platform === 'linux' && process.arch === 'x64'
|
|
33
|
+
? '@owear/linux-x64-gnu'
|
|
34
|
+
: process.platform === 'win32' && process.arch === 'x64'
|
|
35
|
+
? '@owear/win32-x64'
|
|
36
|
+
: process.platform === 'darwin'
|
|
37
|
+
? `@owear/darwin-${process.arch}`
|
|
38
|
+
: null
|
|
39
|
+
if (rtName) {
|
|
40
|
+
try {
|
|
41
|
+
runtimeInclude = path.join(path.dirname(require.resolve(rtName + '/package.json')), 'include')
|
|
42
|
+
} catch {
|
|
43
|
+
/* sin runtime npm: cae al include del monorepo */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// desde packages/cli/src/ → raíz del repo (monorepo en desarrollo)
|
|
47
|
+
const candidates = [
|
|
48
|
+
process.env.OW_INCLUDE_DIR,
|
|
49
|
+
runtimeInclude,
|
|
50
|
+
path.resolve(
|
|
51
|
+
import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url)),
|
|
52
|
+
'../../../include',
|
|
53
|
+
),
|
|
54
|
+
].filter(Boolean)
|
|
55
|
+
for (const c of candidates) if (fs.existsSync(c)) incs.push(c)
|
|
56
|
+
return incs
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function pickCompiler() {
|
|
60
|
+
if (process.env.CXX) return process.env.CXX
|
|
61
|
+
for (const c of ['c++', 'g++', 'clang++']) {
|
|
62
|
+
if (spawnSync(c, ['--version'], { stdio: 'ignore' }).status === 0) return c
|
|
63
|
+
}
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function pickWindowsCompiler() {
|
|
68
|
+
// cl.exe del último VS instalado (via vswhere)
|
|
69
|
+
const vswhere = 'C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe'
|
|
70
|
+
if (!fs.existsSync(vswhere)) {
|
|
71
|
+
if (spawnSync('clang++', ['--version'], { stdio: 'ignore' }).status === 0) {
|
|
72
|
+
return { cmd: 'clang++', msvcLike: false }
|
|
73
|
+
}
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
const r = spawnSync(vswhere, ['-latest', '-property', 'installationPath'], { encoding: 'utf8' })
|
|
77
|
+
const vsPath = r.stdout?.trim()
|
|
78
|
+
if (!vsPath) return null
|
|
79
|
+
const clCandidates = fs.readdirSync(path.join(vsPath, 'VC', 'Tools', 'MSVC'))
|
|
80
|
+
.sort().reverse()
|
|
81
|
+
for (const v of clCandidates) {
|
|
82
|
+
const cl = path.join(vsPath, 'VC', 'Tools', 'MSVC', v, 'bin', 'Hostx64', 'x64', 'cl.exe')
|
|
83
|
+
if (fs.existsSync(cl)) return { cmd: cl, msvcLike: true }
|
|
84
|
+
}
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const incs = frameworkIncludes()
|
|
89
|
+
let failures = 0
|
|
90
|
+
|
|
91
|
+
for (const file of fs.readdirSync(nativeDir)) {
|
|
92
|
+
if (!file.endsWith('.cpp')) continue
|
|
93
|
+
const src = path.join(nativeDir, file)
|
|
94
|
+
const name = path.basename(file, '.cpp')
|
|
95
|
+
const ext = process.platform === 'win32' ? '.dll' : process.platform === 'darwin' ? '.dylib' : '.so'
|
|
96
|
+
const dest = path.join(out, name + ext)
|
|
97
|
+
|
|
98
|
+
// rebuild solo si cambió la fuente
|
|
99
|
+
if (fs.existsSync(dest) && fs.statSync(src).mtimeMs < fs.statSync(dest).mtimeMs) {
|
|
100
|
+
console.log(`[ow-build-native] ${name} al día`)
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const compiler = process.platform === 'win32' ? pickWindowsCompiler() : (() => {
|
|
105
|
+
const cmd = pickCompiler()
|
|
106
|
+
return cmd ? { cmd, msvcLike: false } : null
|
|
107
|
+
})()
|
|
108
|
+
if (!compiler) {
|
|
109
|
+
console.error(`[ow-build-native] ✗ no hay compilador C++ para ${file}`)
|
|
110
|
+
failures++
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let args
|
|
115
|
+
if (compiler.msvcLike) {
|
|
116
|
+
args = ['/std:c++20', '/LD', '/O2', '/EHsc', `/Fe:${dest}`, src,
|
|
117
|
+
...incs.flatMap((i) => [`/I${i}`])]
|
|
118
|
+
} else {
|
|
119
|
+
args = ['-std=c++20', '-O2', '-fPIC', '-shared', '-o', dest, src,
|
|
120
|
+
...incs.flatMap((i) => ['-I', i]),
|
|
121
|
+
...(process.platform === 'darwin' ? [] : [])]
|
|
122
|
+
}
|
|
123
|
+
console.log(`[ow-build-native] compilando ${file} → ${path.basename(dest)}`)
|
|
124
|
+
const r = spawnSync(compiler.cmd, args, { stdio: 'inherit' })
|
|
125
|
+
if (r.status !== 0) {
|
|
126
|
+
console.error(`[ow-build-native] ✗ falló ${file}`)
|
|
127
|
+
failures++
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
process.exit(failures ? 1 : 0)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2026 Owear Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
//
|
|
4
|
+
// main.ts — proceso principal (sidecar Node). Estilo Electron.
|
|
5
|
+
//
|
|
6
|
+
import { app, BrowserWindow } from '@owear/core'
|
|
7
|
+
|
|
8
|
+
let windows = 0
|
|
9
|
+
|
|
10
|
+
app.whenReady().then(() => {
|
|
11
|
+
const win = new BrowserWindow({
|
|
12
|
+
title: 'Mi App Owear',
|
|
13
|
+
width: 1100,
|
|
14
|
+
height: 720,
|
|
15
|
+
titleBarStyle: 'custom', // titlebar custom + drag regions CSS
|
|
16
|
+
url: process.env.OW_DEV_SERVER_URL ?? 'app://index.html',
|
|
17
|
+
})
|
|
18
|
+
windows++
|
|
19
|
+
|
|
20
|
+
win.on('closed', () => {
|
|
21
|
+
windows--
|
|
22
|
+
if (windows === 0) app.quit()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// ejemplo: evaluar JS en la página
|
|
26
|
+
win.on('ready-to-show', async () => {
|
|
27
|
+
console.log('[main] ventana lista, id =', win.id)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="es">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Mi App Owear</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<header data-ow-drag class="titlebar">
|
|
10
|
+
<span>Mi App Owear</span>
|
|
11
|
+
<nav>
|
|
12
|
+
<button data-ow-no-drag onclick="ow.invoke('ow-window','minimize', window.__owWindowId)">–</button>
|
|
13
|
+
<button data-ow-no-drag onclick="ow.invoke('ow-window','maximize', window.__owWindowId, true)">□</button>
|
|
14
|
+
<button data-ow-no-drag onclick="ow.invoke('ow-window','close', window.__owWindowId)">✕</button>
|
|
15
|
+
</nav>
|
|
16
|
+
</header>
|
|
17
|
+
<main>
|
|
18
|
+
<h1>Funciona 🚀</h1>
|
|
19
|
+
<p id="demo">invocando módulo nativo…</p>
|
|
20
|
+
<pre id="out"></pre>
|
|
21
|
+
</main>
|
|
22
|
+
<script type="module" src="/src/renderer.ts"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright 2026 Owear Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
//
|
|
4
|
+
// native/files.cpp — módulo nativo PROPIO de la app.
|
|
5
|
+
// Se compila a .owm y se invoca desde el renderer con:
|
|
6
|
+
// import { files } from '@owear/native'
|
|
7
|
+
// await files.readText('/etc/hostname')
|
|
8
|
+
//
|
|
9
|
+
#include <ow/Json.h>
|
|
10
|
+
#include <ow/Module.h>
|
|
11
|
+
#include "ow_api.h"
|
|
12
|
+
|
|
13
|
+
#include <filesystem>
|
|
14
|
+
#include <fstream>
|
|
15
|
+
#include <sstream>
|
|
16
|
+
|
|
17
|
+
namespace fs = std::filesystem;
|
|
18
|
+
|
|
19
|
+
static void readText(const ow_request_t* req, ow_response_t* res) {
|
|
20
|
+
auto parsed = ow::json::Parse(std::string_view(req->json, req->json_len));
|
|
21
|
+
if (!parsed.value || !parsed.value->IsArray() || !parsed.value->AsArray()[0].IsString())
|
|
22
|
+
return ow::Module::RespondError(res, "readText(path): path requerido");
|
|
23
|
+
std::ifstream f(parsed.value->AsArray()[0].AsString(), std::ios::binary);
|
|
24
|
+
if (!f) return ow::Module::RespondError(res, "no se pudo abrir");
|
|
25
|
+
std::ostringstream ss;
|
|
26
|
+
ss << f.rdbuf();
|
|
27
|
+
ow::Module::RespondOk(res, ow::json::Value(ss.str()).Serialize().c_str());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static void exists(const ow_request_t* req, ow_response_t* res) {
|
|
31
|
+
auto parsed = ow::json::Parse(std::string_view(req->json, req->json_len));
|
|
32
|
+
if (!parsed.value || !parsed.value->IsArray() || !parsed.value->AsArray()[0].IsString())
|
|
33
|
+
return ow::Module::RespondError(res, "exists(path): path requerido");
|
|
34
|
+
std::error_code ec;
|
|
35
|
+
bool ok = fs::exists(parsed.value->AsArray()[0].AsString(), ec);
|
|
36
|
+
ow::Module::RespondOk(res, ok ? "true" : "false");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
OW_MODULE_BEGIN(files, "1.0.0")
|
|
40
|
+
OW_FN(readText)
|
|
41
|
+
OW_FN(exists)
|
|
42
|
+
OW_MODULE_END()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mi-app-owear",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "ow dev",
|
|
8
|
+
"build": "ow build"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@owear/core": "^0.1.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@owear/cli": "^0.1.0",
|
|
15
|
+
"@owear/vite-plugin": "^0.1.0",
|
|
16
|
+
"esbuild": "^0.25.0",
|
|
17
|
+
"typescript": "^5.6.0",
|
|
18
|
+
"vite": "^6.0.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2026 Owear Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
//
|
|
4
|
+
// renderer.ts — corre dentro del WebView. `ow` lo inyecta el kernel.
|
|
5
|
+
//
|
|
6
|
+
import { files } from '@owear/native'
|
|
7
|
+
|
|
8
|
+
const out = document.getElementById('out')!
|
|
9
|
+
const demo = document.getElementById('demo')!
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
try {
|
|
13
|
+
// módulo nativo PROPIO (native/files.cpp)
|
|
14
|
+
const text = await files.readText('/etc/hostname')
|
|
15
|
+
demo.textContent = `hostname leído desde C++ nativo: ${text.trim()}`
|
|
16
|
+
|
|
17
|
+
// módulo stock fs
|
|
18
|
+
const st = await ow.invoke('fs', 'stat', '/etc/hosts')
|
|
19
|
+
out.textContent = JSON.stringify(st, null, 2)
|
|
20
|
+
|
|
21
|
+
// eventos de ventana
|
|
22
|
+
ow.on('resize', (b) => {
|
|
23
|
+
document.title = `${b.width}×${b.height}`
|
|
24
|
+
})
|
|
25
|
+
} catch (e) {
|
|
26
|
+
demo.textContent = '✗ ' + (e as Error).message
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main()
|