Skip to content

Commit

Permalink
Add timestamp to printed compile statement (#1876)
Browse files Browse the repository at this point in the history
Co-authored-by: dannypernik <[email protected]>
Co-authored-by: Natalie Weizenbaum <[email protected]>
Co-authored-by: なつき <[email protected]>
  • Loading branch information
4 people authored Feb 17, 2023
1 parent 13cc7d2 commit c452388
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 98 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 1.58.2

### Command Line Interface

* Add a timestamp to messages printed in `--watch` mode.

* Print better `calc()`-based suggestions for `/`-as-division expression that
contain calculation-incompatible constructs like unary minus.

Expand Down
10 changes: 9 additions & 1 deletion lib/src/executable/compile_stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ Future<void> compileStylesheet(ExecutableOptions options, StylesheetGraph graph,

if (options.quiet || (!options.update && !options.watch)) return;
var buffer = StringBuffer();
if (options.color) buffer.write('\u001b[32m');

var sourceName = source == null ? 'stdin' : p.prettyUri(p.toUri(source));
// `destination` is guaranteed to be non-null in update and watch mode.
var destinationName = p.prettyUri(p.toUri(destination!));

var nowStr = DateTime.now().toString();
// Remove fractional seconds from printed timestamp
var timestamp = nowStr.substring(0, nowStr.length - 7);

if (options.color) buffer.write('\u001b[90m');
buffer.write('[$timestamp] ');
if (options.color) buffer.write('\u001b[32m');
buffer.write('Compiled $sourceName to $destinationName.');
if (options.color) buffer.write('\u001b[0m');

print(buffer);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.58.2-dev
version: 1.58.2
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
22 changes: 11 additions & 11 deletions test/cli/shared/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await d.file("test.scss", "a {b: c}").create();

var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled test.scss to out.css.')));
await sass.shouldExit(0);

await d
Expand All @@ -32,7 +32,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await d.file("test.scss", "a {b: c}").create();

var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled test.scss to out.css.')));
await sass.shouldExit(0);

await d
Expand All @@ -45,14 +45,14 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await d.file("test.scss", "@import 'other'").create();

var sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled test.scss to out.css.')));
await sass.shouldExit(0);

await tick;
await d.file("other.scss", "x {y: z}").create();

sass = await update(["test.scss:out.css"]);
expect(sass.stdout, emits('Compiled test.scss to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled test.scss to out.css.')));
await sass.shouldExit(0);

await d
Expand All @@ -66,16 +66,16 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await d.file("test2.scss", r"$var: 2; @import 'other'").create();

var sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test1.scss to out1.css.'));
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
expect(sass.stdout, emits(endsWith('Compiled test1.scss to out1.css.')));
expect(sass.stdout, emits(endsWith('Compiled test2.scss to out2.css.')));
await sass.shouldExit(0);

await tick;
await d.file("other.scss", r"x {y: $var}").create();

sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test1.scss to out1.css.'));
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
expect(sass.stdout, emits(endsWith('Compiled test1.scss to out1.css.')));
expect(sass.stdout, emits(endsWith('Compiled test2.scss to out2.css.')));
await sass.shouldExit(0);

await d
Expand All @@ -90,7 +90,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
var sass = await update(["-:out.css"]);
sass.stdin.writeln("a {b: c}");
sass.stdin.close();
expect(sass.stdout, emits('Compiled stdin to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled stdin to out.css.')));
await sass.shouldExit(0);

await d
Expand All @@ -100,7 +100,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
sass = await update(["-:out.css"]);
sass.stdin.writeln("x {y: z}");
sass.stdin.close();
expect(sass.stdout, emits('Compiled stdin to out.css.'));
expect(sass.stdout, emits(endsWith('Compiled stdin to out.css.')));
await sass.shouldExit(0);

await d
Expand Down Expand Up @@ -142,7 +142,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await d.file("test2.scss", "d {e: f}").create();

var sass = await update(["test1.scss:out1.css", "test2.scss:out2.css"]);
expect(sass.stdout, emits('Compiled test2.scss to out2.css.'));
expect(sass.stdout, emits(endsWith('Compiled test2.scss to out2.css.')));
await sass.shouldExit(0);

await d.file("out1.css", "x {y: z}").validate();
Expand Down
Loading

0 comments on commit c452388

Please sign in to comment.