craft-native 0.0.100 → 0.0.101
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/dist/android/src/index.js +2 -1
- package/dist/cli.js +5 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/ios/src/index.js +2 -1
- package/dist/ios/templates/CraftApp.swift +77 -4
- package/package.json +1 -1
|
@@ -361,9 +361,10 @@ async function init(options) {
|
|
|
361
361
|
`);
|
|
362
362
|
const finalPackageName = packageName || `com.craft.${generatedPackageSegment(name)}`;
|
|
363
363
|
const packagePath = finalPackageName.replace(/\./g, "/");
|
|
364
|
+
const given = Object.fromEntries(Object.entries(options.config ?? {}).filter(([, value]) => value !== undefined));
|
|
364
365
|
const config = {
|
|
365
366
|
...DEFAULT_CONFIG,
|
|
366
|
-
...
|
|
367
|
+
...given,
|
|
367
368
|
appName: name,
|
|
368
369
|
packageName: finalPackageName
|
|
369
370
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1404,12 +1404,13 @@ async function init(options) {
|
|
|
1404
1404
|
}
|
|
1405
1405
|
const finalBundleId = bundleId || `com.craft.${name.toLowerCase()}`;
|
|
1406
1406
|
const bundleIdPrefix = finalBundleId.split(".").slice(0, -1).join(".");
|
|
1407
|
+
const given = Object.fromEntries(Object.entries(options.config ?? {}).filter(([, value]) => value !== undefined));
|
|
1407
1408
|
const config = {
|
|
1408
1409
|
...DEFAULT_CONFIG,
|
|
1409
1410
|
appName: displayName,
|
|
1410
1411
|
bundleId: finalBundleId,
|
|
1411
1412
|
teamId: teamId || "",
|
|
1412
|
-
...
|
|
1413
|
+
...given
|
|
1413
1414
|
};
|
|
1414
1415
|
if (config.enableBackgroundLocation)
|
|
1415
1416
|
config.enableGeolocation = true;
|
|
@@ -2004,9 +2005,10 @@ async function init2(options) {
|
|
|
2004
2005
|
`);
|
|
2005
2006
|
const finalPackageName = packageName || `com.craft.${generatedPackageSegment(name)}`;
|
|
2006
2007
|
const packagePath = finalPackageName.replace(/\./g, "/");
|
|
2008
|
+
const given = Object.fromEntries(Object.entries(options.config ?? {}).filter(([, value]) => value !== undefined));
|
|
2007
2009
|
const config = {
|
|
2008
2010
|
...DEFAULT_CONFIG2,
|
|
2009
|
-
...
|
|
2011
|
+
...given,
|
|
2010
2012
|
appName: name,
|
|
2011
2013
|
packageName: finalPackageName
|
|
2012
2014
|
};
|
|
@@ -4619,7 +4621,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
|
|
|
4619
4621
|
`);
|
|
4620
4622
|
}
|
|
4621
4623
|
// package.json
|
|
4622
|
-
var version = "0.0.
|
|
4624
|
+
var version = "0.0.101";
|
|
4623
4625
|
|
|
4624
4626
|
// bin/cli.ts
|
|
4625
4627
|
var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/dist/ios/src/index.js
CHANGED
|
@@ -385,12 +385,13 @@ async function init(options) {
|
|
|
385
385
|
}
|
|
386
386
|
const finalBundleId = bundleId || `com.craft.${name.toLowerCase()}`;
|
|
387
387
|
const bundleIdPrefix = finalBundleId.split(".").slice(0, -1).join(".");
|
|
388
|
+
const given = Object.fromEntries(Object.entries(options.config ?? {}).filter(([, value]) => value !== undefined));
|
|
388
389
|
const config = {
|
|
389
390
|
...DEFAULT_CONFIG,
|
|
390
391
|
appName: displayName,
|
|
391
392
|
bundleId: finalBundleId,
|
|
392
393
|
teamId: teamId || "",
|
|
393
|
-
...
|
|
394
|
+
...given
|
|
394
395
|
};
|
|
395
396
|
if (config.enableBackgroundLocation)
|
|
396
397
|
config.enableGeolocation = true;
|
|
@@ -337,17 +337,40 @@ class AppState: ObservableObject {
|
|
|
337
337
|
@Published var config: CraftConfig
|
|
338
338
|
|
|
339
339
|
init() {
|
|
340
|
-
// Load config from craft.config.json if available
|
|
341
340
|
if let configURL = Bundle.main.url(forResource: "craft.config", withExtension: "json"),
|
|
342
|
-
let data = try? Data(contentsOf: configURL)
|
|
343
|
-
|
|
344
|
-
self.config = config
|
|
341
|
+
let data = try? Data(contentsOf: configURL) {
|
|
342
|
+
self.config = CraftConfig.load(from: data)
|
|
345
343
|
} else {
|
|
346
344
|
self.config = CraftConfig()
|
|
347
345
|
}
|
|
348
346
|
}
|
|
349
347
|
}
|
|
350
348
|
|
|
349
|
+
extension CraftConfig {
|
|
350
|
+
/// The bundled config laid over the defaults, key by key.
|
|
351
|
+
///
|
|
352
|
+
/// Decoded whole, one missing or mistyped key failed the entire file and
|
|
353
|
+
/// the app ran on `CraftConfig()` — every capability off, silently: the
|
|
354
|
+
/// network bridge refused, the page read that as offline, and nothing said
|
|
355
|
+
/// why. A key the file leaves out now keeps its default, and a file that
|
|
356
|
+
/// still cannot be read says so in the log.
|
|
357
|
+
static func load(from data: Data) -> CraftConfig {
|
|
358
|
+
let defaults = (try? JSONEncoder().encode(CraftConfig()))
|
|
359
|
+
.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: Any] } ?? [:]
|
|
360
|
+
guard let given = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else {
|
|
361
|
+
NSLog("[craft] craft.config.json is not a JSON object; running on defaults")
|
|
362
|
+
return CraftConfig()
|
|
363
|
+
}
|
|
364
|
+
let merged = defaults.merging(given.filter { !($0.value is NSNull) }) { _, bundled in bundled }
|
|
365
|
+
do {
|
|
366
|
+
return try JSONDecoder().decode(CraftConfig.self, from: JSONSerialization.data(withJSONObject: merged))
|
|
367
|
+
} catch {
|
|
368
|
+
NSLog("[craft] craft.config.json could not be read, running on defaults: %@", String(describing: error))
|
|
369
|
+
return CraftConfig()
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
351
374
|
// MARK: - Configuration
|
|
352
375
|
struct CraftConfig: Codable {
|
|
353
376
|
var appName: String = "Craft App"
|
|
@@ -514,6 +537,48 @@ final class BundledAssetSchemeHandler: NSObject, WKURLSchemeHandler {
|
|
|
514
537
|
}
|
|
515
538
|
}
|
|
516
539
|
|
|
540
|
+
#if DEBUG
|
|
541
|
+
/// Relays the page's console and uncaught errors to NSLog in debug builds.
|
|
542
|
+
final class PageConsoleRelay: NSObject, WKScriptMessageHandler {
|
|
543
|
+
static let script = """
|
|
544
|
+
(function() {
|
|
545
|
+
var handler = window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.craftLog;
|
|
546
|
+
if (!handler) return;
|
|
547
|
+
function text(value) {
|
|
548
|
+
try { return typeof value === 'string' ? value : (value && value.stack) || JSON.stringify(value); }
|
|
549
|
+
catch (e) { return String(value); }
|
|
550
|
+
}
|
|
551
|
+
function send(level, message) { try { handler.postMessage({ level: level, message: String(message).slice(0, 4000) }); } catch (e) {} }
|
|
552
|
+
['error', 'warn', 'log', 'info'].forEach(function(level) {
|
|
553
|
+
var original = console[level];
|
|
554
|
+
console[level] = function() {
|
|
555
|
+
send(level, Array.prototype.map.call(arguments, text).join(' '));
|
|
556
|
+
return original.apply(console, arguments);
|
|
557
|
+
};
|
|
558
|
+
});
|
|
559
|
+
// Capture phase: a script or stylesheet that fails to load fires its
|
|
560
|
+
// error on the element, which never bubbles to window.
|
|
561
|
+
window.addEventListener('error', function(event) {
|
|
562
|
+
var target = event.target;
|
|
563
|
+
if (target && target !== window && (target.src || target.href)) {
|
|
564
|
+
send('error', 'failed to load ' + (target.src || target.href));
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
send('error', 'uncaught ' + event.message + ' at ' + event.filename + ':' + event.lineno + ':' + event.colno);
|
|
568
|
+
}, true);
|
|
569
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
570
|
+
send('error', 'unhandled rejection ' + text(event.reason));
|
|
571
|
+
});
|
|
572
|
+
})();
|
|
573
|
+
"""
|
|
574
|
+
|
|
575
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
576
|
+
guard let body = message.body as? [String: Any] else { return }
|
|
577
|
+
NSLog("[craft page] %@: %@", body["level"] as? String ?? "log", body["message"] as? String ?? "")
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
#endif
|
|
581
|
+
|
|
517
582
|
struct CraftWebView: UIViewRepresentable {
|
|
518
583
|
let config: CraftConfig
|
|
519
584
|
|
|
@@ -528,6 +593,14 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
528
593
|
let contentController = WKUserContentController()
|
|
529
594
|
contentController.add(context.coordinator, name: "craft")
|
|
530
595
|
webConfig.userContentController = contentController
|
|
596
|
+
#if DEBUG
|
|
597
|
+
// The page's errors and console, in the device log, so a debug build
|
|
598
|
+
// can be diagnosed from `log stream` or `simctl spawn … log show`
|
|
599
|
+
// without attaching Safari. A separate handler, outside the bridge's
|
|
600
|
+
// action dispatch. Never in a release build.
|
|
601
|
+
contentController.add(PageConsoleRelay(), name: "craftLog")
|
|
602
|
+
contentController.addUserScript(WKUserScript(source: PageConsoleRelay.script, injectionTime: .atDocumentStart, forMainFrameOnly: true))
|
|
603
|
+
#endif
|
|
531
604
|
|
|
532
605
|
let webView = WKWebView(frame: .zero, configuration: webConfig)
|
|
533
606
|
webView.navigationDelegate = context.coordinator
|