Skip to content

Commit

Permalink
move the tool/bindings_generator dart+node script into the top-level …
Browse files Browse the repository at this point in the history
…bindings_generator/ directory (#123)

move the tool/bindings_generator dart+node script into the top-level bindings_generator/ directory
  • Loading branch information
devoncarew authored Dec 15, 2023
1 parent acf0beb commit e170bf2
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: dart pub get
- name: Install Node dependencies
run: npm install
working-directory: tool/bindings_generator
working-directory: bindings_generator
- name: Run the generator
run: dart tool/update_bindings.dart
- name: Analyze code
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.dart_tool
doc/api/
pubspec.lock
tool/bindings_generator/*.js
tool/bindings_generator/*.js.*
tool/bindings_generator/node_modules/

bindings_generator/*.js
bindings_generator/*.js.*
bindings_generator/node_modules/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ void main() {
<!-- START updated by tool/update_bindings.dart. Do not modify by hand -->
Based on [`@webref/idl 3.39.1`](https://www.npmjs.com/package/@webref/idl/v/3.39.1).
<!-- END updated by tool/update_bindings.dart. Do not modify by hand -->

For instructions on re-generating the DOM bindings, see
(bindings_generator/README.md)[bindings_generator/README.md].
19 changes: 19 additions & 0 deletions bindings_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The bindings generator for `package:web`.

This tool is written in Dart, compiled to JavaScript, and run on Node.

## Generating the bindings

Run:

```
dart tool/update_bindings.dart
```

## Update to the latest Web IDL versions and regenerate

Run:

```
dart tool/update_bindings.dart --update
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ const Map<String, String?> jsTypeSupertypes = {
'JSUint16Array': 'JSTypedArray',
'JSUint32Array': 'JSTypedArray',
'JSUint8Array': 'JSTypedArray',
'JSUint8ClampedArray': 'JSTypedArray'
'JSUint8ClampedArray': 'JSTypedArray',
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion test/type_union_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import '../tool/bindings_generator/type_union.dart';

import '../bindings_generator/type_union.dart';

void main() {
test('Non-JS types', () {
Expand Down
17 changes: 0 additions & 17 deletions tool/bindings_generator/README.md

This file was deleted.

41 changes: 19 additions & 22 deletions tool/update_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ $_usage''');

assert(p.fromUri(Platform.script).endsWith(_thisScript));

// Run `npm install` or `npm upgrade` as needed.
if (argResult['update'] as bool) {
await _runProc('npm', ['update'], workingDirectory: _bindingsGeneratorPath);
} else {
await _runProc('npm', ['install'],
workingDirectory: _bindingsGeneratorPath);
}
// Run `npm install` or `npm update` as needed.
final update = argResult['update'] as bool;
await _runProc(
'npm',
[update ? 'update' : 'install'],
workingDirectory: _bindingsGeneratorPath,
);

// Compute JS type supertypes for union calculation in translator.
await _generateJsTypeSupertypes();
Expand Down Expand Up @@ -79,7 +79,7 @@ $_usage''');
// Run app with `node`.
await _runProc(
'node',
['main.mjs', '../../lib/src'],
['main.mjs', '../lib/src'],
workingDirectory: _bindingsGeneratorPath,
);

Expand All @@ -93,7 +93,7 @@ $_usage''');

// Update readme.
final readmeFile = File(
p.normalize(p.join(_bindingsGeneratorPath, '..', '..', 'README.md')),
p.normalize(p.join(_bindingsGeneratorPath, '..', 'README.md')),
);

final sourceContent = readmeFile.readAsStringSync();
Expand Down Expand Up @@ -138,8 +138,7 @@ String _webRefIdlVersion() {
return webRefIdl['version'] as String;
}

final _bindingsGeneratorPath =
p.fromUri(Platform.script.resolve('bindings_generator/'));
const _bindingsGeneratorPath = 'bindings_generator';

const _webRefIdl = '@webref/idl';

Expand Down Expand Up @@ -194,6 +193,7 @@ Future<void> _generateJsTypeSupertypes() async {
// the old code.
void storeSupertypes(InterfaceElement element) {
if (!_isInJsTypesOrJsInterop(element)) return;

String? parentJsType;
final supertype = element.supertype;
final immediateSupertypes = <InterfaceType>[
Expand Down Expand Up @@ -222,22 +222,19 @@ Future<void> _generateJsTypeSupertypes() async {
}

final jsTypeSupertypesScript = '''
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Updated by $_thisScript. Do not modify by hand.
// Updated by $_thisScript. Do not modify by hand.
const Map<String, String?> jsTypeSupertypes = $jsTypeSupertypes;
''';
const Map<String, String?> jsTypeSupertypes = {
${jsTypeSupertypes.entries.map((e) => " ${e.key}: ${e.value},").join('\n')}
};
''';
final jsTypeSupertypesPath =
p.join(_bindingsGeneratorPath, 'js_type_supertypes.dart');
await File(jsTypeSupertypesPath).writeAsString(jsTypeSupertypesScript);
await _runProc(
Platform.executable,
['format', jsTypeSupertypesPath],
workingDirectory: _bindingsGeneratorPath,
);
}

final _usage = '''
Expand Down

0 comments on commit e170bf2

Please sign in to comment.