Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: tool/grind.dart

Issue 1640023002: Support deploying an npm package exporting a formatCode method. (Closed) Base URL: git@github.com:dart-lang/dart_style.git@master
Patch Set: ptal Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tool/grind.dart
diff --git a/tool/grind.dart b/tool/grind.dart
index 5a9b1c697f05fe92b9c1dd309b9caf2a2e883b60..4d5b55b2a0ba98c9e2d096254eb60c0a0a6a5230 100644
--- a/tool/grind.dart
+++ b/tool/grind.dart
@@ -3,9 +3,14 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:grinder/grinder.dart';
+import 'package:grinder/src/run.dart' as runner;
+import "package:node_preamble/preamble.dart" as preamble;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart' as yaml;
+import 'dart:convert';
+import 'dart:io';
Bob Nystrom 2016/01/27 21:53:46 The blank line is good, but these go *above* the p
+
/// Matches the version line in dart_style's pubspec.
final _versionPattern = new RegExp(r"^version: .*$", multiLine: true);
@@ -24,6 +29,40 @@ validate() async {
Dart.run("bin/format.dart", arguments: ["-w", "."]);
}
+@Task('Publish to npm')
+npm() {
+ var out = 'dist';
+
+ var pubspec = yaml.loadYaml(getFile("pubspec.yaml").readAsStringSync());
+ var homepage = pubspec["homepage"];
+ var fileName = 'index.js';
+
+ // Generate modified dart2js output suitable to run on node.
+ var tempFile = new File('${Directory.systemTemp.path}/temp.js');
+
+ Dart2js.compile(new File('tool/node_format_service.dart'),
+ outFile: tempFile, categories: 'all');
+ var dart2jsOutput = tempFile.readAsStringSync();
+ new File('$out/$fileName').writeAsStringSync('''${preamble.getPreamble()}
+self.exports = exports; // Temporary hack for Dart-JS Interop under node.
+$dart2jsOutput''');
+
+ new File('$out/package.json')
+ .writeAsStringSync(const JsonEncoder.withIndent(' ').convert({
+ "name": "dart-style",
+ "version": pubspec["version"],
+ "description": pubspec["description"],
+ "main": fileName,
+ "scripts": {"test": "echo \"Error: no test specified\" && exit 1"},
+ "repository": {"type": "git", "url": "git+$homepage"},
+ "author": pubspec["author"],
+ "license": "BSD",
+ "bugs": {"url": "$homepage/issues"},
+ "homepage": homepage
+ }));
+ run('npm', arguments: ['publish', out]);
+}
+
/// Gets ready to publish a new version of the package.
///
/// To publish a version, you need to:
« pubspec.yaml ('K') | « pubspec.yaml ('k') | tool/node_format_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698