@terrazzo/plugin-sass 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/build.d.ts +7 -0
- package/dist/build.js +40 -0
- package/dist/build.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +30 -0
- package/dist/lib.js.map +1 -0
- package/package.json +47 -0
- package/src/build.ts +51 -0
- package/src/index.ts +25 -0
- package/src/lib.ts +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Drew Powers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BuildHookOptions } from '@terrazzo/parser';
|
|
2
|
+
import { type SassPluginOptions } from './lib.js';
|
|
3
|
+
export interface BuildParams {
|
|
4
|
+
getTransforms: BuildHookOptions['getTransforms'];
|
|
5
|
+
options?: SassPluginOptions;
|
|
6
|
+
}
|
|
7
|
+
export default function build({ getTransforms, options }: BuildParams): string;
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
+
import { defaultAliasTransform } from '@terrazzo/token-tools/css';
|
|
3
|
+
import { FILE_HEADER, MIXIN_TOKEN, MIXIN_TYPOGRAPHY } from './lib.js';
|
|
4
|
+
export default function build({ getTransforms, options }) {
|
|
5
|
+
const tokens = getTransforms({ format: 'css', id: '*', mode: '.' });
|
|
6
|
+
const output = [FILE_HEADER, ''];
|
|
7
|
+
// main values
|
|
8
|
+
output.push('$__token-values: (');
|
|
9
|
+
for (const token of tokens) {
|
|
10
|
+
if (isTokenMatch(token.token.id, options?.exclude ?? [])) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
// typography tokens handled later
|
|
14
|
+
if (token.token.$type === 'typography') {
|
|
15
|
+
output.push(` "${token.token.id}": (
|
|
16
|
+
"__tz-error": 'This is a typography mixin. Use \`@include typography("${token.token.id}")\` instead.',
|
|
17
|
+
),`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const name = token.localID ?? token.token.id;
|
|
21
|
+
output.push(` "${token.token.id}": (${defaultAliasTransform(name)}),`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
output.push(');', '');
|
|
25
|
+
// typography mixins
|
|
26
|
+
output.push('$__token-typography-mixins: (');
|
|
27
|
+
const typographyTokens = getTransforms({ format: 'css', id: '*', mode: '.', $type: 'typography' });
|
|
28
|
+
for (const token of typographyTokens) {
|
|
29
|
+
output.push(` "${token.token.id}": (`);
|
|
30
|
+
for (const property of Object.keys(token.value)) {
|
|
31
|
+
const name = `${token.localID ?? token.token.id}-${property}`;
|
|
32
|
+
output.push(` "${property}": (${defaultAliasTransform(name)}),`);
|
|
33
|
+
}
|
|
34
|
+
output.push(' ),');
|
|
35
|
+
}
|
|
36
|
+
output.push(');', '');
|
|
37
|
+
output.push(MIXIN_TOKEN, '', MIXIN_TYPOGRAPHY, '');
|
|
38
|
+
return output.join('\n');
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAA0B,MAAM,UAAU,CAAC;AAO9F,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,aAAa,EAAE,OAAO,EAAe;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAEpE,MAAM,MAAM,GAAa,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAE3C,cAAc;IACd,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;YACzD,SAAS;QACX,CAAC;QACD,kCAAkC;QAClC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,YAAY,EAAE,CAAC;YACvC,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,EAAE;4EACsC,KAAK,CAAC,KAAK,CAAC,EAAE;KACrF,CAAC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEtB,oBAAoB;IACpB,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAE7C,MAAM,gBAAgB,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IACnG,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;QACxC,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,QAAQ,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC,QAAQ,QAAQ,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEtB,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAEnD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @terrazzo/plugin-sass
|
|
3
|
+
* @license MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2021 Drew Powers
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
import build from './build.js';
|
|
26
|
+
export default function pluginSass(options) {
|
|
27
|
+
const filename = options?.filename ?? 'index.scss';
|
|
28
|
+
return {
|
|
29
|
+
name: '@terrazzo/plugin-sass',
|
|
30
|
+
enforce: 'post',
|
|
31
|
+
config(config) {
|
|
32
|
+
// plugin-css is required for transforms. throw error
|
|
33
|
+
if (!config.plugins.some((p) => p.name === '@terrazzo/plugin-css')) {
|
|
34
|
+
throw new Error(`@terrazzo/plugin-sass relies on @terrazzo/plugin-css.
|
|
35
|
+
Please install @terrazzo/plugin-css and follow setup to add to your config.`);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async build({ getTransforms, outputFile }) {
|
|
39
|
+
const output = build({ getTransforms, options });
|
|
40
|
+
outputFile(filename, output);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAA2B;IAC5D,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,YAAY,CAAC;IAEnD,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,MAAM;QACf,MAAM,CAAC,MAAM;YACX,qDAAqD;YACrD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,sBAAsB,CAAC,EAAE,CAAC;gBACnE,MAAM,IAAI,KAAK,CACb;4EACkE,CACnE,CAAC;YACJ,CAAC;QACH,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE;YACvC,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;YACjD,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CSSPluginOptions } from '@terrazzo/plugin-css';
|
|
2
|
+
export interface SassPluginOptions {
|
|
3
|
+
/** Where to output CSS */
|
|
4
|
+
filename?: CSSPluginOptions['filename'];
|
|
5
|
+
/** Glob patterns to exclude tokens from output */
|
|
6
|
+
exclude?: CSSPluginOptions['exclude'];
|
|
7
|
+
}
|
|
8
|
+
export declare const FILE_HEADER = "////\n/// Autogenerated by \u26CB Terrazzo. DO NOT EDIT!\n////\n\n@use \"sass:list\";\n@use \"sass:map\";";
|
|
9
|
+
export declare const MIXIN_TOKEN = "@function token($tokenName) {\n @if map.has-key($__token-values, $tokenName) == false {\n @error 'No token named \"#{$tokenName}\"';\n }\n $_token: map.get($__token-values, $tokenName);\n @if map.has-key($_token, \"__tz-error\") {\n @error map.get($_token, \"__tz-error\");\n }\n @return map.get($_token);\n}";
|
|
10
|
+
export declare const MIXIN_TYPOGRAPHY = "@mixin typography($tokenName, $modeName: \".\") {\n @if map.has-key($__token-typography-mixins, $tokenName) == false {\n @error 'No typography mixin named \"#{$tokenName}\"';\n }\n $_mixin: map.get($__token-typography-mixins, $tokenName);\n $_properties: map.get($_mixin, \".\");\n @if map.has-key($_mixin) {\n $_properties: map.get($_mixin);\n }\n @each $_property, $_value in $_properties {\n #{$_property}: #{$_value};\n }\n}";
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const FILE_HEADER = `////
|
|
2
|
+
/// Autogenerated by ⛋ Terrazzo. DO NOT EDIT!
|
|
3
|
+
////
|
|
4
|
+
|
|
5
|
+
@use "sass:list";
|
|
6
|
+
@use "sass:map";`;
|
|
7
|
+
export const MIXIN_TOKEN = `@function token($tokenName) {
|
|
8
|
+
@if map.has-key($__token-values, $tokenName) == false {
|
|
9
|
+
@error 'No token named "#{$tokenName}"';
|
|
10
|
+
}
|
|
11
|
+
$_token: map.get($__token-values, $tokenName);
|
|
12
|
+
@if map.has-key($_token, "__tz-error") {
|
|
13
|
+
@error map.get($_token, "__tz-error");
|
|
14
|
+
}
|
|
15
|
+
@return map.get($_token);
|
|
16
|
+
}`;
|
|
17
|
+
export const MIXIN_TYPOGRAPHY = `@mixin typography($tokenName, $modeName: ".") {
|
|
18
|
+
@if map.has-key($__token-typography-mixins, $tokenName) == false {
|
|
19
|
+
@error 'No typography mixin named "#{$tokenName}"';
|
|
20
|
+
}
|
|
21
|
+
$_mixin: map.get($__token-typography-mixins, $tokenName);
|
|
22
|
+
$_properties: map.get($_mixin, ".");
|
|
23
|
+
@if map.has-key($_mixin) {
|
|
24
|
+
$_properties: map.get($_mixin);
|
|
25
|
+
}
|
|
26
|
+
@each $_property, $_value in $_properties {
|
|
27
|
+
#{$_property}: #{$_value};
|
|
28
|
+
}
|
|
29
|
+
}`;
|
|
30
|
+
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;iBAKV,CAAC;AAElB,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;EASzB,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;EAY9B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@terrazzo/plugin-sass",
|
|
3
|
+
"description": "Generate scss/sass from your design tokens schema (requires @terrazzo/cli)",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Drew Powers",
|
|
7
|
+
"email": "drew@pow.rs"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"design tokens",
|
|
11
|
+
"design tokens community group",
|
|
12
|
+
"design system",
|
|
13
|
+
"dtcg",
|
|
14
|
+
"w3c",
|
|
15
|
+
"css",
|
|
16
|
+
"sass"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@terrazzo/cli": "^0.0.6",
|
|
23
|
+
"@terrazzo/plugin-css": "^0.0.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@types/mime": "^3.0.4",
|
|
27
|
+
"mime": "^3.0.0",
|
|
28
|
+
"svgo": "^3.2.0",
|
|
29
|
+
"@terrazzo/token-tools": "^0.0.2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@terrazzo/cli": "^0.0.6",
|
|
33
|
+
"@terrazzo/parser": "^0.0.6",
|
|
34
|
+
"@terrazzo/plugin-css": "^0.0.4"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "pnpm run build:clean && pnpm run build:ts && pnpm run build:license",
|
|
38
|
+
"build:clean": "del dist",
|
|
39
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
40
|
+
"build:license": "node ../../scripts/inject-license.js @terrazzo/plugin-sass dist/index.js",
|
|
41
|
+
"dev": "tsc -p tsconfig.build.json -w",
|
|
42
|
+
"lint": "biome check .",
|
|
43
|
+
"test": "pnpm run \"/^test:.*/\"",
|
|
44
|
+
"test:js": "vitest run",
|
|
45
|
+
"test:ts": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
+
import { defaultAliasTransform } from '@terrazzo/token-tools/css';
|
|
3
|
+
import type { BuildHookOptions } from '@terrazzo/parser';
|
|
4
|
+
import { FILE_HEADER, MIXIN_TOKEN, MIXIN_TYPOGRAPHY, type SassPluginOptions } from './lib.js';
|
|
5
|
+
|
|
6
|
+
export interface BuildParams {
|
|
7
|
+
getTransforms: BuildHookOptions['getTransforms'];
|
|
8
|
+
options?: SassPluginOptions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function build({ getTransforms, options }: BuildParams): string {
|
|
12
|
+
const tokens = getTransforms({ format: 'css', id: '*', mode: '.' });
|
|
13
|
+
|
|
14
|
+
const output: string[] = [FILE_HEADER, ''];
|
|
15
|
+
|
|
16
|
+
// main values
|
|
17
|
+
output.push('$__token-values: (');
|
|
18
|
+
for (const token of tokens) {
|
|
19
|
+
if (isTokenMatch(token.token.id, options?.exclude ?? [])) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
// typography tokens handled later
|
|
23
|
+
if (token.token.$type === 'typography') {
|
|
24
|
+
output.push(` "${token.token.id}": (
|
|
25
|
+
"__tz-error": 'This is a typography mixin. Use \`@include typography("${token.token.id}")\` instead.',
|
|
26
|
+
),`);
|
|
27
|
+
} else {
|
|
28
|
+
const name = token.localID ?? token.token.id;
|
|
29
|
+
output.push(` "${token.token.id}": (${defaultAliasTransform(name)}),`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
output.push(');', '');
|
|
33
|
+
|
|
34
|
+
// typography mixins
|
|
35
|
+
output.push('$__token-typography-mixins: (');
|
|
36
|
+
|
|
37
|
+
const typographyTokens = getTransforms({ format: 'css', id: '*', mode: '.', $type: 'typography' });
|
|
38
|
+
for (const token of typographyTokens) {
|
|
39
|
+
output.push(` "${token.token.id}": (`);
|
|
40
|
+
for (const property of Object.keys(token.value)) {
|
|
41
|
+
const name = `${token.localID ?? token.token.id}-${property}`;
|
|
42
|
+
output.push(` "${property}": (${defaultAliasTransform(name)}),`);
|
|
43
|
+
}
|
|
44
|
+
output.push(' ),');
|
|
45
|
+
}
|
|
46
|
+
output.push(');', '');
|
|
47
|
+
|
|
48
|
+
output.push(MIXIN_TOKEN, '', MIXIN_TYPOGRAPHY, '');
|
|
49
|
+
|
|
50
|
+
return output.join('\n');
|
|
51
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Plugin } from '@terrazzo/parser';
|
|
2
|
+
import build from './build.js';
|
|
3
|
+
import type { SassPluginOptions } from './lib.js';
|
|
4
|
+
|
|
5
|
+
export default function pluginSass(options?: SassPluginOptions): Plugin {
|
|
6
|
+
const filename = options?.filename ?? 'index.scss';
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
name: '@terrazzo/plugin-sass',
|
|
10
|
+
enforce: 'post',
|
|
11
|
+
config(config) {
|
|
12
|
+
// plugin-css is required for transforms. throw error
|
|
13
|
+
if (!config.plugins.some((p) => p.name === '@terrazzo/plugin-css')) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`@terrazzo/plugin-sass relies on @terrazzo/plugin-css.
|
|
16
|
+
Please install @terrazzo/plugin-css and follow setup to add to your config.`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async build({ getTransforms, outputFile }) {
|
|
21
|
+
const output = build({ getTransforms, options });
|
|
22
|
+
outputFile(filename, output);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
package/src/lib.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CSSPluginOptions } from '@terrazzo/plugin-css';
|
|
2
|
+
|
|
3
|
+
export interface SassPluginOptions {
|
|
4
|
+
/** Where to output CSS */
|
|
5
|
+
filename?: CSSPluginOptions['filename'];
|
|
6
|
+
/** Glob patterns to exclude tokens from output */
|
|
7
|
+
exclude?: CSSPluginOptions['exclude'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const FILE_HEADER = `////
|
|
11
|
+
/// Autogenerated by ⛋ Terrazzo. DO NOT EDIT!
|
|
12
|
+
////
|
|
13
|
+
|
|
14
|
+
@use "sass:list";
|
|
15
|
+
@use "sass:map";`;
|
|
16
|
+
|
|
17
|
+
export const MIXIN_TOKEN = `@function token($tokenName) {
|
|
18
|
+
@if map.has-key($__token-values, $tokenName) == false {
|
|
19
|
+
@error 'No token named "#{$tokenName}"';
|
|
20
|
+
}
|
|
21
|
+
$_token: map.get($__token-values, $tokenName);
|
|
22
|
+
@if map.has-key($_token, "__tz-error") {
|
|
23
|
+
@error map.get($_token, "__tz-error");
|
|
24
|
+
}
|
|
25
|
+
@return map.get($_token);
|
|
26
|
+
}`;
|
|
27
|
+
|
|
28
|
+
export const MIXIN_TYPOGRAPHY = `@mixin typography($tokenName, $modeName: ".") {
|
|
29
|
+
@if map.has-key($__token-typography-mixins, $tokenName) == false {
|
|
30
|
+
@error 'No typography mixin named "#{$tokenName}"';
|
|
31
|
+
}
|
|
32
|
+
$_mixin: map.get($__token-typography-mixins, $tokenName);
|
|
33
|
+
$_properties: map.get($_mixin, ".");
|
|
34
|
+
@if map.has-key($_mixin) {
|
|
35
|
+
$_properties: map.get($_mixin);
|
|
36
|
+
}
|
|
37
|
+
@each $_property, $_value in $_properties {
|
|
38
|
+
#{$_property}: #{$_value};
|
|
39
|
+
}
|
|
40
|
+
}`;
|