@terrazzo/plugin-sass 0.0.0 → 0.0.1
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 +2 -2
- package/README.md +38 -3
- package/dist/build.js +5 -4
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +15 -14
- package/src/build.ts +0 -51
- package/src/index.ts +0 -25
- package/src/lib.ts +0 -40
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Drew Powers
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
# ⛋ @terrazzo/plugin-
|
|
1
|
+
# ⛋ @terrazzo/plugin-sass
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate Sass code from DTCG tokens.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Requires [Node.js 18 or later](https://nodejs.org). With that installed, run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i -D @terrazzo/cli @terrazzo/plugin-css @terrazzo/plugin-sass
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add a `terrazzo.config.js` to the root of your project with:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "@terrazzo/cli";
|
|
17
|
+
import sass from "@terrazzo/plugin-sass";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
outDir: "./tokens/",
|
|
21
|
+
plugins: [
|
|
22
|
+
css({
|
|
23
|
+
fileName: "tokens.css",
|
|
24
|
+
}),
|
|
25
|
+
sass({
|
|
26
|
+
fileName: "index.sass",
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Lastly, run:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx tz build
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
And you’ll see a `./tokens/index.scss` file generated in your project.
|
|
39
|
+
|
|
40
|
+
[Full Documentation](https://terrazzo.app/docs/integrations/sass)
|
package/dist/build.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
-
import {
|
|
2
|
+
import { makeCSSVar } from '@terrazzo/token-tools/css';
|
|
3
|
+
import { FORMAT_ID } from '@terrazzo/plugin-css';
|
|
3
4
|
import { FILE_HEADER, MIXIN_TOKEN, MIXIN_TYPOGRAPHY } from './lib.js';
|
|
4
5
|
export default function build({ getTransforms, options }) {
|
|
5
|
-
const tokens = getTransforms({ format:
|
|
6
|
+
const tokens = getTransforms({ format: FORMAT_ID, id: '*', mode: '.' });
|
|
6
7
|
const output = [FILE_HEADER, ''];
|
|
7
8
|
// main values
|
|
8
9
|
output.push('$__token-values: (');
|
|
@@ -18,7 +19,7 @@ export default function build({ getTransforms, options }) {
|
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
21
|
const name = token.localID ?? token.token.id;
|
|
21
|
-
output.push(` "${token.token.id}": (${
|
|
22
|
+
output.push(` "${token.token.id}": (${makeCSSVar(name, { wrapVar: true })}),`);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
output.push(');', '');
|
|
@@ -29,7 +30,7 @@ export default function build({ getTransforms, options }) {
|
|
|
29
30
|
output.push(` "${token.token.id}": (`);
|
|
30
31
|
for (const property of Object.keys(token.value)) {
|
|
31
32
|
const name = `${token.localID ?? token.token.id}-${property}`;
|
|
32
|
-
output.push(` "${property}": (${
|
|
33
|
+
output.push(` "${property}": (${makeCSSVar(name, { wrapVar: true })}),`);
|
|
33
34
|
}
|
|
34
35
|
output.push(' ),');
|
|
35
36
|
}
|
package/dist/build.js.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,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,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAExE,MAAM,MAAM,GAAa,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAE3C,cAAc;IACd,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,KAAK,MAAM,KAAK,I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QAAQ,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC,QAAQ,QAAQ,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9E,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
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,cAAc,UAAU,CAAC;AAEzB,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/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrazzo/plugin-sass",
|
|
3
3
|
"description": "Generate scss/sass from your design tokens schema (requires @terrazzo/cli)",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "Drew Powers",
|
|
7
8
|
"email": "drew@pow.rs"
|
|
8
9
|
},
|
|
9
10
|
"keywords": [
|
|
10
11
|
"design tokens",
|
|
11
|
-
"design tokens community group",
|
|
12
|
-
"design system",
|
|
13
12
|
"dtcg",
|
|
14
13
|
"w3c",
|
|
15
14
|
"css",
|
|
16
15
|
"sass"
|
|
17
16
|
],
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"type": "module",
|
|
20
17
|
"main": "./dist/index.js",
|
|
18
|
+
"homepage": "https://terrazzoapp.com/docs/cli/integrations/sass",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/terrazzoapp/terrazzo.git",
|
|
22
|
+
"directory": "packages/plugin-sass"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
21
25
|
"peerDependencies": {
|
|
22
|
-
"@terrazzo/cli": "^0.0.
|
|
23
|
-
"@terrazzo/plugin-css": "^0.0.
|
|
26
|
+
"@terrazzo/cli": "^0.0.10",
|
|
27
|
+
"@terrazzo/plugin-css": "^0.0.5"
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"mime": "^3.0.0",
|
|
28
|
-
"svgo": "^3.2.0",
|
|
29
|
-
"@terrazzo/token-tools": "^0.0.2"
|
|
30
|
+
"@terrazzo/token-tools": "^0.0.4"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@terrazzo/cli": "^0.0.
|
|
33
|
-
"@terrazzo/parser": "^0.0.
|
|
34
|
-
"@terrazzo/plugin-css": "^0.0.
|
|
33
|
+
"@terrazzo/cli": "^0.0.10",
|
|
34
|
+
"@terrazzo/parser": "^0.0.10",
|
|
35
|
+
"@terrazzo/plugin-css": "^0.0.5"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "pnpm run build:clean && pnpm run build:ts && pnpm run build:license",
|
package/src/build.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
}`;
|