From 5b9a0fc8458c12a1e23c93802e9d06aa05e9a1d4 Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Thu, 20 Jun 2019 12:57:54 -0700 Subject: [PATCH 1/3] Add a separate sass entrypoint --- lib/sass.dart | 30 +++++++++++++ lib/src/bin/compile_sass.dart | 84 ++++++++++++++++++----------------- 2 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 lib/sass.dart diff --git a/lib/sass.dart b/lib/sass.dart new file mode 100644 index 00000000..eb7480f6 --- /dev/null +++ b/lib/sass.dart @@ -0,0 +1,30 @@ +// Copyright 2019 Workiva Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// Entry-point for consumers wanting to extend / utilize the CLI for the `compile_sass` pub executable. +library w_common.sass; + +export 'src/bin/compile_sass.dart' + show + sassCliArgs, + sourceDirArg, + sourceDirDefaultValue, + outputDirArg, + outputDirDefaultValue, + watchDirsArg, + outputStyleArg, + expandedOutputStyleFileExtensionArg, + expandedOutputStyleFileExtensionDefaultValue, + compressedOutputStyleFileExtensionArg, + compressedOutputStyleFileExtensionDefaultValue; diff --git a/lib/src/bin/compile_sass.dart b/lib/src/bin/compile_sass.dart index 900309af..da94d286 100644 --- a/lib/src/bin/compile_sass.dart +++ b/lib/src/bin/compile_sass.dart @@ -45,6 +45,46 @@ const Map outputStyleArgToOutputStyleValue = const { 'expanded': sass.OutputStyle.expanded, }; +/// The CLI options for `pub run w_common compile_sass`. +final ArgParser sassCliArgs = new ArgParser() + ..addMultiOption(outputStyleArg, + abbr: 's', + help: 'The output style used to format the compiled CSS.', + defaultsTo: outputStyleDefaultValue, + splitCommas: true) + ..addOption(expandedOutputStyleFileExtensionArg, + help: + 'The file extension that will be used for the CSS compiled using \n`expanded` outputStyle.', + defaultsTo: expandedOutputStyleFileExtensionDefaultValue) + ..addOption(compressedOutputStyleFileExtensionArg, + help: + 'The file extension that will be used for the CSS compiled using \n`compressed` outputStyle.\n' + '(defaults to $compressedOutputStyleFileExtensionDefaultValue, or .min.css\n' + ' if `--$outputStyleArg` contains more than one style)') + ..addOption(sourceDirArg, + help: + 'The directory where the `.scss` files that you want to compile live. \n(defaults to $sourceDirDefaultValue, or the value of `--$outputDirArg`, if specified.)') + ..addOption(outputDirArg, + help: + 'The directory where the compiled CSS should go. \n(defaults to $outputDirDefaultValue, or the value of `--$sourceDirArg`, if specified.)') + ..addMultiOption(watchDirsArg, + splitCommas: true, + defaultsTo: const [], + help: + 'Directories that should be watched in addition to `sourceDir`. \nOnly valid with --watch.') + ..addFlag(watchFlag, + negatable: false, + help: 'Watch stylesheets and recompile when they change.') + ..addFlag(checkFlag, + abbr: 'c', + negatable: false, + help: + 'When set to true, no `.css` outputs will be written to disk, \nand a non-zero exit code will be returned if `sass.compile()` \nproduces results that differ from those found in the committed \n`.css` files. \nIntended only for use as a CI safeguard.') + ..addFlag(helpFlag, + abbr: 'h', + negatable: false, + help: 'Prints usage instructions to the terminal.'); + class SassCompilationOptions { final List unparsedArgs; final String expandedOutputStyleFileExtension; @@ -159,44 +199,6 @@ class SassCompilationOptions { Future main(List args) async { taskTimer = new Stopwatch(); - final parser = new ArgParser() - ..addMultiOption(outputStyleArg, - abbr: 's', - help: 'The output style used to format the compiled CSS.', - defaultsTo: outputStyleDefaultValue, - splitCommas: true) - ..addOption(expandedOutputStyleFileExtensionArg, - help: - 'The file extension that will be used for the CSS compiled using \n`expanded` outputStyle.', - defaultsTo: expandedOutputStyleFileExtensionDefaultValue) - ..addOption(compressedOutputStyleFileExtensionArg, - help: - 'The file extension that will be used for the CSS compiled using \n`compressed` outputStyle.\n' - '(defaults to $compressedOutputStyleFileExtensionDefaultValue, or .min.css\n' - ' if `--$outputStyleArg` contains more than one style)') - ..addOption(sourceDirArg, - help: - 'The directory where the `.scss` files that you want to compile live. \n(defaults to $sourceDirDefaultValue, or the value of `--$outputDirArg`, if specified.)') - ..addOption(outputDirArg, - help: - 'The directory where the compiled CSS should go. \n(defaults to $outputDirDefaultValue, or the value of `--$sourceDirArg`, if specified.)') - ..addMultiOption(watchDirsArg, - splitCommas: true, - defaultsTo: const [], - help: - 'Directories that should be watched in addition to `sourceDir`. \nOnly valid with --watch.') - ..addFlag(watchFlag, - negatable: false, - help: 'Watch stylesheets and recompile when they change.') - ..addFlag(checkFlag, - abbr: 'c', - negatable: false, - help: - 'When set to true, no `.css` outputs will be written to disk, \nand a non-zero exit code will be returned if `sass.compile()` \nproduces results that differ from those found in the committed \n`.css` files. \nIntended only for use as a CI safeguard.') - ..addFlag(helpFlag, - abbr: 'h', - negatable: false, - help: 'Prints usage instructions to the terminal.'); List outputStylesValue; bool helpValue; @@ -204,7 +206,7 @@ Future main(List args) async { SassCompilationOptions options; try { - final results = parser.parse(args); + final results = sassCliArgs.parse(args); outputStylesValue = results[outputStyleArg]; helpValue = results[helpFlag]; @@ -224,13 +226,13 @@ Future main(List args) async { check: results[checkFlag], ); } on FormatException { - print(parser.usage); + print(sassCliArgs.usage); exitCode = 1; rethrow; } if (helpValue) { - print(parser.usage); + print(sassCliArgs.usage); exitCode = 0; return new Future(() {}); } From 4df01776aef9aca84ecb6bbfe9c19547b2be1dcc Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Thu, 20 Jun 2019 12:58:15 -0700 Subject: [PATCH 2/3] LOG --- lib/src/bin/compile_sass.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/bin/compile_sass.dart b/lib/src/bin/compile_sass.dart index da94d286..aca3ec92 100644 --- a/lib/src/bin/compile_sass.dart +++ b/lib/src/bin/compile_sass.dart @@ -110,8 +110,6 @@ class SassCompilationOptions { ? '.min.css' : compressedOutputStyleFileExtension ?? compressedOutputStyleFileExtensionDefaultValue; - print( - '_compressedOutputStyleFileExtension: $_compressedOutputStyleFileExtension'); if (outputStyles.length > 1 && this.compressedOutputStyleFileExtension == From 53b16a9cef121362e2db89a2466b5998489cf9c1 Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Fri, 21 Jun 2019 13:33:23 -0700 Subject: [PATCH 3/3] Expose main compile_sass entrypoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + So that consumers like dart_dev don’t have to require that their consumers have a non-transitive dependency on of w_common in order to use their pub script that proxies ours. --- lib/sass.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sass.dart b/lib/sass.dart index eb7480f6..fb60dfc0 100644 --- a/lib/sass.dart +++ b/lib/sass.dart @@ -17,6 +17,7 @@ library w_common.sass; export 'src/bin/compile_sass.dart' show + main, sassCliArgs, sourceDirArg, sourceDirDefaultValue,