@sugarcube-org/postcss 0.0.1-alpha.1 → 0.0.1-alpha.2

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/dist/index.cjs CHANGED
@@ -1,133 +1,3 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var path = require('node:path');
5
- var core = require('@sugarcube-org/core');
6
-
7
- function isSingleCollection(tokens) {
8
- return tokens && "source" in tokens && Array.isArray(tokens.source);
9
- }
10
- function processTokenSources(sources, result, outputFiles = /* @__PURE__ */ new Set()) {
11
- for (const source of sources) {
12
- if (!source.includes("*") && fs.existsSync(source)) {
13
- const resolvedPath = path.resolve(process.cwd(), source);
14
- if (!outputFiles.has(resolvedPath)) {
15
- result.messages.push({
16
- type: "dependency",
17
- plugin: "postcss-sugarcube",
18
- file: resolvedPath
19
- });
20
- }
21
- } else if (source.includes("*")) {
22
- const sourceDir = path.dirname(source);
23
- const pattern = path.basename(source);
24
- if (fs.existsSync(sourceDir)) {
25
- result.messages.push({
26
- type: "dir-dependency",
27
- plugin: "postcss-sugarcube",
28
- dir: path.resolve(process.cwd(), sourceDir),
29
- glob: pattern
30
- });
31
- }
32
- }
33
- }
34
- }
35
- function registerDependencies(config, result) {
36
- result.messages.push({
37
- type: "dependency",
38
- plugin: "postcss-sugarcube",
39
- file: path.resolve(process.cwd(), "sugarcube.config.json")
40
- });
41
- if (!config.tokens) return;
42
- const outputDir = config.output?.directories?.css || "./src/styles";
43
- const outputFiles = /* @__PURE__ */ new Set();
44
- if (config.output?.css?.separate) {
45
- outputFiles.add(
46
- path.resolve(process.cwd(), `${outputDir}/global/variables/colors.variables.css`)
47
- );
48
- } else {
49
- outputFiles.add(path.resolve(process.cwd(), `${outputDir}/tokens.css`));
50
- }
51
- if (isSingleCollection(config.tokens)) {
52
- processTokenSources(config.tokens.source, result, outputFiles);
53
- } else {
54
- for (const [collectionName, collection] of Object.entries(config.tokens)) {
55
- if (collection && "source" in collection && Array.isArray(collection.source)) {
56
- processTokenSources(collection.source, result, outputFiles);
57
- }
58
- }
59
- }
60
- }
61
- function formatErrors(errors) {
62
- const fileErrors = errors.filter((err) => err.file || err.source?.sourcePath);
63
- const otherErrors = errors.filter(
64
- (err) => !err.file && (!err.source || !err.source.sourcePath)
65
- );
66
- const messages = [];
67
- for (const err of fileErrors) {
68
- const file = err.file || err.source?.sourcePath;
69
- if (!file) continue;
70
- const relativeFile = path.relative(process.cwd(), file);
71
- const errMessage = err.message.replace(file, relativeFile);
72
- messages.push(errMessage);
73
- }
74
- for (const err of otherErrors) {
75
- messages.push(err.message);
76
- }
77
- return messages.join("\n - ");
78
- }
79
- let lastMessageTime = 0;
80
- const sugarcubePlugin = (opts = {}) => {
81
- return {
82
- postcssPlugin: "postcss-sugarcube",
83
- async Once(root, { result }) {
84
- const currentFile = result.opts.from;
85
- if (!currentFile) {
86
- result.warn("No input file provided to postcss-sugarcube");
87
- return;
88
- }
89
- try {
90
- const firstNode = root.nodes[0];
91
- if (firstNode && firstNode.type === "comment" && firstNode.text.includes("AUTOMATICALLY GENERATED FILE")) {
92
- return;
93
- }
94
- const config = await core.loadConfig();
95
- registerDependencies(config, result);
96
- const pipelineResult = await core.tokensToCSSPipeline(config);
97
- const allErrors = [
98
- ...pipelineResult.errors.load,
99
- ...pipelineResult.errors.flatten,
100
- ...pipelineResult.errors.validation,
101
- ...pipelineResult.errors.resolution
102
- ];
103
- if (allErrors.length > 0) {
104
- result.warn(`Token validation failed:
105
- - ${formatErrors(allErrors)}`, {
106
- plugin: "postcss-sugarcube",
107
- word: "error"
108
- });
109
- return;
110
- }
111
- const tokenPaths = core.getTokenPathsFromConfig(config);
112
- await core.writeCSSFilesToDisk(pipelineResult.output, true, tokenPaths);
113
- const now = Date.now();
114
- if (!opts.silent && now - lastMessageTime > 1e3) {
115
- result.messages.push({
116
- type: "log",
117
- plugin: "postcss-sugarcube",
118
- text: "\u2728 Generated CSS files from tokens"
119
- });
120
- lastMessageTime = now;
121
- }
122
- } catch (error) {
123
- result.warn(error instanceof Error ? error.message : String(error), {
124
- plugin: "postcss-sugarcube",
125
- word: "error"
126
- });
127
- }
128
- }
129
- };
130
- };
131
- sugarcubePlugin.postcss = true;
132
-
133
- module.exports = sugarcubePlugin;
1
+ "use strict";var h=Object.defineProperty;var u=(s,n)=>h(s,"name",{value:n,configurable:!0});var f=require("node:fs"),c=require("node:path"),l=require("@sugarcube-org/core");function y(s){return s&&"source"in s&&Array.isArray(s.source)}u(y,"isSingleCollection");function d(s,n,t=new Set){for(const r of s)if(!r.includes("*")&&f.existsSync(r)){const e=c.resolve(process.cwd(),r);t.has(e)||n.messages.push({type:"dependency",plugin:"postcss-sugarcube",file:e})}else if(r.includes("*")){const e=c.dirname(r),o=c.basename(r);f.existsSync(e)&&n.messages.push({type:"dir-dependency",plugin:"postcss-sugarcube",dir:c.resolve(process.cwd(),e),glob:o})}}u(d,"processTokenSources");function b(s,n){if(n.messages.push({type:"dependency",plugin:"postcss-sugarcube",file:c.resolve(process.cwd(),"sugarcube.config.json")}),!s.tokens)return;const t=s.output?.directories?.css||"./src/styles",r=new Set;if(s.output?.css?.separate?r.add(c.resolve(process.cwd(),`${t}/global/variables/colors.variables.css`)):r.add(c.resolve(process.cwd(),`${t}/tokens.css`)),y(s.tokens))d(s.tokens.source,n,r);else for(const[e,o]of Object.entries(s.tokens))o&&"source"in o&&Array.isArray(o.source)&&d(o.source,n,r)}u(b,"registerDependencies");function v(s){const n=s.filter(e=>e.file||e.source?.sourcePath),t=s.filter(e=>!e.file&&(!e.source||!e.source.sourcePath)),r=[];for(const e of n){const o=e.file||e.source?.sourcePath;if(!o)continue;const i=c.relative(process.cwd(),o),a=e.message.replace(o,i);r.push(a)}for(const e of t)r.push(e.message);return r.join(`
2
+ - `)}u(v,"formatErrors");let g=0;const w=u((s={})=>({postcssPlugin:"postcss-sugarcube",async Once(n,{result:t}){if(!t.opts.from){t.warn("No input file provided to postcss-sugarcube");return}try{const e=n.nodes[0];if(e&&e.type==="comment"&&e.text.includes("AUTOMATICALLY GENERATED FILE"))return;const o=await l.loadConfig();b(o,t);const i=await l.tokensToCSSPipeline(o),a=[...i.errors.load,...i.errors.flatten,...i.errors.validation,...i.errors.resolution];if(a.length>0){t.warn(`Token validation failed:
3
+ - ${v(a)}`,{plugin:"postcss-sugarcube",word:"error"});return}const m=l.getTokenPathsFromConfig(o);await l.writeCSSFilesToDisk(i.output,!0,m);const p=Date.now();!s.silent&&p-g>1e3&&(t.messages.push({type:"log",plugin:"postcss-sugarcube",text:"\u2728 Generated CSS files from tokens"}),g=p)}catch(e){t.warn(e instanceof Error?e.message:String(e),{plugin:"postcss-sugarcube",word:"error"})}}}),"sugarcubePlugin");w.postcss=!0,module.exports=w;
package/dist/index.mjs CHANGED
@@ -1,131 +1,3 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { loadConfig, tokensToCSSPipeline, getTokenPathsFromConfig, writeCSSFilesToDisk } from '@sugarcube-org/core';
4
-
5
- function isSingleCollection(tokens) {
6
- return tokens && "source" in tokens && Array.isArray(tokens.source);
7
- }
8
- function processTokenSources(sources, result, outputFiles = /* @__PURE__ */ new Set()) {
9
- for (const source of sources) {
10
- if (!source.includes("*") && fs.existsSync(source)) {
11
- const resolvedPath = path.resolve(process.cwd(), source);
12
- if (!outputFiles.has(resolvedPath)) {
13
- result.messages.push({
14
- type: "dependency",
15
- plugin: "postcss-sugarcube",
16
- file: resolvedPath
17
- });
18
- }
19
- } else if (source.includes("*")) {
20
- const sourceDir = path.dirname(source);
21
- const pattern = path.basename(source);
22
- if (fs.existsSync(sourceDir)) {
23
- result.messages.push({
24
- type: "dir-dependency",
25
- plugin: "postcss-sugarcube",
26
- dir: path.resolve(process.cwd(), sourceDir),
27
- glob: pattern
28
- });
29
- }
30
- }
31
- }
32
- }
33
- function registerDependencies(config, result) {
34
- result.messages.push({
35
- type: "dependency",
36
- plugin: "postcss-sugarcube",
37
- file: path.resolve(process.cwd(), "sugarcube.config.json")
38
- });
39
- if (!config.tokens) return;
40
- const outputDir = config.output?.directories?.css || "./src/styles";
41
- const outputFiles = /* @__PURE__ */ new Set();
42
- if (config.output?.css?.separate) {
43
- outputFiles.add(
44
- path.resolve(process.cwd(), `${outputDir}/global/variables/colors.variables.css`)
45
- );
46
- } else {
47
- outputFiles.add(path.resolve(process.cwd(), `${outputDir}/tokens.css`));
48
- }
49
- if (isSingleCollection(config.tokens)) {
50
- processTokenSources(config.tokens.source, result, outputFiles);
51
- } else {
52
- for (const [collectionName, collection] of Object.entries(config.tokens)) {
53
- if (collection && "source" in collection && Array.isArray(collection.source)) {
54
- processTokenSources(collection.source, result, outputFiles);
55
- }
56
- }
57
- }
58
- }
59
- function formatErrors(errors) {
60
- const fileErrors = errors.filter((err) => err.file || err.source?.sourcePath);
61
- const otherErrors = errors.filter(
62
- (err) => !err.file && (!err.source || !err.source.sourcePath)
63
- );
64
- const messages = [];
65
- for (const err of fileErrors) {
66
- const file = err.file || err.source?.sourcePath;
67
- if (!file) continue;
68
- const relativeFile = path.relative(process.cwd(), file);
69
- const errMessage = err.message.replace(file, relativeFile);
70
- messages.push(errMessage);
71
- }
72
- for (const err of otherErrors) {
73
- messages.push(err.message);
74
- }
75
- return messages.join("\n - ");
76
- }
77
- let lastMessageTime = 0;
78
- const sugarcubePlugin = (opts = {}) => {
79
- return {
80
- postcssPlugin: "postcss-sugarcube",
81
- async Once(root, { result }) {
82
- const currentFile = result.opts.from;
83
- if (!currentFile) {
84
- result.warn("No input file provided to postcss-sugarcube");
85
- return;
86
- }
87
- try {
88
- const firstNode = root.nodes[0];
89
- if (firstNode && firstNode.type === "comment" && firstNode.text.includes("AUTOMATICALLY GENERATED FILE")) {
90
- return;
91
- }
92
- const config = await loadConfig();
93
- registerDependencies(config, result);
94
- const pipelineResult = await tokensToCSSPipeline(config);
95
- const allErrors = [
96
- ...pipelineResult.errors.load,
97
- ...pipelineResult.errors.flatten,
98
- ...pipelineResult.errors.validation,
99
- ...pipelineResult.errors.resolution
100
- ];
101
- if (allErrors.length > 0) {
102
- result.warn(`Token validation failed:
103
- - ${formatErrors(allErrors)}`, {
104
- plugin: "postcss-sugarcube",
105
- word: "error"
106
- });
107
- return;
108
- }
109
- const tokenPaths = getTokenPathsFromConfig(config);
110
- await writeCSSFilesToDisk(pipelineResult.output, true, tokenPaths);
111
- const now = Date.now();
112
- if (!opts.silent && now - lastMessageTime > 1e3) {
113
- result.messages.push({
114
- type: "log",
115
- plugin: "postcss-sugarcube",
116
- text: "\u2728 Generated CSS files from tokens"
117
- });
118
- lastMessageTime = now;
119
- }
120
- } catch (error) {
121
- result.warn(error instanceof Error ? error.message : String(error), {
122
- plugin: "postcss-sugarcube",
123
- word: "error"
124
- });
125
- }
126
- }
127
- };
128
- };
129
- sugarcubePlugin.postcss = true;
130
-
131
- module.exports = sugarcubePlugin;
1
+ var h=Object.defineProperty;var u=(s,o)=>h(s,"name",{value:o,configurable:!0});var y=(s,o)=>()=>(o||s((o={exports:{}}).exports,o),o.exports);import p from"node:fs";import c from"node:path";import{loadConfig as b,tokensToCSSPipeline as v,getTokenPathsFromConfig as S,writeCSSFilesToDisk as k}from"@sugarcube-org/core";var A=y((N,m)=>{function E(s){return s&&"source"in s&&Array.isArray(s.source)}u(E,"isSingleCollection");function f(s,o,n=new Set){for(const r of s)if(!r.includes("*")&&p.existsSync(r)){const e=c.resolve(process.cwd(),r);n.has(e)||o.messages.push({type:"dependency",plugin:"postcss-sugarcube",file:e})}else if(r.includes("*")){const e=c.dirname(r),t=c.basename(r);p.existsSync(e)&&o.messages.push({type:"dir-dependency",plugin:"postcss-sugarcube",dir:c.resolve(process.cwd(),e),glob:t})}}u(f,"processTokenSources");function P(s,o){if(o.messages.push({type:"dependency",plugin:"postcss-sugarcube",file:c.resolve(process.cwd(),"sugarcube.config.json")}),!s.tokens)return;const n=s.output?.directories?.css||"./src/styles",r=new Set;if(s.output?.css?.separate?r.add(c.resolve(process.cwd(),`${n}/global/variables/colors.variables.css`)):r.add(c.resolve(process.cwd(),`${n}/tokens.css`)),E(s.tokens))f(s.tokens.source,o,r);else for(const[e,t]of Object.entries(s.tokens))t&&"source"in t&&Array.isArray(t.source)&&f(t.source,o,r)}u(P,"registerDependencies");function T(s){const o=s.filter(e=>e.file||e.source?.sourcePath),n=s.filter(e=>!e.file&&(!e.source||!e.source.sourcePath)),r=[];for(const e of o){const t=e.file||e.source?.sourcePath;if(!t)continue;const i=c.relative(process.cwd(),t),a=e.message.replace(t,i);r.push(a)}for(const e of n)r.push(e.message);return r.join(`
2
+ - `)}u(T,"formatErrors");let d=0;const g=u((s={})=>({postcssPlugin:"postcss-sugarcube",async Once(o,{result:n}){if(!n.opts.from){n.warn("No input file provided to postcss-sugarcube");return}try{const e=o.nodes[0];if(e&&e.type==="comment"&&e.text.includes("AUTOMATICALLY GENERATED FILE"))return;const t=await b();P(t,n);const i=await v(t),a=[...i.errors.load,...i.errors.flatten,...i.errors.validation,...i.errors.resolution];if(a.length>0){n.warn(`Token validation failed:
3
+ - ${T(a)}`,{plugin:"postcss-sugarcube",word:"error"});return}const w=S(t);await k(i.output,!0,w);const l=Date.now();!s.silent&&l-d>1e3&&(n.messages.push({type:"log",plugin:"postcss-sugarcube",text:"\u2728 Generated CSS files from tokens"}),d=l)}catch(e){n.warn(e instanceof Error?e.message:String(e),{plugin:"postcss-sugarcube",word:"error"})}}}),"sugarcubePlugin");g.postcss=!0,m.exports=g});export default A();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarcube-org/postcss",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.2",
4
4
  "exports": {
5
5
  "require": {
6
6
  "types": "./dist/index.d.cts",
@@ -15,7 +15,7 @@
15
15
  "dist/"
16
16
  ],
17
17
  "dependencies": {
18
- "@sugarcube-org/core": "0.0.1-alpha.4"
18
+ "@sugarcube-org/core": "0.0.1-alpha.5"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "postcss": "^8.4.0"
@@ -26,7 +26,7 @@
26
26
  "tsx": "^4.19.2"
27
27
  },
28
28
  "scripts": {
29
- "build": "pkgroll",
29
+ "build": "pkgroll --minify --clean-dist",
30
30
  "dev": "pkgroll --watch",
31
31
  "type-check": "tsc --noEmit"
32
32
  }