Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPLAT-6212: Add dedicated sass entrypoint #123

Merged
merged 3 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/sass.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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
main,
sassCliArgs,
sourceDirArg,
sourceDirDefaultValue,
outputDirArg,
outputDirDefaultValue,
watchDirsArg,
outputStyleArg,
expandedOutputStyleFileExtensionArg,
expandedOutputStyleFileExtensionDefaultValue,
compressedOutputStyleFileExtensionArg,
compressedOutputStyleFileExtensionDefaultValue;
86 changes: 43 additions & 43 deletions lib/src/bin/compile_sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,46 @@ const Map<String, sass.OutputStyle> 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 <String>[],
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<String> unparsedArgs;
final String expandedOutputStyleFileExtension;
Expand All @@ -70,8 +110,6 @@ class SassCompilationOptions {
? '.min.css'
: compressedOutputStyleFileExtension ??
compressedOutputStyleFileExtensionDefaultValue;
print(
'_compressedOutputStyleFileExtension: $_compressedOutputStyleFileExtension');

if (outputStyles.length > 1 &&
this.compressedOutputStyleFileExtension ==
Expand Down Expand Up @@ -159,52 +197,14 @@ class SassCompilationOptions {

Future<Null> main(List<String> 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 <String>[],
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<String> outputStylesValue;
bool helpValue;

SassCompilationOptions options;

try {
final results = parser.parse(args);
final results = sassCliArgs.parse(args);
outputStylesValue = results[outputStyleArg];
helpValue = results[helpFlag];

Expand All @@ -224,13 +224,13 @@ Future<Null> main(List<String> 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(() {});
}
Expand Down