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

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
« no previous file with comments | « pubspec.yaml ('k') | tool/node_format_service.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/grind.dart
diff --git a/tool/grind.dart b/tool/grind.dart
index 5a9b1c697f05fe92b9c1dd309b9caf2a2e883b60..4b6105f20b7b4c417c1185c8530d821eb3a97e33 100644
--- a/tool/grind.dart
+++ b/tool/grind.dart
@@ -2,7 +2,12 @@
// 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:convert';
+import 'dart:io';
+
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;
@@ -24,6 +29,41 @@ 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,
+ "typings": "dart-style.d.ts",
+ "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:
« no previous file with comments | « pubspec.yaml ('k') | tool/node_format_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698