Skip to content

Commit

Permalink
adding vyuh_feature_system and vyuh_extension_script packages
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanpodila committed Mar 20, 2024
1 parent 5b060d9 commit 4227710
Show file tree
Hide file tree
Showing 82 changed files with 3,158 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- packages/system/vyuh_cache
- packages/system/vyuh_core
- packages/system/vyuh_feature_developer
- packages/system/vyuh_feature_system
- packages/system/vyuh_extension_script
- packages/sanity/sanity_client
- packages/sanity/flutter_sanity_portable_text

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
- packages/system/vyuh_cache
- packages/system/vyuh_core
- packages/system/vyuh_feature_developer
- packages/system/vyuh_feature_system
- packages/system/vyuh_extension_script
- packages/sanity/flutter_sanity_portable_text
- packages/sanity/sanity_client

Expand Down
2 changes: 1 addition & 1 deletion apps/vyuh_demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

vc.runApp(
initialLocation: '/',
initialLocation: '/counter',
features: [
developer.feature,
sample.featureLauncher,
Expand Down
28 changes: 14 additions & 14 deletions apps/vyuh_demo/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ packages:
dependency: transitive
description:
name: go_router
sha256: "170c46e237d6eb0e6e9f0e8b3f56101e14fb64f787016e42edd74c39cf8b176a"
sha256: "7ecb2f391edbca5473db591b48555a8912dde60edd0fb3013bd6743033b2d3f8"
url: "https://pub.dev"
source: hosted
version: "13.2.0"
version: "13.2.1"
http:
dependency: transitive
description:
name: http
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
http_parser:
dependency: transitive
description:
Expand Down Expand Up @@ -431,10 +431,10 @@ packages:
dependency: transitive
description:
name: sqflite_common
sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5"
sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4"
url: "https://pub.dev"
source: hosted
version: "2.5.3"
version: "2.5.4"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -529,7 +529,7 @@ packages:
path: "../../packages/system/vyuh_core"
relative: true
source: path
version: "1.0.0-beta.1"
version: "1.0.0-beta.2"
vyuh_extension_content:
dependency: "direct main"
description:
Expand All @@ -543,23 +543,23 @@ packages:
path: "../../packages/system/vyuh_feature_developer"
relative: true
source: path
version: "1.0.0-beta.1"
version: "1.0.0-beta.2"
web:
dependency: transitive
description:
name: web
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.4.2"
version: "0.5.1"
win32:
dependency: transitive
description:
name: win32
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480"
url: "https://pub.dev"
source: hosted
version: "5.2.0"
version: "5.3.0"
xdg_directories:
dependency: transitive
description:
Expand All @@ -569,5 +569,5 @@ packages:
source: hosted
version: "1.0.4"
sdks:
dart: ">=3.3.0-279.1.beta <4.0.0"
flutter: ">=3.13.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.16.0"
2 changes: 1 addition & 1 deletion apps/vyuh_demo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
flutter_mobx: ^2.2.0+2
vyuh_core: ^1.0.0-beta.1
vyuh_extension_content: ^1.0.0-beta.1
vyuh_feature_developer: ^1.0.0-beta.1
vyuh_feature_developer: ^1.0.0-beta.2
feature_sample: ^1.0.0

dev_dependencies:
Expand Down
6 changes: 3 additions & 3 deletions packages/system/vyuh_core/lib/feature_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class FeatureDescriptor {
final List<FeatureExtensionDescriptor>? extensions;
final List<FeatureExtensionBuilder>? extensionBuilders;

final RouteBuilderFunction? _routes;
final RouteBuilderFunction _routes;
RouteBuilderFunction? get routes => _routes;

FeatureDescriptor({
Expand All @@ -26,10 +26,10 @@ final class FeatureDescriptor {
this.description,
this.icon,
this.init,
RouteBuilderFunction? routes,
required RouteBuilderFunction routes,
this.extensions,
this.extensionBuilders,
}) : _routes = routes == null ? null : _runOnce(routes);
}) : _routes = _runOnce(routes);
}

FutureOr<T?> Function() _runOnce<T>(FutureOr<T?> Function() fn) {
Expand Down
29 changes: 29 additions & 0 deletions packages/system/vyuh_extension_script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
10 changes: 10 additions & 0 deletions packages/system/vyuh_extension_script/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "ba393198430278b6595976de84fe170f553cc728"
channel: "stable"

project_type: package
5 changes: 5 additions & 0 deletions packages/system/vyuh_extension_script/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.0.0-beta.1

* Initial release
* Contains support for running JavaScript code inside a Dart context using `flutter_js`
* Provides extensibility via the `ScriptExtensionDescriptor`
20 changes: 20 additions & 0 deletions packages/system/vyuh_extension_script/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2024 Vyuh.tech

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions packages/system/vyuh_extension_script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
4 changes: 4 additions & 0 deletions packages/system/vyuh_extension_script/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
22 changes: 22 additions & 0 deletions packages/system/vyuh_extension_script/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
targets:
$default:
builders:
json_serializable:
options:
# Options configure how source code is generated for every
# `@JsonSerializable`-annotated class in the package.
#
# The default value for each is listed.
any_map: false
checked: false
constructor: ''
create_factory: true
create_field_map: false
create_per_field_to_json: false
create_to_json: false
disallow_unrecognized_keys: false
explicit_to_json: false
field_rename: none
generic_argument_factories: false
ignore_unannotated: false
include_if_null: true
34 changes: 34 additions & 0 deletions packages/system/vyuh_extension_script/lib/js_script.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vyuh_core/vyuh_core.dart';
import 'package:vyuh_extension_content/vyuh_extension_content.dart';

import 'script_runtime.dart'
if (dart.library.html) 'web_script_runtime.dart' as rt;

part 'js_script.g.dart';

@JsonSerializable()
final class JavaScriptAction extends ActionConfiguration {
static const schemaName = 'vyuh.action.javascript';

static final typeDescriptor = TypeDescriptor(
schemaType: JavaScriptAction.schemaName,
title: 'JavaScript Action',
fromJson: JavaScriptAction.fromJson,
);

@JsonKey(defaultValue: '')
final String script;

JavaScriptAction({required this.script, super.isAsync})
: super(schemaType: schemaName);

factory JavaScriptAction.fromJson(Map<String, dynamic> json) =>
_$JavaScriptActionFromJson(json);

@override
void execute(BuildContext context) {
rt.ScriptRuntime.evaluate(script, context);
}
}
13 changes: 13 additions & 0 deletions packages/system/vyuh_extension_script/lib/js_script.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions packages/system/vyuh_extension_script/lib/script_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:async';

import 'package:vyuh_core/vyuh_core.dart';

import 'script_runtime.dart' if (dart.library.html) 'web_script_runtime.dart'
as rt;

final class ScriptExtensionDescriptor extends FeatureExtensionDescriptor {
final String name;

String get runtime => 'javascript';

final FutureOr<dynamic> Function(dynamic args) function;

ScriptExtensionDescriptor({required this.name, required this.function})
: super(title: 'ScriptExtension: $name');
}

final class ScriptExtensionBuilder extends FeatureExtensionBuilder {
ScriptExtensionBuilder()
: super(
extensionType: ScriptExtensionDescriptor, title: 'ScriptExtension');

@override
void build(List<FeatureExtensionDescriptor> extensions) {
for (final extension in extensions.cast<ScriptExtensionDescriptor>()) {
rt.ScriptRuntime.registerFunction(extension.name, extension.function);
}
}

@override
void init() {
rt.ScriptRuntime.init();
}
}
Loading

0 comments on commit 4227710

Please sign in to comment.