@weave-apps/sdk 0.5.0 → 0.6.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/bin/compile.js +58 -18
- package/package.json +2 -1
package/bin/compile.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Weave App Compiler
|
|
5
5
|
*
|
|
6
|
-
* Compiles TypeScript and transpiles to Weave-ready JavaScript
|
|
6
|
+
* Compiles TypeScript and transpiles to Weave-ready JavaScript.
|
|
7
|
+
* Supports multi-file apps by bundling all imports into a single output file.
|
|
8
|
+
*
|
|
9
|
+
* Uses esbuild for bundling and tsc for type-checking only.
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
12
|
const { execSync } = require('child_process');
|
|
@@ -74,6 +77,27 @@ if (!fs.existsSync(tsconfigPath)) {
|
|
|
74
77
|
process.exit(1);
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
// Look for esbuild in multiple locations
|
|
81
|
+
let esbuildPath = null;
|
|
82
|
+
const possibleEsbuildPaths = [
|
|
83
|
+
path.join(appDir, 'node_modules', '.bin', 'esbuild'),
|
|
84
|
+
path.join(sdkDir, 'node_modules', '.bin', 'esbuild'),
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
for (const candidate of possibleEsbuildPaths) {
|
|
88
|
+
if (fs.existsSync(candidate)) {
|
|
89
|
+
esbuildPath = candidate;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!esbuildPath) {
|
|
95
|
+
console.error('❌ Error: esbuild not found');
|
|
96
|
+
console.error('It should be installed as part of @weave-apps/sdk.');
|
|
97
|
+
console.error('Try running: npm install');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
77
101
|
try {
|
|
78
102
|
// Create dist directory if it doesn't exist
|
|
79
103
|
const distDir = path.join(appDir, 'dist');
|
|
@@ -81,35 +105,51 @@ try {
|
|
|
81
105
|
fs.mkdirSync(distDir, { recursive: true });
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
const entryPoint = path.join(appDir, 'src', 'app.ts');
|
|
109
|
+
const targetFile = path.join(distDir, `${appName}.js`);
|
|
110
|
+
|
|
111
|
+
// Step 1: Type-check with tsc (no emit)
|
|
112
|
+
console.log('� Type-checking with TypeScript...');
|
|
86
113
|
const tscCommand = tscPath === 'npx tsc'
|
|
87
|
-
? `npx tsc --project ${tsconfigPath} --
|
|
88
|
-
: `"${tscPath}" --project ${tsconfigPath} --
|
|
114
|
+
? `npx tsc --project ${tsconfigPath} --noEmit`
|
|
115
|
+
: `"${tscPath}" --project ${tsconfigPath} --noEmit`;
|
|
89
116
|
|
|
90
117
|
execSync(tscCommand, {
|
|
91
118
|
stdio: 'inherit',
|
|
92
119
|
cwd: appDir
|
|
93
120
|
});
|
|
94
121
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
122
|
+
console.log('✅ Type-check passed\n');
|
|
123
|
+
|
|
124
|
+
// Step 2: Bundle with esbuild (all imports resolved into single file)
|
|
125
|
+
console.log('📦 Bundling with esbuild...');
|
|
126
|
+
const esbuildCommand = [
|
|
127
|
+
`"${esbuildPath}"`,
|
|
128
|
+
`"${entryPoint}"`,
|
|
129
|
+
'--bundle',
|
|
130
|
+
`--outfile="${targetFile}"`,
|
|
131
|
+
'--format=esm',
|
|
132
|
+
'--target=es2020',
|
|
133
|
+
'--platform=browser',
|
|
134
|
+
// Mark SDK as external — build.js will replace with window globals
|
|
135
|
+
'--external:@weave-apps/sdk',
|
|
136
|
+
'--external:@weave/app-sdk',
|
|
137
|
+
].join(' ');
|
|
138
|
+
|
|
139
|
+
execSync(esbuildCommand, {
|
|
140
|
+
stdio: 'inherit',
|
|
141
|
+
cwd: appDir
|
|
142
|
+
});
|
|
102
143
|
|
|
103
|
-
console.log('✅
|
|
144
|
+
console.log('✅ Bundle complete\n');
|
|
104
145
|
|
|
105
|
-
// Step
|
|
146
|
+
// Step 3: Extract settings schema and inject into compiled JS
|
|
106
147
|
console.log('📋 Extracting settings schema...');
|
|
107
148
|
const extractSchemaScript = path.join(sdkDir, 'scripts', 'extract-settings-schema.js');
|
|
108
|
-
const sourceFile = path.join(appDir, 'src', 'app.ts');
|
|
109
149
|
|
|
110
|
-
if (fs.existsSync(extractSchemaScript) && fs.existsSync(
|
|
150
|
+
if (fs.existsSync(extractSchemaScript) && fs.existsSync(entryPoint)) {
|
|
111
151
|
try {
|
|
112
|
-
execSync(`node "${extractSchemaScript}" "${
|
|
152
|
+
execSync(`node "${extractSchemaScript}" "${entryPoint}" "${targetFile}"`, {
|
|
113
153
|
stdio: 'inherit',
|
|
114
154
|
cwd: appDir
|
|
115
155
|
});
|
|
@@ -120,7 +160,7 @@ try {
|
|
|
120
160
|
|
|
121
161
|
console.log('');
|
|
122
162
|
|
|
123
|
-
// Step
|
|
163
|
+
// Step 4: Run weave-build to transpile (strip imports, add window globals)
|
|
124
164
|
console.log('🔧 Transpiling to Weave format...');
|
|
125
165
|
const buildScript = path.join(__dirname, 'build.js');
|
|
126
166
|
execSync(`node "${buildScript}"`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-apps/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "SDK for building Weave Micro Apps",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"author": "Weave Platform",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"esbuild": "^0.24.0",
|
|
35
36
|
"typescript": "^5.9.3"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|