aliascss 1.4.4 → 1.4.5
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/aliascss.config.js +32 -32
- package/lib/node/compileFile-bk.d.ts +27 -0
- package/lib/node/compileFile-bk.js +379 -0
- package/lib/node/compileFile.d.ts +11 -11
- package/lib/node/compileFile.js +170 -235
- package/package.json +1 -1
package/aliascss.config.js
CHANGED
|
@@ -8,43 +8,43 @@ const config={
|
|
|
8
8
|
location:'demo/acss.css',
|
|
9
9
|
"--file":true
|
|
10
10
|
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
// '--module':true,
|
|
12
|
+
// prefix:'',
|
|
13
|
+
// importModuleAs:'x',
|
|
14
|
+
// // minify:true,
|
|
15
|
+
// extractorFunction:"String",
|
|
16
|
+
// //reg:new RegExp('x' + "(`|\\(["+`"'])`+ "(.+)" + "(`|" + `["']` + "\\))") ,
|
|
17
|
+
// media:{
|
|
18
|
+
// prefix:{
|
|
19
|
+
// xs:'@media (max-width : 24px)'
|
|
20
|
+
// }
|
|
21
|
+
// },
|
|
22
|
+
// prebuild:{
|
|
23
|
+
// 'colorize-dark':'background:#0f0f0f;color:#e3e3e3',
|
|
24
|
+
// //'x-clip-menu':'clip-path: polygon(0% 10%,100% 10%,100% 20%,0% 20%,0% 45%,100% 45%,100% 55%,0% 55%,0% 80%,100% 80%,100% 90%,0% 90%);',
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
// },
|
|
27
|
+
// group:{
|
|
28
|
+
// //...prebuild,
|
|
29
|
+
// //'x-card':"w-256px h-120px [class~=shadow]-bxs-0px-12px-24px-rgba-43-43-67-0d16 bgc-fff b-1px-s-gray-lightest br-16px --hover-bgc-primary-lightest --hover-b-1px-s-primary-hover --active[b-1px-s-primary,bgc-primary-light]",
|
|
30
|
+
// 'x-responsive':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
|
|
31
|
+
// 'x-responsive-sm':'xs-w-100p sm-w-540px md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
|
|
32
|
+
// 'x-responsive-md':'xs-w-100p sm-w-100p md-w-720px lg-w-960px xl-w-1140px 2xl-w-1320px',
|
|
33
|
+
// 'x-responsive-lg':'xs-w-100p sm-w-100p md-w-100p lg-w-960px xl-w-1140px 2xl-w-1320px',
|
|
34
|
+
// 'x-responsive-xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-1140px 2xl-w-1320px',
|
|
35
|
+
// 'x-responsive-2xl':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-w-100p 2xl-w-1320px',
|
|
36
|
+
// 'x-responsive-fluid':'xs-w-100p sm-w-100p md-w-100p lg-w-100p xl-100p 2xl-100p',
|
|
37
|
+
// 'btn':`\
|
|
38
|
+
// [bgc-red,c-yellow]
|
|
39
|
+
// --hover[c-blue,bgc-yellow]
|
|
40
|
+
// `,
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
// },
|
|
43
|
+
// statement:`.color{color:red}`,
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
// ignore:['bgc-red']
|
|
48
48
|
}
|
|
49
49
|
export default config;
|
|
50
50
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default function main(config: {
|
|
2
|
+
['input']: string | string[];
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare function globalCSSCompiler(): void;
|
|
6
|
+
export declare function compileFile(file: string, config: any, statementMaker: {
|
|
7
|
+
['make']: (a: string) => string;
|
|
8
|
+
group: (a: string, b: string) => string;
|
|
9
|
+
['rawCSS']?: string;
|
|
10
|
+
['customGroupStatement']?: string;
|
|
11
|
+
}, globalClassList: string[]): string[];
|
|
12
|
+
export declare function groupStatement(name: string, classNames: string, statementMaker: {
|
|
13
|
+
['group']: (a: string, b: string) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function keyframesStatement(name: string, timeLine: string, statementMaker: {
|
|
16
|
+
['make']: (a: string, b?: string | null, c?: boolean) => string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function createCSSFileByFile(file: string, bool?: boolean): void;
|
|
19
|
+
export declare function postify(file: string, plugin: any[], minify?: boolean, sort?: "mobile-first" | "desktop-first"): void;
|
|
20
|
+
export declare function writeStatementToFile(file: string, content: string, from?: string): void;
|
|
21
|
+
export declare function initialize(configFile: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function watch(config: {
|
|
25
|
+
['input']: string | string[];
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}): void;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
2
|
+
import { compiler as statementMaker } from "../returnStatement.js";
|
|
3
|
+
import config from '../config.js';
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import fg from "fast-glob";
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import postcss from 'postcss';
|
|
8
|
+
import postcssDiscardDuplicates from 'postcss-discard-duplicates';
|
|
9
|
+
import cssnano from 'cssnano';
|
|
10
|
+
import chokidar from 'chokidar';
|
|
11
|
+
import sortMediaQueries from 'postcss-sort-media-queries';
|
|
12
|
+
import { splitByCommaOutsideParens } from '../utils/helper.js';
|
|
13
|
+
const init = {
|
|
14
|
+
classList: [], // hold className for MasterCSS to avoid repeating
|
|
15
|
+
groups: [],
|
|
16
|
+
input: '', // input glob pattern
|
|
17
|
+
output: '', // location off output
|
|
18
|
+
'--file': false, // if set true compileFileByFile to [filename].css
|
|
19
|
+
statementMaker,
|
|
20
|
+
config,
|
|
21
|
+
'--module': false,
|
|
22
|
+
rawCSS: '',
|
|
23
|
+
layers: [],
|
|
24
|
+
initializedLayer: false,
|
|
25
|
+
customGroupStatement: '',
|
|
26
|
+
minify: false,
|
|
27
|
+
globPattern: '', // Use this to check valid new created file to add to watch during watch.on
|
|
28
|
+
};
|
|
29
|
+
export default function main(config) {
|
|
30
|
+
// initialize
|
|
31
|
+
initialize(config);
|
|
32
|
+
if (init.config.prefix)
|
|
33
|
+
init.statementMaker.prefix = init.config.prefix;
|
|
34
|
+
if (init.input && (init.output || init['--file'])) {
|
|
35
|
+
const input = fg.sync(init.input, { dot: true });
|
|
36
|
+
// console.log(input);
|
|
37
|
+
input.forEach((file) => {
|
|
38
|
+
createCSSFileByFile(file);
|
|
39
|
+
});
|
|
40
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function globalCSSCompiler() {
|
|
47
|
+
const classList = [];
|
|
48
|
+
if (init.globPattern && init.output) {
|
|
49
|
+
fs.truncateSync(init.output);
|
|
50
|
+
// 1. Write @layer once at the top of the freshly truncated file
|
|
51
|
+
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
52
|
+
fs.writeFileSync(init.output, `@layer ${init.layers.join(', ')};\n\n`, { flag: 'a+' });
|
|
53
|
+
init.initializedLayer = true;
|
|
54
|
+
}
|
|
55
|
+
const input = fg.sync(init.globPattern, { dot: true });
|
|
56
|
+
// console.log(input);
|
|
57
|
+
input.forEach((file) => {
|
|
58
|
+
const [gbContent,] = compileFile(file, config, statementMaker, classList);
|
|
59
|
+
try {
|
|
60
|
+
fs.writeFileSync(init.output, `/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${gbContent}
|
|
61
|
+
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
62
|
+
`, { flag: 'a+' });
|
|
63
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
67
|
+
console.log(error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function compileFile(file, config, statementMaker, globalClassList) {
|
|
77
|
+
let [globalStatement, compiledStatement, moduleStatement] = ['', '', ''];
|
|
78
|
+
// inject config.group and config.statement
|
|
79
|
+
if (statementMaker.rawCSS) {
|
|
80
|
+
compiledStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* -----End:aliacss.config.statement----- */\n\n`;
|
|
81
|
+
moduleStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* ------End:aliacss.config.statement----- */\n\n`;
|
|
82
|
+
}
|
|
83
|
+
if (statementMaker.customGroupStatement) {
|
|
84
|
+
compiledStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
85
|
+
moduleStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
86
|
+
}
|
|
87
|
+
const [classList, groups, keyframe, rawCSSStatement] = extractClassNamesFromFile(file, config);
|
|
88
|
+
// 1. raw-css
|
|
89
|
+
if (rawCSSStatement) {
|
|
90
|
+
globalStatement += rawCSSStatement + '\n';
|
|
91
|
+
compiledStatement += rawCSSStatement + '\n';
|
|
92
|
+
}
|
|
93
|
+
// 2. group
|
|
94
|
+
for (const key in groups) {
|
|
95
|
+
if (groups.hasOwnProperty(key)) {
|
|
96
|
+
// --------------ModuleStatement
|
|
97
|
+
if (/^module=/.test(key)) {
|
|
98
|
+
const mdStatement = statementMaker.group(groups[key], key.replace(/module=/, ''));
|
|
99
|
+
moduleStatement += mdStatement + '\n';
|
|
100
|
+
}
|
|
101
|
+
// -------------EndOfModule
|
|
102
|
+
else {
|
|
103
|
+
const gpStatement = statementMaker.group(groups[key], key);
|
|
104
|
+
globalStatement += gpStatement + '\n';
|
|
105
|
+
compiledStatement += gpStatement + '\n';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 2. ClassList
|
|
110
|
+
classList.forEach((e) => {
|
|
111
|
+
const statement = statementMaker.make(e);
|
|
112
|
+
if (statement) {
|
|
113
|
+
console.log('\x1b[32m', statement);
|
|
114
|
+
if (globalClassList.indexOf(e) === -1) {
|
|
115
|
+
globalStatement += statement + '\n';
|
|
116
|
+
globalClassList.push(e);
|
|
117
|
+
// console.log(e);
|
|
118
|
+
}
|
|
119
|
+
compiledStatement += statement + '\n';
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
// 3. Keyframe
|
|
123
|
+
for (const key in keyframe) {
|
|
124
|
+
if (keyframe.hasOwnProperty(key)) {
|
|
125
|
+
const kfStatement = keyframesStatement(key, keyframe[key], statementMaker);
|
|
126
|
+
globalStatement += kfStatement + '\n';
|
|
127
|
+
compiledStatement += kfStatement + '\n';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [globalStatement, compiledStatement, moduleStatement];
|
|
131
|
+
}
|
|
132
|
+
export function groupStatement(name, classNames, statementMaker) {
|
|
133
|
+
return statementMaker.group(classNames, name) + '\n';
|
|
134
|
+
}
|
|
135
|
+
export function keyframesStatement(name, timeLine, statementMaker) {
|
|
136
|
+
let kfStatement = '@keyframes ' + name + "{\n";
|
|
137
|
+
const returnPnV = (e) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
138
|
+
const split = timeLine.split(/\s+/);
|
|
139
|
+
split.forEach((each) => {
|
|
140
|
+
try {
|
|
141
|
+
const [at, pNv] = each.replace(/\]\[/, ']-[').replace("-", "=").split("=");
|
|
142
|
+
// kfStatement+=` ${at.replace('@','').replace(/:/g,',').replace(/,/g,"%,").replace(/[\[|\]]/g,'')}% {${returnPnV(pNv.replace(/^\[|\]$/g,'').split(','))}}`
|
|
143
|
+
kfStatement += ` ${at.replace('@', '').replace(/:/g, ',').replace(/,/g, "%,").replace(/[\[|\]]/g, '')}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, '')))}}`;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Not a valid entry for AliasCSS keyframes processor : ' + each, error);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return kfStatement + "\n}\n";
|
|
150
|
+
}
|
|
151
|
+
export function createCSSFileByFile(file, bool = false) {
|
|
152
|
+
const [gbContent, content, module] = compileFile(file, config, statementMaker, init.classList);
|
|
153
|
+
// console.log(init.classList);
|
|
154
|
+
// If its fileByFile
|
|
155
|
+
if (init["--module"] && module.trim()) {
|
|
156
|
+
try {
|
|
157
|
+
fs.writeFileSync(file + '.module.css', module);
|
|
158
|
+
// console.log(content);
|
|
159
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'module Locally ');
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
163
|
+
console.log(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (init["--file"]) {
|
|
167
|
+
try {
|
|
168
|
+
fs.writeFileSync(file + '.css', content);
|
|
169
|
+
postify(file + '.css', [postcssDiscardDuplicates], init.minify);
|
|
170
|
+
// console.log(content);
|
|
171
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'Locally');
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
175
|
+
console.log(error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Check for Global
|
|
179
|
+
if (!bool && init.output) {
|
|
180
|
+
try {
|
|
181
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${postcss([postcssDiscardDuplicates]).process(gbContent)}
|
|
182
|
+
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
183
|
+
`, { flag: 'a+' });
|
|
184
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
188
|
+
console.log(error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export function postify(file, plugin, minify = false, sort = "mobile-first") {
|
|
193
|
+
const data = fs.readFileSync(file, 'utf-8');
|
|
194
|
+
plugin.push(sortMediaQueries({
|
|
195
|
+
sort
|
|
196
|
+
}));
|
|
197
|
+
if (fs.existsSync(file)) {
|
|
198
|
+
if (minify === true)
|
|
199
|
+
plugin.push(cssnano);
|
|
200
|
+
postcss(plugin).process(data, { from: undefined }).then(result => {
|
|
201
|
+
fs.truncateSync(file);
|
|
202
|
+
fs.writeFileSync(file, result.css);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// fs.readFile(file, (err, css) => {
|
|
206
|
+
// postcss(plugin)
|
|
207
|
+
// .process(css, { from: file, to: file+"post.css" })
|
|
208
|
+
// .then(result => {
|
|
209
|
+
// fs.writeFile(file+"post.css", result.css, () => true)
|
|
210
|
+
// // if ( result.map ) {
|
|
211
|
+
// // fs.writeFile(file+'.map', result.map.toString(), () => true)
|
|
212
|
+
// // }
|
|
213
|
+
// })
|
|
214
|
+
// })
|
|
215
|
+
}
|
|
216
|
+
export function writeStatementToFile(file, content, from) {
|
|
217
|
+
// Check for Global
|
|
218
|
+
if (init.output) {
|
|
219
|
+
try {
|
|
220
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS:From aliasCSSConfig.${from}------------------------*/\n${content}
|
|
221
|
+
\n/* End :-----------ACSS aliasCSSConfig.${from}----------------------------*/\n
|
|
222
|
+
`, { flag: 'a+' });
|
|
223
|
+
console.log('AliasCSS compiled', '[aliasCSSConfig.statement]', 'aliascss.config.js');
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.log('\x1b[31m', "Couldn't able to append/create [key:statement] from alias.config.js ");
|
|
227
|
+
console.log(error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Initialize
|
|
232
|
+
export function initialize(configFile) {
|
|
233
|
+
// ----------------input-------------------
|
|
234
|
+
if (configFile.hasOwnProperty('input')) {
|
|
235
|
+
init.input = configFile.input;
|
|
236
|
+
init.globPattern = configFile.input;
|
|
237
|
+
}
|
|
238
|
+
// ----------------input-------------------
|
|
239
|
+
if (configFile.hasOwnProperty('layers') && Array.isArray(configFile.layers)) {
|
|
240
|
+
init.layers = configFile.layers;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
init.layers = config.layers;
|
|
244
|
+
}
|
|
245
|
+
// ----------------Prefix-------------------
|
|
246
|
+
if (configFile.hasOwnProperty('prefix')) {
|
|
247
|
+
init.config.prefix = configFile.prefix;
|
|
248
|
+
}
|
|
249
|
+
// ----------------output-------------------
|
|
250
|
+
if (configFile.hasOwnProperty('output')) {
|
|
251
|
+
const op = configFile.output;
|
|
252
|
+
if (op.hasOwnProperty('location')) {
|
|
253
|
+
init.output = op.location;
|
|
254
|
+
}
|
|
255
|
+
if (op.hasOwnProperty('--file') && op['--file'] === true) {
|
|
256
|
+
init["--file"] = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Adding Custom color, length etc
|
|
260
|
+
if (configFile.hasOwnProperty('custom') && typeof configFile.custom === 'object') {
|
|
261
|
+
Object.keys(configFile.custom).forEach((key) => {
|
|
262
|
+
init.statementMaker.addCustom(key, configFile.custom[key]);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
// Extend custom class name define {'border-color-native":'border-color: skyBlue',}
|
|
266
|
+
if (configFile.hasOwnProperty('prebuild')) {
|
|
267
|
+
init.statementMaker.prebuild(configFile.prebuild);
|
|
268
|
+
}
|
|
269
|
+
// Ignore these class name
|
|
270
|
+
if (configFile.hasOwnProperty('ignore')) {
|
|
271
|
+
if (Array.isArray(configFile.ignore)) {
|
|
272
|
+
configFile.ignore.forEach((each) => init.config.ignore.push(each.trim()));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// --module
|
|
276
|
+
if (configFile.hasOwnProperty('--module') && configFile.hasOwnProperty('importModuleAs')) {
|
|
277
|
+
init["--module"] = true;
|
|
278
|
+
init.config.useCSSModule = init["--module"] ? true : false;
|
|
279
|
+
if (init.config.useCSSModule)
|
|
280
|
+
init.config.matchCSSModuleFunction = init.config.createCSSModuleRegex(configFile.importModuleAs);
|
|
281
|
+
}
|
|
282
|
+
// ---------output Minify
|
|
283
|
+
if (configFile.hasOwnProperty('minify')) {
|
|
284
|
+
init.minify = configFile.minify;
|
|
285
|
+
}
|
|
286
|
+
// ------------Extractor function-------
|
|
287
|
+
if (configFile.hasOwnProperty('extractorFunction')) {
|
|
288
|
+
init.config.useExtractorFunction = configFile.extractorFunction.trim() ? true : false;
|
|
289
|
+
if (init.config.useExtractorFunction)
|
|
290
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex(configFile.extractorFunction);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
init.config.useExtractorFunction = true;
|
|
294
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex('String');
|
|
295
|
+
}
|
|
296
|
+
// ---------Extend----------------
|
|
297
|
+
if (configFile.hasOwnProperty('extend') && typeof configFile.extend === 'object') {
|
|
298
|
+
const filteredObj = {};
|
|
299
|
+
Object.keys(configFile.extend).map((key) => {
|
|
300
|
+
// if (configFile.extend[key].hasOwnProperty('compiler') && (typeof configFile.extend[key].compiler === 'function')){
|
|
301
|
+
filteredObj[key] = configFile.extend[key];
|
|
302
|
+
// }
|
|
303
|
+
});
|
|
304
|
+
init.statementMaker.extend(filteredObj);
|
|
305
|
+
}
|
|
306
|
+
// -----------------useColon----------------------------
|
|
307
|
+
if (configFile.hasOwnProperty('useColon')) {
|
|
308
|
+
init.config.useColon = configFile.useColon;
|
|
309
|
+
}
|
|
310
|
+
// ---------------addMedia----------------
|
|
311
|
+
if (configFile.hasOwnProperty('media') && typeof configFile.media === 'object') {
|
|
312
|
+
init.statementMaker.addMedia(configFile.media);
|
|
313
|
+
}
|
|
314
|
+
// /Truncate File every time we bundle
|
|
315
|
+
if (configFile.hasOwnProperty('truncate') && configFile.truncate === false) {
|
|
316
|
+
// do nothing
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (fs.existsSync(init.output))
|
|
320
|
+
fs.truncateSync(path.resolve(init.output));
|
|
321
|
+
writeStatementToFile(init.output, `@layer ${init.layers.join(', ')};`, 'Initializating @layer,');
|
|
322
|
+
}
|
|
323
|
+
// Custom CSS statement
|
|
324
|
+
if (configFile.hasOwnProperty('statement')) {
|
|
325
|
+
init.rawCSS = configFile.statement;
|
|
326
|
+
init.statementMaker.rawCSS = configFile.statement;
|
|
327
|
+
writeStatementToFile(init.output, configFile.statement, 'config.statement');
|
|
328
|
+
}
|
|
329
|
+
// Custom Groups bundling acss classnames in single class name
|
|
330
|
+
if (configFile.hasOwnProperty('group')) {
|
|
331
|
+
init.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
332
|
+
init.statementMaker.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
333
|
+
if (init.customGroupStatement)
|
|
334
|
+
writeStatementToFile(init.output, init.customGroupStatement, 'config.group');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// ----------------WATCH-------------------------------
|
|
338
|
+
export function watch(config) {
|
|
339
|
+
main(config);
|
|
340
|
+
const watcher = chokidar.watch(init.input, {
|
|
341
|
+
ignored: '*.css', // ignore dot-files
|
|
342
|
+
persistent: true
|
|
343
|
+
});
|
|
344
|
+
const compileFile = (file) => {
|
|
345
|
+
console.log(`--processing file : ${file}`);
|
|
346
|
+
createCSSFileByFile(file, true);
|
|
347
|
+
globalCSSCompiler();
|
|
348
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
349
|
+
console.log('Done! ');
|
|
350
|
+
};
|
|
351
|
+
// Something to use when events are received.
|
|
352
|
+
const log = console.log.bind(console);
|
|
353
|
+
// Add event listeners.
|
|
354
|
+
watcher
|
|
355
|
+
.on('add', path => log(`File ${path} has been added to watch`))
|
|
356
|
+
.on('change', path => compileFile(path));
|
|
357
|
+
// .on('unlink', path => log(`File ${path} has been removed`));
|
|
358
|
+
// More possible events.
|
|
359
|
+
watcher
|
|
360
|
+
.on('addDir', path => log(`Directory ${path} has been added`))
|
|
361
|
+
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
|
362
|
+
// .on('error', error => log(`Watcher error: ${error}`))
|
|
363
|
+
// .on('ready', () => log('Initial scan complete. Ready for changes'))
|
|
364
|
+
.on('raw', (event, path, details) => {
|
|
365
|
+
// log('Raw event info:', event, path, details);
|
|
366
|
+
if (event === 'created' && details.type === 'file') {
|
|
367
|
+
if (init.globPattern) {
|
|
368
|
+
const files = fg.sync(init.globPattern, { absolute: true });
|
|
369
|
+
if (files.indexOf(path) !== -1) {
|
|
370
|
+
watcher.add(path);
|
|
371
|
+
// console.log(path,123123);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
watcher.add(path);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
export default function main(config: {
|
|
2
|
-
['input']: string | string[];
|
|
3
2
|
[key: string]: any;
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
input: string | string[];
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function globalCSSCompiler(): Promise<void>;
|
|
6
6
|
export declare function compileFile(file: string, config: any, statementMaker: {
|
|
7
|
-
|
|
7
|
+
make: (a: string, b?: any, c?: any) => string;
|
|
8
8
|
group: (a: string, b: string) => string;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
rawCSS?: string;
|
|
10
|
+
customGroupStatement?: string;
|
|
11
11
|
}, globalClassList: string[]): string[];
|
|
12
12
|
export declare function groupStatement(name: string, classNames: string, statementMaker: {
|
|
13
|
-
|
|
13
|
+
group: (a: string, b: string) => string;
|
|
14
14
|
}): string;
|
|
15
15
|
export declare function keyframesStatement(name: string, timeLine: string, statementMaker: {
|
|
16
|
-
|
|
16
|
+
make: (a: string, b?: string | null, c?: boolean) => string;
|
|
17
17
|
}): string;
|
|
18
|
-
export declare function createCSSFileByFile(file: string, bool?: boolean): void
|
|
19
|
-
export declare function postify(file: string, plugin: any[], minify?: boolean, sort?: "mobile-first" | "desktop-first"): void
|
|
18
|
+
export declare function createCSSFileByFile(file: string, bool?: boolean): Promise<void>;
|
|
19
|
+
export declare function postify(file: string, plugin: any[], minify?: boolean, sort?: "mobile-first" | "desktop-first"): Promise<void>;
|
|
20
20
|
export declare function writeStatementToFile(file: string, content: string, from?: string): void;
|
|
21
21
|
export declare function initialize(configFile: {
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}): void;
|
|
24
24
|
export declare function watch(config: {
|
|
25
|
-
['input']: string | string[];
|
|
26
25
|
[key: string]: any;
|
|
26
|
+
input: string | string[];
|
|
27
27
|
}): void;
|
package/lib/node/compileFile.js
CHANGED
|
@@ -1,76 +1,102 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
2
11
|
import { compiler as statementMaker } from "../returnStatement.js";
|
|
3
|
-
import config from
|
|
12
|
+
import config from "../config.js";
|
|
4
13
|
import fs from "fs";
|
|
5
14
|
import fg from "fast-glob";
|
|
6
|
-
import path from
|
|
7
|
-
import postcss from
|
|
8
|
-
import postcssDiscardDuplicates from
|
|
9
|
-
import cssnano from
|
|
10
|
-
import chokidar from
|
|
11
|
-
import sortMediaQueries from
|
|
12
|
-
import { splitByCommaOutsideParens } from
|
|
15
|
+
import path from "path";
|
|
16
|
+
import postcss from "postcss";
|
|
17
|
+
import postcssDiscardDuplicates from "postcss-discard-duplicates";
|
|
18
|
+
import cssnano from "cssnano";
|
|
19
|
+
import chokidar from "chokidar";
|
|
20
|
+
import sortMediaQueries from "postcss-sort-media-queries";
|
|
21
|
+
import { splitByCommaOutsideParens } from "../utils/helper.js";
|
|
13
22
|
const init = {
|
|
14
|
-
classList: [],
|
|
23
|
+
classList: [],
|
|
15
24
|
groups: [],
|
|
16
|
-
input:
|
|
17
|
-
output:
|
|
18
|
-
|
|
25
|
+
input: "",
|
|
26
|
+
output: "",
|
|
27
|
+
"--file": false,
|
|
19
28
|
statementMaker,
|
|
20
29
|
config,
|
|
21
|
-
|
|
22
|
-
rawCSS:
|
|
30
|
+
"--module": false,
|
|
31
|
+
rawCSS: "",
|
|
23
32
|
layers: [],
|
|
24
|
-
|
|
33
|
+
initializedLayer: false,
|
|
34
|
+
customGroupStatement: "",
|
|
25
35
|
minify: false,
|
|
26
|
-
globPattern:
|
|
36
|
+
globPattern: "",
|
|
27
37
|
};
|
|
28
38
|
export default function main(config) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
initialize(config);
|
|
41
|
+
if (init.config.prefix)
|
|
42
|
+
init.statementMaker.prefix = init.config.prefix;
|
|
43
|
+
if (init.input && (init.output || init["--file"])) {
|
|
44
|
+
const input = fg.sync(init.input, { dot: true });
|
|
45
|
+
input.forEach((file) => {
|
|
46
|
+
createCSSFileByFile(file, true);
|
|
47
|
+
});
|
|
48
|
+
if (init.output) {
|
|
49
|
+
yield globalCSSCompiler();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
44
56
|
}
|
|
45
57
|
export function globalCSSCompiler() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
\n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${gbContent}
|
|
56
|
-
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
57
|
-
`, { flag: 'a+' });
|
|
58
|
-
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const classList = [];
|
|
60
|
+
if (init.globPattern && init.output) {
|
|
61
|
+
fs.truncateSync(init.output);
|
|
62
|
+
let basePreamble = "";
|
|
63
|
+
// 1. Layer declaration
|
|
64
|
+
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
65
|
+
basePreamble += `@layer ${init.layers.join(", ")};\n\n`;
|
|
66
|
+
init.initializedLayer = true;
|
|
59
67
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
// 2. Custom CSS statements & group statements
|
|
69
|
+
if (init.rawCSS) {
|
|
70
|
+
basePreamble += `/* Start :-----------ACSS:From aliasCSSConfig.statement------------------------*/\n${init.rawCSS}\n/* End :-----------ACSS aliasCSSConfig.statement----------------------------*/\n\n`;
|
|
63
71
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
if (init.customGroupStatement) {
|
|
73
|
+
basePreamble += `/* Start :-----------ACSS:From aliasCSSConfig.group------------------------*/\n${init.customGroupStatement}\n/* End :-----------ACSS aliasCSSConfig.group----------------------------*/\n\n`;
|
|
74
|
+
}
|
|
75
|
+
if (basePreamble) {
|
|
76
|
+
fs.writeFileSync(init.output, basePreamble, { flag: "a+" });
|
|
77
|
+
}
|
|
78
|
+
// 3. Process matched files
|
|
79
|
+
const input = fg.sync(init.globPattern, { dot: true });
|
|
80
|
+
input.forEach((file) => {
|
|
81
|
+
const [gbContent] = compileFile(file, config, statementMaker, classList);
|
|
82
|
+
try {
|
|
83
|
+
fs.writeFileSync(init.output, `/* Start :-----------ACSS ${path.relative(".", file)}------------------------*/\n${gbContent}\n/* End :-----------ACSS ${path.relative(".", file)}----------------------------*/\n\n`, { flag: "a+" });
|
|
84
|
+
console.log("AliasCSS compiled", path.relative(".", file), "to main css file :" + init.output);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
88
|
+
console.log(error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
yield postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
70
97
|
}
|
|
71
98
|
export function compileFile(file, config, statementMaker, globalClassList) {
|
|
72
|
-
let [globalStatement, compiledStatement, moduleStatement] = [
|
|
73
|
-
// inject config.group and config.statement
|
|
99
|
+
let [globalStatement, compiledStatement, moduleStatement] = ["", "", ""];
|
|
74
100
|
if (statementMaker.rawCSS) {
|
|
75
101
|
compiledStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* -----End:aliacss.config.statement----- */\n\n`;
|
|
76
102
|
moduleStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* ------End:aliacss.config.statement----- */\n\n`;
|
|
@@ -80,291 +106,200 @@ export function compileFile(file, config, statementMaker, globalClassList) {
|
|
|
80
106
|
moduleStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
81
107
|
}
|
|
82
108
|
const [classList, groups, keyframe, rawCSSStatement] = extractClassNamesFromFile(file, config);
|
|
83
|
-
// 1. raw-css
|
|
84
109
|
if (rawCSSStatement) {
|
|
85
|
-
globalStatement += rawCSSStatement +
|
|
86
|
-
compiledStatement += rawCSSStatement +
|
|
110
|
+
globalStatement += rawCSSStatement + "\n";
|
|
111
|
+
compiledStatement += rawCSSStatement + "\n";
|
|
87
112
|
}
|
|
88
|
-
// 2. group
|
|
89
113
|
for (const key in groups) {
|
|
90
|
-
if (
|
|
91
|
-
// --------------ModuleStatement
|
|
114
|
+
if (Object.prototype.hasOwnProperty.call(groups, key)) {
|
|
92
115
|
if (/^module=/.test(key)) {
|
|
93
|
-
|
|
94
|
-
moduleStatement += mdStatement + '\n';
|
|
116
|
+
moduleStatement += statementMaker.group(groups[key], key.replace(/module=/, "")) + "\n";
|
|
95
117
|
}
|
|
96
|
-
// -------------EndOfModule
|
|
97
118
|
else {
|
|
98
119
|
const gpStatement = statementMaker.group(groups[key], key);
|
|
99
|
-
globalStatement += gpStatement +
|
|
100
|
-
compiledStatement += gpStatement +
|
|
120
|
+
globalStatement += gpStatement + "\n";
|
|
121
|
+
compiledStatement += gpStatement + "\n";
|
|
101
122
|
}
|
|
102
123
|
}
|
|
103
124
|
}
|
|
104
|
-
// 2. ClassList
|
|
105
125
|
classList.forEach((e) => {
|
|
106
126
|
const statement = statementMaker.make(e);
|
|
107
127
|
if (statement) {
|
|
108
|
-
console.log('\x1b[32m', statement);
|
|
109
128
|
if (globalClassList.indexOf(e) === -1) {
|
|
110
|
-
globalStatement += statement +
|
|
129
|
+
globalStatement += statement + "\n";
|
|
111
130
|
globalClassList.push(e);
|
|
112
|
-
// console.log(e);
|
|
113
131
|
}
|
|
114
|
-
compiledStatement += statement +
|
|
132
|
+
compiledStatement += statement + "\n";
|
|
115
133
|
}
|
|
116
134
|
});
|
|
117
|
-
// 3. Keyframe
|
|
118
135
|
for (const key in keyframe) {
|
|
119
|
-
if (
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(keyframe, key)) {
|
|
120
137
|
const kfStatement = keyframesStatement(key, keyframe[key], statementMaker);
|
|
121
|
-
globalStatement += kfStatement +
|
|
122
|
-
compiledStatement += kfStatement +
|
|
138
|
+
globalStatement += kfStatement + "\n";
|
|
139
|
+
compiledStatement += kfStatement + "\n";
|
|
123
140
|
}
|
|
124
141
|
}
|
|
125
142
|
return [globalStatement, compiledStatement, moduleStatement];
|
|
126
143
|
}
|
|
127
144
|
export function groupStatement(name, classNames, statementMaker) {
|
|
128
|
-
return statementMaker.group(classNames, name) +
|
|
145
|
+
return statementMaker.group(classNames, name) + "\n";
|
|
129
146
|
}
|
|
130
147
|
export function keyframesStatement(name, timeLine, statementMaker) {
|
|
131
|
-
let kfStatement =
|
|
148
|
+
let kfStatement = "@keyframes " + name + "{\n";
|
|
132
149
|
const returnPnV = (e) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
133
150
|
const split = timeLine.split(/\s+/);
|
|
134
151
|
split.forEach((each) => {
|
|
135
152
|
try {
|
|
136
|
-
const [at, pNv] = each.replace(/\]\[/,
|
|
137
|
-
|
|
138
|
-
kfStatement += ` ${at.replace('@', '').replace(/:/g, ',').replace(/,/g, "%,").replace(/[\[|\]]/g, '')}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, '')))}}`;
|
|
153
|
+
const [at, pNv] = each.replace(/\]\[/, "]-[").replace("-", "=").split("=");
|
|
154
|
+
kfStatement += ` ${at.replace("@", "").replace(/:/g, ",").replace(/,/g, "%,").replace(/[\[|\]]/g, "")}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, "")))}}`;
|
|
139
155
|
}
|
|
140
156
|
catch (error) {
|
|
141
|
-
console.error(
|
|
157
|
+
console.error("Not a valid entry for AliasCSS keyframes processor : " + each, error);
|
|
142
158
|
}
|
|
143
159
|
});
|
|
144
160
|
return kfStatement + "\n}\n";
|
|
145
161
|
}
|
|
146
|
-
export function createCSSFileByFile(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
console.log(error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (init["--file"]) {
|
|
162
|
-
try {
|
|
163
|
-
fs.writeFileSync(file + '.css', content);
|
|
164
|
-
postify(file + '.css', [postcssDiscardDuplicates], init.minify);
|
|
165
|
-
// console.log(content);
|
|
166
|
-
console.log('AliasCSS compiled', path.relative('.', file), 'Locally');
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
170
|
-
console.log(error);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Check for Global
|
|
174
|
-
if (!bool && init.output) {
|
|
175
|
-
try {
|
|
176
|
-
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${postcss([postcssDiscardDuplicates]).process(gbContent)}
|
|
177
|
-
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
178
|
-
`, { flag: 'a+' });
|
|
179
|
-
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
162
|
+
export function createCSSFileByFile(file_1) {
|
|
163
|
+
return __awaiter(this, arguments, void 0, function* (file, bool = false) {
|
|
164
|
+
const [gbContent, content, module] = compileFile(file, config, statementMaker, init.classList);
|
|
165
|
+
if (init["--module"] && module.trim()) {
|
|
166
|
+
try {
|
|
167
|
+
fs.writeFileSync(file + ".module.css", module);
|
|
168
|
+
console.log("AliasCSS compiled", path.relative(".", file), "module Locally ");
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
172
|
+
console.log(error);
|
|
173
|
+
}
|
|
180
174
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
if (init["--file"]) {
|
|
176
|
+
try {
|
|
177
|
+
fs.writeFileSync(file + ".css", content);
|
|
178
|
+
yield postify(file + ".css", [postcssDiscardDuplicates], init.minify);
|
|
179
|
+
console.log("AliasCSS compiled", path.relative(".", file), "Locally");
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
183
|
+
console.log(error);
|
|
184
|
+
}
|
|
184
185
|
}
|
|
185
|
-
}
|
|
186
|
+
});
|
|
186
187
|
}
|
|
187
|
-
export function postify(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (minify
|
|
194
|
-
|
|
195
|
-
postcss(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
// fs.readFile(file, (err, css) => {
|
|
201
|
-
// postcss(plugin)
|
|
202
|
-
// .process(css, { from: file, to: file+"post.css" })
|
|
203
|
-
// .then(result => {
|
|
204
|
-
// fs.writeFile(file+"post.css", result.css, () => true)
|
|
205
|
-
// // if ( result.map ) {
|
|
206
|
-
// // fs.writeFile(file+'.map', result.map.toString(), () => true)
|
|
207
|
-
// // }
|
|
208
|
-
// })
|
|
209
|
-
// })
|
|
188
|
+
export function postify(file_1, plugin_1) {
|
|
189
|
+
return __awaiter(this, arguments, void 0, function* (file, plugin, minify = false, sort = "mobile-first") {
|
|
190
|
+
if (!fs.existsSync(file))
|
|
191
|
+
return;
|
|
192
|
+
const data = fs.readFileSync(file, "utf-8");
|
|
193
|
+
const plugins = [...plugin, sortMediaQueries({ sort })];
|
|
194
|
+
if (minify)
|
|
195
|
+
plugins.push(cssnano);
|
|
196
|
+
const result = yield postcss(plugins).process(data, { from: undefined });
|
|
197
|
+
fs.writeFileSync(file, result.css);
|
|
198
|
+
});
|
|
210
199
|
}
|
|
211
200
|
export function writeStatementToFile(file, content, from) {
|
|
212
|
-
// Check for Global
|
|
213
201
|
if (init.output) {
|
|
214
202
|
try {
|
|
215
|
-
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS:From aliasCSSConfig.${from}------------------------*/\n${content}
|
|
216
|
-
|
|
217
|
-
`, { flag: 'a+' });
|
|
218
|
-
console.log('AliasCSS compiled', '[aliasCSSConfig.statement]', 'aliascss.config.js');
|
|
203
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS:From aliasCSSConfig.${from}------------------------*/\n${content}\n/* End :-----------ACSS aliasCSSConfig.${from}----------------------------*/\n`, { flag: "a+" });
|
|
204
|
+
console.log("AliasCSS compiled", `[aliasCSSConfig.${from}]`, "aliascss.config.js");
|
|
219
205
|
}
|
|
220
206
|
catch (error) {
|
|
221
|
-
console.log('\x1b[31m',
|
|
207
|
+
console.log('\x1b[31m', `Couldn't able to append/create [key:${from}] from alias.config.js`);
|
|
222
208
|
console.log(error);
|
|
223
209
|
}
|
|
224
210
|
}
|
|
225
211
|
}
|
|
226
|
-
// Initialize
|
|
227
212
|
export function initialize(configFile) {
|
|
228
|
-
|
|
229
|
-
if (configFile.hasOwnProperty('input')) {
|
|
213
|
+
if (configFile.hasOwnProperty("input")) {
|
|
230
214
|
init.input = configFile.input;
|
|
231
215
|
init.globPattern = configFile.input;
|
|
232
216
|
}
|
|
233
|
-
|
|
234
|
-
if (configFile.hasOwnProperty('layers') && Array.isArray(configFile.layers)) {
|
|
217
|
+
if (configFile.hasOwnProperty("layers") && Array.isArray(configFile.layers)) {
|
|
235
218
|
init.layers = configFile.layers;
|
|
236
219
|
}
|
|
237
220
|
else {
|
|
238
221
|
init.layers = config.layers;
|
|
239
222
|
}
|
|
240
|
-
|
|
241
|
-
if (configFile.hasOwnProperty('prefix')) {
|
|
223
|
+
if (configFile.hasOwnProperty("prefix")) {
|
|
242
224
|
init.config.prefix = configFile.prefix;
|
|
243
225
|
}
|
|
244
|
-
|
|
245
|
-
if (configFile.hasOwnProperty('output')) {
|
|
226
|
+
if (configFile.hasOwnProperty("output")) {
|
|
246
227
|
const op = configFile.output;
|
|
247
|
-
if (op.hasOwnProperty(
|
|
228
|
+
if (op.hasOwnProperty("location"))
|
|
248
229
|
init.output = op.location;
|
|
249
|
-
|
|
250
|
-
if (op.hasOwnProperty('--file') && op['--file'] === true) {
|
|
230
|
+
if (op.hasOwnProperty("--file") && op["--file"] === true)
|
|
251
231
|
init["--file"] = true;
|
|
252
|
-
}
|
|
253
232
|
}
|
|
254
|
-
|
|
255
|
-
if (configFile.hasOwnProperty('custom') && typeof configFile.custom === 'object') {
|
|
233
|
+
if (configFile.hasOwnProperty("custom") && typeof configFile.custom === "object") {
|
|
256
234
|
Object.keys(configFile.custom).forEach((key) => {
|
|
257
235
|
init.statementMaker.addCustom(key, configFile.custom[key]);
|
|
258
236
|
});
|
|
259
237
|
}
|
|
260
|
-
|
|
261
|
-
if (configFile.hasOwnProperty('prebuild')) {
|
|
238
|
+
if (configFile.hasOwnProperty("prebuild")) {
|
|
262
239
|
init.statementMaker.prebuild(configFile.prebuild);
|
|
263
240
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (Array.isArray(configFile.ignore)) {
|
|
267
|
-
configFile.ignore.forEach((each) => init.config.ignore.push(each.trim()));
|
|
268
|
-
}
|
|
241
|
+
if (configFile.hasOwnProperty("ignore") && Array.isArray(configFile.ignore)) {
|
|
242
|
+
configFile.ignore.forEach((each) => init.config.ignore.push(each.trim()));
|
|
269
243
|
}
|
|
270
|
-
|
|
271
|
-
if (configFile.hasOwnProperty('--module') && configFile.hasOwnProperty('importModuleAs')) {
|
|
244
|
+
if (configFile.hasOwnProperty("--module") && configFile.hasOwnProperty("importModuleAs")) {
|
|
272
245
|
init["--module"] = true;
|
|
273
|
-
init.config.useCSSModule =
|
|
274
|
-
|
|
275
|
-
init.config.matchCSSModuleFunction = init.config.createCSSModuleRegex(configFile.importModuleAs);
|
|
246
|
+
init.config.useCSSModule = true;
|
|
247
|
+
init.config.matchCSSModuleFunction = init.config.createCSSModuleRegex(configFile.importModuleAs);
|
|
276
248
|
}
|
|
277
|
-
|
|
278
|
-
if (configFile.hasOwnProperty('minify')) {
|
|
249
|
+
if (configFile.hasOwnProperty("minify")) {
|
|
279
250
|
init.minify = configFile.minify;
|
|
280
251
|
}
|
|
281
|
-
|
|
282
|
-
if (configFile.hasOwnProperty('extractorFunction')) {
|
|
252
|
+
if (configFile.hasOwnProperty("extractorFunction")) {
|
|
283
253
|
init.config.useExtractorFunction = configFile.extractorFunction.trim() ? true : false;
|
|
284
254
|
if (init.config.useExtractorFunction)
|
|
285
255
|
init.config.matchExtractorFunction = init.config.createExtractorRegex(configFile.extractorFunction);
|
|
286
256
|
}
|
|
287
257
|
else {
|
|
288
258
|
init.config.useExtractorFunction = true;
|
|
289
|
-
init.config.matchExtractorFunction = init.config.createExtractorRegex(
|
|
259
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex("String");
|
|
290
260
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const filteredObj = {};
|
|
294
|
-
Object.keys(configFile.extend).map((key) => {
|
|
295
|
-
// if (configFile.extend[key].hasOwnProperty('compiler') && (typeof configFile.extend[key].compiler === 'function')){
|
|
296
|
-
filteredObj[key] = configFile.extend[key];
|
|
297
|
-
// }
|
|
298
|
-
});
|
|
299
|
-
init.statementMaker.extend(filteredObj);
|
|
261
|
+
if (configFile.hasOwnProperty("extend") && typeof configFile.extend === "object") {
|
|
262
|
+
init.statementMaker.extend(configFile.extend);
|
|
300
263
|
}
|
|
301
|
-
|
|
302
|
-
if (configFile.hasOwnProperty('useColon')) {
|
|
264
|
+
if (configFile.hasOwnProperty("useColon")) {
|
|
303
265
|
init.config.useColon = configFile.useColon;
|
|
304
266
|
}
|
|
305
|
-
|
|
306
|
-
if (configFile.hasOwnProperty('media') && typeof configFile.media === 'object') {
|
|
267
|
+
if (configFile.hasOwnProperty("media") && typeof configFile.media === "object") {
|
|
307
268
|
init.statementMaker.addMedia(configFile.media);
|
|
308
269
|
}
|
|
309
|
-
|
|
310
|
-
if (configFile.hasOwnProperty('truncate') && configFile.truncate === false) {
|
|
311
|
-
// do nothing
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
if (fs.existsSync(init.output))
|
|
315
|
-
fs.truncateSync(path.resolve(init.output));
|
|
316
|
-
writeStatementToFile(init.output, `@layer ${init.layers.join(', ')};`, 'Initializating @layer,');
|
|
317
|
-
}
|
|
318
|
-
// Custom CSS statement
|
|
319
|
-
if (configFile.hasOwnProperty('statement')) {
|
|
270
|
+
if (configFile.hasOwnProperty("statement")) {
|
|
320
271
|
init.rawCSS = configFile.statement;
|
|
321
272
|
init.statementMaker.rawCSS = configFile.statement;
|
|
322
|
-
writeStatementToFile(init.output, configFile.statement, 'config.statement');
|
|
323
273
|
}
|
|
324
|
-
|
|
325
|
-
if (configFile.hasOwnProperty('group')) {
|
|
274
|
+
if (configFile.hasOwnProperty("group")) {
|
|
326
275
|
init.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
327
276
|
init.statementMaker.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
328
|
-
if (init.customGroupStatement)
|
|
329
|
-
writeStatementToFile(init.output, init.customGroupStatement, 'config.group');
|
|
330
277
|
}
|
|
331
278
|
}
|
|
332
|
-
// ----------------WATCH-------------------------------
|
|
333
279
|
export function watch(config) {
|
|
334
280
|
main(config);
|
|
335
281
|
const watcher = chokidar.watch(init.input, {
|
|
336
|
-
ignored:
|
|
337
|
-
persistent: true
|
|
282
|
+
ignored: "*.css",
|
|
283
|
+
persistent: true,
|
|
338
284
|
});
|
|
339
|
-
const compileFile = (file) => {
|
|
285
|
+
const compileFile = (file) => __awaiter(this, void 0, void 0, function* () {
|
|
340
286
|
console.log(`--processing file : ${file}`);
|
|
341
|
-
createCSSFileByFile(file, true);
|
|
342
|
-
globalCSSCompiler();
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
};
|
|
346
|
-
// Something to use when events are received.
|
|
287
|
+
yield createCSSFileByFile(file, true);
|
|
288
|
+
yield globalCSSCompiler();
|
|
289
|
+
console.log("Done! ");
|
|
290
|
+
});
|
|
347
291
|
const log = console.log.bind(console);
|
|
348
|
-
// Add event listeners.
|
|
349
292
|
watcher
|
|
350
|
-
.on(
|
|
351
|
-
.on(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
|
357
|
-
// .on('error', error => log(`Watcher error: ${error}`))
|
|
358
|
-
// .on('ready', () => log('Initial scan complete. Ready for changes'))
|
|
359
|
-
.on('raw', (event, path, details) => {
|
|
360
|
-
// log('Raw event info:', event, path, details);
|
|
361
|
-
if (event === 'created' && details.type === 'file') {
|
|
293
|
+
.on("add", (path) => log(`File ${path} has been added to watch`))
|
|
294
|
+
.on("change", (path) => compileFile(path))
|
|
295
|
+
.on("addDir", (path) => log(`Directory ${path} has been added`))
|
|
296
|
+
.on("unlinkDir", (path) => log(`Directory ${path} has been removed`))
|
|
297
|
+
.on("raw", (event, path, details) => {
|
|
298
|
+
if (event === "created" && details.type === "file") {
|
|
362
299
|
if (init.globPattern) {
|
|
363
300
|
const files = fg.sync(init.globPattern, { absolute: true });
|
|
364
|
-
if (files.indexOf(path) !== -1)
|
|
301
|
+
if (files.indexOf(path) !== -1)
|
|
365
302
|
watcher.add(path);
|
|
366
|
-
// console.log(path,123123);
|
|
367
|
-
}
|
|
368
303
|
}
|
|
369
304
|
else {
|
|
370
305
|
watcher.add(path);
|