Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit ffd8331

Browse files
authored
feat(core): add static scss mixin (#940)
Fixes #783
1 parent 1548727 commit ffd8331

13 files changed

+142
-465
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"karma-jasmine": "^1.1.2",
102102
"karma-sauce-launcher": "^1.2.0",
103103
"karma-sourcemap-loader": "^0.3.7",
104-
"madge": "^3.3.0",
105104
"magic-string": "^0.22.5",
106105
"merge2": "^1.2.3",
107106
"minimatch": "^3.0.4",

src/lib/core/sass/_layout-bp.scss

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
@charset "UTF-8";
2+
3+
// Non-overlapping Material Design breakpoints
4+
// @type map
5+
$breakpoints: (
6+
xs: (
7+
begin: 0,
8+
end: 599px
9+
),
10+
sm: (
11+
begin: 600px,
12+
end: 959px
13+
),
14+
md: (
15+
begin: 960px,
16+
end: 1279px
17+
),
18+
lg: (
19+
begin: 1280px,
20+
end: 1919px
21+
),
22+
xl: (
23+
begin: 1920px,
24+
end: 5000px
25+
),
26+
) !default;
27+
28+
// Overlapping breakpoints that are greater than defined
29+
// Material Design breakpoints
30+
// @type map
31+
$overlapping-gt: (
32+
xs: 600px,
33+
sm: 960px,
34+
md: 1280px,
35+
lg: 1920px,
36+
) !default;
37+
38+
// Overlapping breakpoints that are less than defined
39+
// Material Design breakpoints
40+
// @type map
41+
$overlapping-lt: (
42+
sm: 599px,
43+
md: 959px,
44+
lg: 1279px,
45+
xl: 1919px,
46+
) !default;
47+
48+
49+
// Media Query Mixin, takes a breakpoint and returns a wrapping
50+
// media query statement
51+
// e.g.
52+
//
53+
// @include layout-bp(xs) {
54+
// background-color: red;
55+
// }
56+
//
57+
// becomes
58+
//
59+
// @media (min-width: 0px) and (max-width: 599px) {
60+
// background-color: red;
61+
// }
62+
@mixin layout-bp($bp) {
63+
@if map-has-key($breakpoints, $bp) {
64+
$min: map-get(map-get($breakpoints, $bp), begin);
65+
$max: map-get(map-get($breakpoints, $bp), end);
66+
@media (min-width: $min) and (max-width: $max) { @content; }
67+
}
68+
@else if map-has-key($overlapping-gt, $bp) {
69+
$min: map-get($breakpoints, $bp);
70+
@media (min-width: $min) { @content; }
71+
}
72+
@else if map-has-key($overlapping-lt, $bp) {
73+
$max: map-get($breakpoints, $bp);
74+
@media (max-width: $max) { @content; }
75+
}
76+
}

stylelint-config.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"shorthand-property-no-redundant-values": true,
2929

3030
"property-case": "lower",
31+
"no-duplicate-at-import-rules": true,
3132

32-
"declaration-block-no-duplicate-properties": [ true, {
33+
"declaration-block-no-duplicate-properties": [true, {
3334
"ignore": ["consecutive-duplicates-with-different-values"]
3435
}],
3536
"declaration-block-trailing-semicolon": "always",
@@ -39,8 +40,8 @@
3940
"declaration-block-semicolon-newline-before": "never-multi-line",
4041
"declaration-block-semicolon-newline-after": "always-multi-line",
4142
"declaration-property-value-blacklist": [
42-
{ "/.*/": ["initial"] },
43-
{ "message": "The `initial` value is not supported in IE."}
43+
{"/.*/": ["initial"]},
44+
{"message": "The `initial` value is not supported in IE."}
4445
],
4546

4647
"block-closing-brace-newline-after": "always",
@@ -61,6 +62,8 @@
6162
"selector-type-case": "lower",
6263
"selector-max-id": 0,
6364
"no-missing-end-of-source-newline": true,
64-
"max-line-length": 100
65+
"no-eol-whitespace": true,
66+
"max-line-length": 100,
67+
"linebreaks": "unix"
6568
}
6669
}

tools/gulp/tasks/aot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {task} from 'gulp';
22
import {existsSync} from 'fs';
33
import {join} from 'path';
44
import {buildConfig, sequenceTask} from 'lib-build-tools';
5-
import {execTask} from '../util/task_helpers';
5+
import {execTask} from '../util/task-helpers';
66

77
const {outputDir, packagesDir, projectVersion} = buildConfig;
88

tools/gulp/tasks/build-release.ts

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
import {task} from 'gulp';
2-
import {composeRelease, sequenceTask} from 'lib-build-tools';
2+
import {mkdirpSync, writeFileSync} from 'fs-extra';
3+
import {buildConfig, composeRelease, sequenceTask} from 'lib-build-tools';
4+
import {join} from 'path';
5+
import {Bundler} from 'scss-bundle';
36
import {flexLayoutPackage} from '../packages';
7+
8+
const distDir = buildConfig.outputDir;
9+
const {sourceDir} = flexLayoutPackage;
10+
11+
/** Path to the directory where all releases are created. */
12+
const releasesDir = join(distDir, 'releases');
13+
14+
// Path to the release output of material.
15+
const releasePath = join(releasesDir, 'flex-layout');
16+
17+
// Matches all SCSS files in the different packages. Note that this glob is not used to build
18+
// the bundle. It's used to identify Sass files that shouldn't be included multiple times.
19+
const allScssDedupeGlob = join(buildConfig.packagesDir, '**/*.scss');
20+
21+
// The entry-point for the scss theming bundle.
22+
const themingEntryPointPath = join(sourceDir, 'core', 'sass', '_layout-bp.scss');
23+
24+
// Output path for the scss theming bundle.
25+
const themingBundlePath = join(releasePath, '_mq.scss');
26+
427
/**
528
* Overwrite the release task for the Flex-Layout package. The Flex-Layout release
629
* will include special files, like a bundled theming SCSS file or all prebuilt themes.
@@ -14,6 +37,19 @@ task('flex-layout:build-release', ['flex-layout:prepare-release'], () => {
1437
* a bundled SCSS file for theming
1538
*/
1639
task('flex-layout:prepare-release', sequenceTask(
17-
'flex-layout:build'
40+
['flex-layout:build'],
41+
['flex-layout:bundle-theming-scss'],
1842
));
1943

44+
/** Bundles all scss requires for theming into a single scss file in the root of the package. */
45+
task('flex-layout:bundle-theming-scss', () => {
46+
// Instantiates the SCSS bundler and bundles all imports of the specified entry point SCSS file.
47+
// A glob of all SCSS files in the library will be passed to the bundler. The bundler takes an
48+
// array of globs, which will match SCSS files that will be only included once in the bundle.
49+
return new Bundler().Bundle(themingEntryPointPath, [allScssDedupeGlob]).then(result => {
50+
// The release directory is not created yet because the composing of the release happens when
51+
// this task finishes.
52+
mkdirpSync(releasePath);
53+
writeFileSync(themingBundlePath, result.bundledContent);
54+
});
55+
});

tools/gulp/tasks/clean.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {task} from 'gulp';
2-
import {cleanTask} from '../util/task_helpers';
2+
import {cleanTask} from '../util/task-helpers';
33
import {buildConfig} from 'lib-build-tools';
44

55

tools/gulp/tasks/development.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {task} from 'gulp';
2-
import {execTask} from '../util/task_helpers';
2+
import {execTask} from '../util/task-helpers';
33
import {join} from 'path';
44
import {
55
buildConfig, copyFiles, sequenceTask, watchFiles

tools/gulp/tasks/hello-world.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {task} from 'gulp';
22
import {existsSync} from 'fs';
33
import {join} from 'path';
44
import {buildConfig, sequenceTask} from 'lib-build-tools';
5-
import {execTask} from '../util/task_helpers';
5+
import {execTask} from '../util/task-helpers';
66

77
const {outputDir, packagesDir, projectVersion} = buildConfig;
88

tools/gulp/tasks/lint.ts

+5-35
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,21 @@
11
import {task} from 'gulp';
2-
import {execNodeTask} from '../util/task_helpers';
3-
import {join} from 'path';
4-
import {buildConfig} from 'lib-build-tools';
5-
import {red} from 'chalk';
6-
7-
// These types lack of type definitions
8-
const madge = require('madge');
2+
import {execNodeTask} from '../util/task-helpers';
93

104
/** Glob that matches all SCSS or CSS files that should be linted. */
11-
const stylesGlob = '+(tools|src)/**/!(*.bundle).+(css|scss)';
5+
const styleGlob = 'src/lib/**/*.+(css|scss)';
126

137
/** List of flags that will passed to the different TSLint tasks. */
148
const tsLintBaseFlags = ['-c', 'tslint.json', '--project', './tsconfig.json'];
159

16-
/** Path to the output of the Flex-Layout package. */
17-
const libOutPath = join(buildConfig.outputDir, 'packages', 'flex-layout');
18-
19-
task('lint', ['tslint', 'stylelint', 'madge']);
20-
21-
10+
task('lint', ['tslint', 'stylelint']);
2211

23-
/** Task to lint Angular Flex-Layout's scss stylesheets. */
12+
/** Task to lint Angular Layout's scss stylesheets. */
2413
task('stylelint', execNodeTask(
25-
'stylelint', [stylesGlob, '--config', 'stylelint-config.json', '--syntax', 'scss']
14+
'stylelint', [styleGlob, '--config', 'stylelint-config.json', '--syntax', 'scss']
2615
));
2716

2817
/** Task to run TSLint against the e2e/ and src/ directories. */
2918
task('tslint', execNodeTask('tslint', tsLintBaseFlags));
3019

3120
/** Task that automatically fixes TSLint warnings. */
3221
task('tslint:fix', execNodeTask('tslint', [...tsLintBaseFlags, '--fix']));
33-
34-
/** Task that runs madge to detect circular dependencies. */
35-
task('madge', ['flex-layout:clean-build'], () => {
36-
madge([libOutPath]).then((res: any) => {
37-
const circularModules = res.circular();
38-
39-
if (circularModules.length) {
40-
console.error();
41-
console.error(red(`Madge found modules with circular dependencies.`));
42-
console.error(formatMadgeCircularModules(circularModules));
43-
console.error();
44-
}
45-
});
46-
});
47-
48-
/** Returns a string that formats the graph of circular modules. */
49-
function formatMadgeCircularModules(circularModules: string[][]): string {
50-
return circularModules.map((modulePaths: string[]) => `\n - ${modulePaths.join(' > ')}`).join('');
51-
}

tools/gulp/tasks/publish.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {spawn} from 'child_process';
22
import {existsSync, statSync} from 'fs-extra';
33
import {join} from 'path';
44
import {task} from 'gulp';
5-
import {execTask} from '../util/task_helpers';
5+
import {execTask} from '../util/task-helpers';
66
import {buildConfig, sequenceTask} from 'lib-build-tools';
77
import {yellow, green, red, grey} from 'chalk';
88
import * as minimist from 'minimist';

tools/gulp/tasks/universal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {task} from 'gulp';
22
import {existsSync} from 'fs';
3-
import {execTask} from '../util/task_helpers';
3+
import {execTask} from '../util/task-helpers';
44
import {join} from 'path';
55
import {buildConfig, sequenceTask} from 'lib-build-tools';
66

File renamed without changes.

0 commit comments

Comments
 (0)