Index: site/try/build_sdk_json.dart |
diff --git a/site/try/build_sdk_json.dart b/site/try/build_sdk_json.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b46cc77ade65eb456df48c4c0104a4c9bd6e7b7e |
--- /dev/null |
+++ b/site/try/build_sdk_json.dart |
@@ -0,0 +1,47 @@ |
+// Copyright (c) 2013, 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. |
+ |
+import 'dart:io'; |
+import 'dart:convert'; |
+import 'package:compiler/src/util/uri_extras.dart' show relativize; |
+ |
+main(List<String> arguments) async { |
+ if (arguments.length == 0) { |
+ print('usage: jsonify.dart <out-path>'); |
Harry Terkelsen
2016/05/24 16:17:30
usage: build_sdk_json.dart <out-path>
Siggi Cherem (dart-lang)
2016/05/24 16:50:34
Done.
|
+ exit(1); |
+ } |
+ |
+ var out = arguments[0]; |
+ List<Uri> sdkFiles = await collectSdkFiles(); |
+ new File(out).writeAsStringSync(emitSdkAsJson(sdkFiles)); |
+} |
+ |
+Uri sdkRoot = Uri.base.resolveUri(Platform.script).resolve('../../'); |
+ |
+/// Collects a list of files that are part of the SDK. |
+List<Uri> collectSdkFiles() { |
+ var files = <Uri>[]; |
+ for (var entity in new |
+ Directory.fromUri(sdkRoot.resolve('sdk/lib/')).listSync(recursive: true)) { |
Harry Terkelsen
2016/05/24 16:17:30
run dartfmt on this?
Siggi Cherem (dart-lang)
2016/05/24 16:50:34
Done. Split out subexpression to make it more read
|
+ if (entity is File && |
+ (entity.path.endsWith('.dart') || entity.path.endsWith('.platform'))) { |
+ files.add(entity.uri); |
+ } |
+ } |
+ return files; |
+} |
+ |
+/// Creates a string that encodes the contents of the sdk libraries in json. |
+/// |
+/// The keys of the json file are sdk-relative paths to source files, and the |
+/// values are the contents of the file. |
+String emitSdkAsJson(List<Uri> paths) { |
+ var map = <String, String>{}; |
+ for (var uri in paths) { |
+ String filename = relativize(sdkRoot, uri, false); |
Harry Terkelsen
2016/05/24 16:17:30
out of scope for this CL but the boolean flag for
Siggi Cherem (dart-lang)
2016/05/24 16:50:34
Agree - in the future we should also migrate to us
|
+ var contents = new File.fromUri(uri).readAsStringSync(); |
+ map['sdk:/$filename'] = contents; |
+ } |
+ return JSON.encode(map); |
+} |