Skip to content

Commit

Permalink
Switch (partially) to sass_builder plugin
Browse files Browse the repository at this point in the history
Now the global style sheet is built automatically when any of its
SASS files are modified. A project that uses this will have to
creates its own web/theme.scss and import our main scss file to
use it.

I haven't tested this on component SCSS yet.
  • Loading branch information
mehaase committed Mar 8, 2019
1 parent 17d4450 commit d91c6a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 80 deletions.
50 changes: 25 additions & 25 deletions lib/src/modular-admin/modular-admin.scss
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/*
* Import mixins.
*/
@import 'bootstrap/variables';
@import 'bootstrap/mixins';
@import 'modular-admin/mixins';
@import '../bootstrap/variables';
@import '../bootstrap/mixins';
@import 'mixins';

/*
* Import all of Open Sans.
*/
$OpenSansPath: "../open-sans/fonts" !default;
$OpenSansVersion: "1.1.0" !default;

@import 'open-sans/sass/mixins';
@import 'open-sans/sass/Light';
@import 'open-sans/sass/LightItalic';
@import 'open-sans/sass/Regular';
@import 'open-sans/sass/Italic';
@import 'open-sans/sass/Semibold';
@import 'open-sans/sass/SemiboldItalic';
@import 'open-sans/sass/Bold';
@import 'open-sans/sass/BoldItalic';
@import 'open-sans/sass/ExtraBold';
@import 'open-sans/sass/ExtraBoldItalic';
@import '../open-sans/sass/mixins';
@import '../open-sans/sass/Light';
@import '../open-sans/sass/LightItalic';
@import '../open-sans/sass/Regular';
@import '../open-sans/sass/Italic';
@import '../open-sans/sass/Semibold';
@import '../open-sans/sass/SemiboldItalic';
@import '../open-sans/sass/Bold';
@import '../open-sans/sass/BoldItalic';
@import '../open-sans/sass/ExtraBold';
@import '../open-sans/sass/ExtraBoldItalic';

/*
* Import some things we need from Bootstrap.
*/

$enable-flex: true;
@import 'bootstrap/reboot';
@import 'bootstrap/normalize';
@import 'bootstrap/grid';
@import 'bootstrap/code';
@import 'bootstrap/type';
@import 'bootstrap/utilities';
@import 'bootstrap/list-group';
@import '../bootstrap/reboot';
@import '../bootstrap/normalize';
@import '../bootstrap/grid';
@import '../bootstrap/code';
@import '../bootstrap/type';
@import '../bootstrap/utilities';
@import '../bootstrap/list-group';

/*
* Import Modular Admin.
*/
@import 'modular-admin/theme';
@import 'modular-admin/grid';
@import 'modular-admin/document';
@import 'modular-admin/typography';
@import 'theme';
@import 'grid';
@import 'document';
@import 'typography';
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dev_dependencies:
build_runner: ^1.0.0
build_test: ^0.10.2
build_web_compilers: ^0.4.0
sass_builder: ^2.1.2
10 changes: 10 additions & 0 deletions sass_builder.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
builders:
sass_builder:
target: "sass_builder"
import: "package:sass_builder/sass_builder.dart"
builder_factories: ["sassBuilder"]
auto_apply: dependents
build_extensions:
.scss: [".css"]
.sass: [".css"]
build_to: source
55 changes: 0 additions & 55 deletions tool/build-styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:path/path.dart' as path;
main (List<String> rawArgs) {
ArgResults args = _parseArgs(rawArgs);
buildComponentStyles(args['debug']);
buildSharedStyles(args['debug']);
}

/// Build a stylesheet for each component.
Expand Down Expand Up @@ -60,60 +59,6 @@ buildComponentStyles(bool debug) {
}
}

/// Build a stylesheet for each theme.
buildSharedStyles(bool debug) {
print('Building shared stylesheets…');
var themeDir = new Directory(_getPath('lib/src/modular-admin'));
var cssDir = _getPath('lib/css');
var includeDir = _getPath('lib/src');
var sourcePaths = new List<String>();

for (FileSystemEntity entity in themeDir.listSync()) {
String basename = path.basename(entity.path);
String extension = path.extension(entity.path);

if (basename.startsWith('_') || extension != '.scss') {
continue;
}

sourcePaths.add(entity.path);
}

sourcePaths.sort();

for (String sourcePath in sourcePaths) {
String basename = path.basename(sourcePath);
String themeName = basename.substring(0, basename.length - 5);
String destName = themeName + '.css';
String destPath = path.join(cssDir, themeName + '.css');

// TODO temporary hack, always build theme:
bool cached = false;//_styleSheetIsCurrent(sourcePath, destPath);

print(' * lib/src/modular-admin/' + basename +
' → lib/css/' + destName +
(cached ? ' (cached)' : ''));

if (cached) {
continue;
}

var sasscArgs = ['-I', includeDir];

if (!debug) {
sasscArgs.addAll(['-t', 'compressed']);
}

sasscArgs.addAll([sourcePath, destPath]);
var result = Process.runSync('sassc', sasscArgs);
if (result.exitCode != 0) {
print('ERROR: Failed to compile ' + sourcePath);
print(result.stderr);
exit(1);
}
}
}

/// Construct a full path from a path relative to the project toot.
String _getPath(String relPath) {
var scriptPath = Platform.script.toFilePath();
Expand Down

0 comments on commit d91c6a3

Please sign in to comment.