sheetloaf 1.1.0-beta.0 → 1.2.0-beta.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/README.md CHANGED
@@ -70,6 +70,8 @@ Advanced options:
70
70
  --poll Use polling for file watching. Can optionally pass polling [boolean]
71
71
  interval; default 100 ms
72
72
  --config Set a custom directory to look for a config file [string]
73
+ --async Use Sass's compileAsyc/compileStringAsync functions. [boolean]
74
+ This will be slower in most cases.
73
75
 
74
76
  Misc:
75
77
  -v, --version Show version number [boolean]
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateSassOptionsAsync = exports.generateSassOptions = exports.generatePostcssConfigFromUse = exports.generatePostcssConfigFromFile = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ function generatePostcssConfigFromFile(configPath = '') {
10
+ let obj = {
11
+ plugins: []
12
+ };
13
+ let configFileLoc = path_1.default.resolve(process.cwd(), configPath, 'postcss.config.js');
14
+ try {
15
+ fs_1.default.lstatSync(configFileLoc);
16
+ obj = require(configFileLoc);
17
+ }
18
+ catch (e) {
19
+ console.log(`No postcss.config.js file found at location ${configPath}`);
20
+ }
21
+ return obj;
22
+ }
23
+ exports.generatePostcssConfigFromFile = generatePostcssConfigFromFile;
24
+ function generatePostcssConfigFromUse(useArg) {
25
+ let obj = {
26
+ plugins: []
27
+ };
28
+ useArg.split(',').forEach(function (plugin) {
29
+ obj.plugins.push(require(plugin));
30
+ });
31
+ return obj;
32
+ }
33
+ exports.generatePostcssConfigFromUse = generatePostcssConfigFromUse;
34
+ function generateSassOptions(opts) {
35
+ return {
36
+ style: opts.style,
37
+ loadPaths: opts.loadPath ? opts.loadPath.split(',') : [],
38
+ sourceMap: opts.sourceMap === false ? false : true,
39
+ sourceMapIncludeSources: opts.sourceMap === false ? false : true
40
+ };
41
+ }
42
+ exports.generateSassOptions = generateSassOptions;
43
+ function generateSassOptionsAsync(opts) {
44
+ return {
45
+ style: opts.style,
46
+ loadPaths: opts.loadPath ? opts.loadPath.split(',') : [],
47
+ sourceMap: opts.sourceMap === false ? false : true,
48
+ sourceMapIncludeSources: opts.sourceMap === false ? false : true
49
+ };
50
+ }
51
+ exports.generateSassOptionsAsync = generateSassOptionsAsync;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildDestinationPath = exports.getAllFilesPathsFromSources = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const picomatch_1 = __importDefault(require("picomatch"));
10
+ const fast_glob_1 = __importDefault(require("fast-glob"));
11
+ function getAllFilesPathsFromSources(input, callback) {
12
+ let sourcesCompleted = 0;
13
+ let filePaths = [];
14
+ for (let i = 0; i < input.length; i++) {
15
+ let isGlob, isDir, isFile = false;
16
+ isGlob = picomatch_1.default.scan(input[i]).isGlob;
17
+ if (isGlob === true) {
18
+ getGlobPaths(input[i], (files) => {
19
+ filePaths.push(...files);
20
+ sourcesCompleted++;
21
+ if (sourcesCompleted === input.length) {
22
+ callback([...new Set(filePaths)].sort());
23
+ }
24
+ });
25
+ }
26
+ else {
27
+ try {
28
+ isDir = fs_1.default.lstatSync(path_1.default.normalize(input[i])).isDirectory();
29
+ isFile = fs_1.default.lstatSync(path_1.default.normalize(input[i])).isFile();
30
+ if (isFile) {
31
+ getGlobPaths(input[i], (files) => {
32
+ filePaths.push(...files);
33
+ sourcesCompleted++;
34
+ if (sourcesCompleted === input.length) {
35
+ callback([...new Set(filePaths)].sort());
36
+ }
37
+ });
38
+ }
39
+ else if (isDir) {
40
+ getAllFilePathsInDir(input[i], (files) => {
41
+ filePaths.push(...files);
42
+ sourcesCompleted++;
43
+ if (sourcesCompleted === input.length) {
44
+ callback([...new Set(filePaths)].sort());
45
+ }
46
+ });
47
+ }
48
+ }
49
+ catch (err) {
50
+ throw err;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ exports.getAllFilesPathsFromSources = getAllFilesPathsFromSources;
56
+ function getGlobPaths(glob, callback) {
57
+ let expanded = fast_glob_1.default
58
+ .sync(glob, {
59
+ dot: true
60
+ })
61
+ .map((entry) => path_1.default.normalize(entry));
62
+ callback(expanded);
63
+ }
64
+ function getAllFilePathsInDir(dir, callback) {
65
+ let files = [];
66
+ fs_1.default.readdir(dir, (err, nodes) => {
67
+ if (err) {
68
+ throw err;
69
+ }
70
+ else {
71
+ nodes.forEach((file) => {
72
+ let fullname = path_1.default.join(dir, file);
73
+ if (!fs_1.default.lstatSync(fullname).isDirectory()) {
74
+ files.push(fullname);
75
+ }
76
+ });
77
+ callback(files);
78
+ }
79
+ });
80
+ }
81
+ function buildDestinationPath(fileName, outFile = '', dir = '', base = '', extension = '.css', usingStdin) {
82
+ let destination = '';
83
+ let mirror = '';
84
+ if (usingStdin === true) {
85
+ if (outFile.length > 0) {
86
+ destination = outFile;
87
+ }
88
+ else {
89
+ destination = '';
90
+ }
91
+ }
92
+ else {
93
+ if (dir.length > 0) {
94
+ if (base.length > 0) {
95
+ mirror = path_1.default.dirname(fileName.replace(path_1.default.join(base, '/'), ''));
96
+ }
97
+ destination = path_1.default.join(dir, mirror, path_1.default.basename(fileName, path_1.default.extname(fileName)) + extension);
98
+ }
99
+ else if (outFile.length > 0) {
100
+ destination = outFile;
101
+ }
102
+ else {
103
+ destination = '';
104
+ }
105
+ }
106
+ return destination;
107
+ }
108
+ exports.buildDestinationPath = buildDestinationPath;
package/dist/index.js CHANGED
@@ -1,2 +1,283 @@
1
1
  #!/usr/bin/env node
2
- const chokidar=require("chokidar"),color=require("picocolors"),{Command}=require("commander"),fs=require("fs"),path=require("path"),postcss=require("postcss"),sass=require("sass"),parser=require("./parser"),ver=require("../package.json").version,sheetloaf=new Command;let postcssConfig={plugins:[]},usingStdin=!1;sheetloaf.version(ver,"-v, --version","Print the version of Sheetloaf."),sheetloaf.arguments("[sources...]").description("\u{1F4C3}\u{1F35E} Compile Sass to CSS and transform the output using PostCSS all in one command.").action(o=>{if(o.length>0)init(o);else if(!process.stdin.isTTY){let e="";process.stdin.on("readable",function(){var t=this.read();t!==null&&(e+=t)}),process.stdin.on("end",function(){usingStdin=!0,init(e)})}}),sheetloaf.option("-o, --output <LOCATION>","Output file.").option("--dir <LOCATION>","Output directory.").option("--base <DIR>","Mirror the directory structure relative to this path in the output directory, for use with --dir.","").option("--ext <EXTENSION>","Override the output file extension; for use with --dir",".css").option("-s, --style <NAME>",'Output style. ["expanded", "compressed"]',"expanded").option("--source-map","Generate a source map (this is the default option).").option("--no-source-map","Do not generate a source map.").option("--embed-source-map","Embed the contents of the source map file in the generated CSS, rather than creating a separate file and linking to it from the CSS.").option("--embed-sources","Embed the entire contents of the Sass files that contributed to the generated CSS in the source map.").option("--source-map-urls <TYPE>",'Controls how the source maps that Sass generates link back to the Sass files that contributed to the generated CSS. ["relative", "absolute"]',"relative").option("--error-css","Emit a CSS file when an error occurs during compilation (this is the default option).").option("--no-error-css","Do not emit a CSS file when an error occurs during compilation.").option("-I, --load-path <PATHS>","Adds an additional load path for Sass to look for stylesheets.").option("-w, --watch","Watch stylesheets and recompile when they change.").option("--config <LOCATION>","Set a custom directory to look for a postcss config file.").option("--poll [DURATION]","Use polling for file watching. Can optionally pass polling interval; default 100 ms").option("-u, --use <PLUGINS>","List of postcss plugins to use. Will cause sheetloaf to ignore any config files."),sheetloaf.parse(process.argv);function init(o){postcssConfig=parser.generatePostcssConfig(sheetloaf.opts().config,sheetloaf.opts().use),usingStdin===!0?render(o):(parser.expandGlob(o[0].split(","),function(e){e.forEach(function(t){path.basename(t).charAt(0)!=="_"&&render(t)})}),watch(o))}function watch(o){sheetloaf.opts().watch===!0&&chokidar.watch(o[0].split(","),{usePolling:sheetloaf.opts().poll!==void 0,interval:typeof sheetloaf.opts().poll=="number"?sheetloaf.opts().poll:100,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1500,pollInterval:100}}).on("change",e=>{console.log(`File changed: ${e}`),parser.expandGlob(o[0].split(","),function(t){t.forEach(function(i){path.basename(i).charAt(0)!=="_"&&render(i)})})}).on("add",e=>{console.log(`File added: ${e}`),parser.expandGlob(o[0].split(","),function(t){t.forEach(function(i){path.basename(i).charAt(0)!=="_"&&render(i)})})})}function render(o){usingStdin===!1&&console.log(`Rendering ${o}...`);let e=parser.createDestination(o,sheetloaf.opts().output,sheetloaf.opts().dir,sheetloaf.opts().base,sheetloaf.opts().ext,usingStdin),t=generateSassOptions(o,e),i={inline:sheetloaf.opts().embedSourceMap===!0,absolute:sheetloaf.opts().sourceMapUrls==="absolute",sourcesContent:sheetloaf.opts().embedSources===!0};usingStdin===!1&&sheetloaf.opts().sourceMap===!1&&(i=!1);try{let n=sass.renderSync(t);postcss(postcssConfig.plugins).process(n.css.toString(),{from:n.stats.entry,to:e,map:i}).then(s=>{if(s.warnings().forEach(r=>{process.stderr.write(r.toString())}),e!==""){try{fs.mkdirSync(path.dirname(e),{recursive:!0})}catch(r){if(r.code!=="EEXIST"||r.code!=="EISDIR")throw r}fs.writeFile(e,s.css,r=>{if(r)throw r;console.log(color.green(`Successfully written to ${e}`))}),s.map&&fs.writeFile(e+".map",s.map.toString(),r=>{if(r)throw r})}else process.stdout.write(s.css)}).catch(s=>{e!==""?console.log(color.red(s)):process.stderr.write(s)})}catch(n){if(e!==""){console.log(color.red(n.formatted));try{fs.mkdirSync(path.dirname(e),{recursive:!0})}catch(s){if(s.code!=="EEXIST"||s.code!=="EISDIR")throw s}sheetloaf.opts().errorCss!==!1&&fs.writeFile(e,emitSassError(n),s=>{if(s)throw s;console.log(color.yellow(`Emitted error to ${e}`))})}else process.stderr.write(n.formatted);!sheetloaf.opts().watch&&(process.exitCode==null||process.exitCode===0)&&(process.exitCode=1)}}function generateSassOptions(o,e){let t={outFile:e,outputStyle:sheetloaf.opts().style,includePaths:sheetloaf.opts().loadPath?sheetloaf.opts().loadPath.split(","):[]};return usingStdin===!0?(t.data=o,t.sourceMap=!1,t.sourceMapContents=!1,t.sourceMapEmbed=!1):(t.file=o,t.sourceMap=sheetloaf.opts().sourceMap!==!1,t.sourceMapContents=sheetloaf.opts().sourceMap!==!1,t.sourceMapEmbed=sheetloaf.opts().sourceMap!==!1),t}function emitSassError(o){let e=o.formatted.substr(0,o.formatted.indexOf("^")).replace(/(\r\n|\n|\r)/gm," ").replace(/'/,"").replace(/╷.*?│/,"").replace(/│/,"").replace("'","").replace("'",""),t=o.file.replace(/\\/g,"/");return`body:before { content: 'Line ${o.line}: ${e}';display: table;background-color:#cc0000;color:white;border-radius:5px;margin-bottom:5px;padding:5px;font-family:sans-serif}body:after { content: '${t}';display: table;background-color:#0e70b0;color:white;border-radius:5px;padding:5px;margin-bottom: 5px;font-family:sans-serif}body * { display: none; }`}
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const commander_1 = require("commander");
40
+ const chokidar_1 = __importDefault(require("chokidar"));
41
+ const picocolors_1 = __importDefault(require("picocolors"));
42
+ const fs_1 = __importDefault(require("fs"));
43
+ const path_1 = __importDefault(require("path"));
44
+ const sass_1 = __importDefault(require("sass"));
45
+ const postcss_1 = __importDefault(require("postcss"));
46
+ const configs = __importStar(require("./configs"));
47
+ const fileFinder = __importStar(require("./fileFinder"));
48
+ const sheetloaf = new commander_1.Command();
49
+ sheetloaf.version("1.2.0", '-v, --version', 'Print the version of Sheetloaf.');
50
+ let usingStdin = false;
51
+ let postcssConfig = {
52
+ plugins: []
53
+ };
54
+ sheetloaf
55
+ .arguments('[sources...]')
56
+ .description('📃🍞 Compile Sass to CSS and transform the output using PostCSS, all in one command.')
57
+ .action((source) => {
58
+ if (sheetloaf.opts().use) {
59
+ postcssConfig = configs.generatePostcssConfigFromUse(sheetloaf.opts().use);
60
+ }
61
+ else {
62
+ postcssConfig = configs.generatePostcssConfigFromFile(sheetloaf.opts().config);
63
+ }
64
+ if (source.length > 0) {
65
+ renderAllFiles(source);
66
+ watch(source);
67
+ }
68
+ else if (!process.stdin.isTTY) {
69
+ let stdin = '';
70
+ process.stdin.on('readable', () => {
71
+ var chunk = process.stdin.read();
72
+ if (chunk !== null) {
73
+ stdin += chunk;
74
+ }
75
+ });
76
+ process.stdin.on('end', () => {
77
+ usingStdin = true;
78
+ renderSassFromStdin(stdin);
79
+ });
80
+ }
81
+ });
82
+ sheetloaf
83
+ .option('-o, --output <LOCATION>', 'Output file.')
84
+ .option('--dir <LOCATION>', 'Output directory.')
85
+ .option('--base <DIR>', 'Mirror the directory structure relative to this path in the output directory, for use with --dir.', '')
86
+ .option('--ext <EXTENSION>', 'Override the output file extension; for use with --dir', '.css')
87
+ .option('-s, --style <NAME>', 'Output style. ["expanded", "compressed"]', 'expanded')
88
+ .option('--source-map', 'Generate a source map (this is the default option).')
89
+ .option('--no-source-map', 'Do not generate a source map.')
90
+ .option('--embed-source-map', 'Embed the contents of the source map file in the generated CSS, rather than creating a separate file and linking to it from the CSS.')
91
+ .option('--embed-sources', 'Embed the entire contents of the Sass files that contributed to the generated CSS in the source map.')
92
+ .option('--source-map-urls <TYPE>', 'Controls how the source maps that Sass generates link back to the Sass files that contributed to the generated CSS. ["relative", "absolute"]', 'relative')
93
+ .option('--error-css', 'Emit a CSS file when an error occurs during compilation (this is the default option).')
94
+ .option('--no-error-css', 'Do not emit a CSS file when an error occurs during compilation.')
95
+ .option('-I, --load-path <PATHS>', 'Adds an additional load path for Sass to look for stylesheets.')
96
+ .option('-w, --watch', 'Watch stylesheets and recompile when they change.')
97
+ .option('--config <LOCATION>', 'Set a custom directory to look for a postcss config file.')
98
+ .option('--poll [DURATION]', 'Use polling for file watching. Can optionally pass polling interval; default 100 ms')
99
+ .option('-u, --use <PLUGINS>', 'List of postcss plugins to use. Will cause sheetloaf to ignore any config files.')
100
+ .option('--async', `Use sass' asynchronous API. This may be slower.`);
101
+ sheetloaf.parse(process.argv);
102
+ function renderAllFiles(source) {
103
+ fileFinder.getAllFilesPathsFromSources(source[0].split(','), function (entries) {
104
+ entries.forEach(function (fileName) {
105
+ if (path_1.default.basename(fileName).charAt(0) !== '_') {
106
+ renderSass(fileName);
107
+ }
108
+ });
109
+ });
110
+ }
111
+ function watch(source) {
112
+ if (sheetloaf.opts().watch === true) {
113
+ chokidar_1.default
114
+ .watch(source[0].split(','), {
115
+ usePolling: sheetloaf.opts().poll !== undefined,
116
+ interval: typeof sheetloaf.opts().poll === 'number' ? sheetloaf.opts().poll : 100,
117
+ ignoreInitial: true,
118
+ awaitWriteFinish: {
119
+ stabilityThreshold: 1500,
120
+ pollInterval: 100
121
+ }
122
+ })
123
+ .on('change', (changed) => {
124
+ console.log(`File changed: ${changed}`);
125
+ renderAllFiles(source);
126
+ })
127
+ .on('add', (added) => {
128
+ console.log(`File added: ${added}`);
129
+ renderAllFiles(source);
130
+ });
131
+ }
132
+ }
133
+ function renderSass(fileName) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const destination = fileFinder.buildDestinationPath(fileName, sheetloaf.opts().output, sheetloaf.opts().dir, sheetloaf.opts().base, sheetloaf.opts().ext, usingStdin);
136
+ try {
137
+ if (sheetloaf.opts().async === true) {
138
+ const options = configs.generateSassOptionsAsync(sheetloaf.opts());
139
+ const result = yield sass_1.default.compileAsync(fileName, options);
140
+ renderPost(fileName, destination, result);
141
+ }
142
+ else {
143
+ const options = configs.generateSassOptions(sheetloaf.opts());
144
+ const result = sass_1.default.compile(fileName, options);
145
+ renderPost(fileName, destination, result);
146
+ }
147
+ }
148
+ catch (e) {
149
+ sassErrorCatcher(e, destination);
150
+ }
151
+ });
152
+ }
153
+ function renderSassFromStdin(text) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ const destination = fileFinder.buildDestinationPath('', sheetloaf.opts().output, sheetloaf.opts().dir, sheetloaf.opts().base, sheetloaf.opts().ext, usingStdin);
156
+ try {
157
+ if (sheetloaf.opts().async === true) {
158
+ const options = configs.generateSassOptionsAsync(sheetloaf.opts());
159
+ const result = yield sass_1.default.compileStringAsync(text, options);
160
+ renderPost('', destination, result);
161
+ }
162
+ else {
163
+ const options = configs.generateSassOptions(sheetloaf.opts());
164
+ const result = sass_1.default.compileString(text, options);
165
+ renderPost('', destination, result);
166
+ }
167
+ }
168
+ catch (e) {
169
+ sassErrorCatcher(e, destination);
170
+ }
171
+ });
172
+ }
173
+ function renderPost(fileName, destination, sassResult) {
174
+ let postcssMapOptions = {
175
+ annotation: true,
176
+ prev: sassResult.sourceMap,
177
+ inline: sheetloaf.opts().embedSourceMap === true ? true : false,
178
+ absolute: sheetloaf.opts().sourceMapUrls === 'absolute' ? true : false,
179
+ sourcesContent: sheetloaf.opts().embedSources === true ? true : false,
180
+ };
181
+ if (usingStdin === true || sheetloaf.opts().sourceMap === false) {
182
+ postcssMapOptions = false;
183
+ }
184
+ (0, postcss_1.default)(postcssConfig.plugins)
185
+ .process(sassResult.css.toString(), {
186
+ from: fileName,
187
+ to: destination,
188
+ map: postcssMapOptions
189
+ })
190
+ .then((postedResult) => {
191
+ postedResult.warnings().forEach((warn) => {
192
+ process.stderr.write(warn.toString());
193
+ });
194
+ if (destination !== '') {
195
+ try {
196
+ fs_1.default.mkdirSync(path_1.default.dirname(destination), {
197
+ recursive: true
198
+ });
199
+ }
200
+ catch (err) {
201
+ if (err.code !== 'EEXIST' || err.code !== 'EISDIR')
202
+ throw err;
203
+ }
204
+ fs_1.default.writeFile(destination, postedResult.css, (err) => {
205
+ if (err)
206
+ throw err;
207
+ console.log(picocolors_1.default.green(`Successfully written to ${destination}`));
208
+ });
209
+ if (postedResult.map) {
210
+ fs_1.default.writeFile(destination + '.map', postedResult.map.toString(), (err) => {
211
+ if (err)
212
+ throw err;
213
+ });
214
+ }
215
+ }
216
+ else {
217
+ process.stdout.write(postedResult.css);
218
+ }
219
+ })
220
+ .catch((err) => {
221
+ if (destination !== '') {
222
+ console.log(picocolors_1.default.red(err));
223
+ }
224
+ else {
225
+ process.stderr.write(err);
226
+ }
227
+ });
228
+ }
229
+ function sassErrorCatcher(e, destination) {
230
+ if (destination !== '') {
231
+ console.log(e.message);
232
+ try {
233
+ fs_1.default.mkdirSync(path_1.default.dirname(destination), {
234
+ recursive: true
235
+ });
236
+ }
237
+ catch (mkDirErr) {
238
+ if (mkDirErr.code !== 'EEXIST' || mkDirErr.code !== 'EISDIR')
239
+ throw mkDirErr;
240
+ }
241
+ if (sheetloaf.opts().errorCss !== false) {
242
+ fs_1.default.writeFile(destination, emitSassError(e), (writeFileErr) => {
243
+ if (writeFileErr)
244
+ throw writeFileErr;
245
+ console.log(picocolors_1.default.yellow(`Emitted error to ${destination}`));
246
+ });
247
+ }
248
+ }
249
+ else {
250
+ process.stderr.write(e.message);
251
+ }
252
+ if (!sheetloaf.opts().watch && (process.exitCode == null || process.exitCode === 0)) {
253
+ process.exitCode = 1;
254
+ }
255
+ }
256
+ function emitSassError(err) {
257
+ const span = err.span.toString().replace(/'.*'/i, '');
258
+ const message = err.sassMessage.toString().replace(/'.*'/i, '');
259
+ let css = `
260
+ body:before {
261
+ content: 'Error from ${span}';
262
+ display: table;
263
+ background-color:#cc0000;
264
+ color:white;
265
+ border-radius:5px;
266
+ margin-bottom:5px;
267
+ padding:5px;
268
+ font-family:sans-serif
269
+ }
270
+ body:after {
271
+ content: "${message}";
272
+ display: table;
273
+ background-color:#0e70b0;
274
+ color:white;
275
+ border-radius:5px;
276
+ padding:5px;
277
+ margin-bottom: 5px;
278
+ font-family:sans-serif
279
+ }
280
+ body * { display: none; }
281
+ `;
282
+ return css;
283
+ }
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "sheetloaf",
3
- "version": "1.1.0-beta.0",
3
+ "version": "1.2.0-beta.1",
4
4
  "description": "freshmade stylesheets for the whole family.",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
7
7
  "sheetloaf": "./dist/index.js"
8
8
  },
9
+ "type": "module",
9
10
  "scripts": {
10
- "build": "esbuild src/*.js --outdir=dist --platform=node --target=node10.4 --minify",
11
- "test": "mocha",
11
+ "build:development": "tsc --watch",
12
+ "build:production": "tsc",
13
+ "test": "mocha -r ts-node/register test/*.test.ts",
12
14
  "test2": "node . \"test/samples/styles/**/*.scss\" --dir \"test/samples/render/\" --load-path \"test/samples/lib\" --style compressed --base test/samples/styles/ --use autoprefixer,postcss-custom-properties",
13
15
  "test3": "cat test/samples/styles/file.scss | node . --style compressed --use autoprefixer --load-path test/samples/styles > test/samples/render/file.css",
14
16
  "test4": "cat test/samples/styles/file-with-error.scss | node . --style compressed --use autoprefixer > test/samples/render/file.css 2> test/samples/logs/error.log"
@@ -33,22 +35,26 @@
33
35
  },
34
36
  "homepage": "https://github.com/cheddarbread/sheetloaf#readme",
35
37
  "devDependencies": {
36
- "autoprefixer": "^10.4.4",
37
- "esbuild": "^0.14.36",
38
- "lodash": "^4.17.21",
38
+ "@types/mocha": "^9.1.1",
39
+ "@types/node": "^18.6.3",
40
+ "@types/picomatch": "^2.3.0",
41
+ "@types/sass": "^1.43.1",
42
+ "autoprefixer": "^10.4.8",
39
43
  "mocha": "^9.2.2",
40
- "postcss": "^8.4.12",
41
- "postcss-custom-properties": "^12.1.7"
44
+ "postcss": "^8.4.14",
45
+ "postcss-custom-properties": "^12.1.8",
46
+ "ts-node": "^10.9.1",
47
+ "typescript": "^4.7.4"
42
48
  },
43
49
  "peerDependencies": {
44
50
  "postcss": "^8.4.0"
45
51
  },
46
52
  "dependencies": {
47
53
  "chokidar": "^3.5.3",
48
- "commander": "^8.3.0",
54
+ "commander": "^9.4.0",
49
55
  "fast-glob": "^3.2.11",
50
56
  "picocolors": "^1.0.0",
51
57
  "picomatch": "^2.3.1",
52
- "sass": "^1.5.0"
58
+ "sass": "^1.54.3"
53
59
  }
54
- }
60
+ }
package/dist/parser.js DELETED
@@ -1 +0,0 @@
1
- const picomatch=require("picomatch"),fg=require("fast-glob"),fs=require("fs"),path=require("path");function generatePostcssConfig(t,r){let s={plugins:[]};if(r)r.split(",").forEach(function(e){s.plugins.push(require(e))});else{let e;t!==void 0?e=path.resolve(process.cwd(),t,"postcss.config.js"):e=path.resolve(process.cwd(),"postcss.config.js");try{fs.lstatSync(e),s=require(e)}catch{}}return s}function expandGlob(t,r,s=0,e=[]){if(s<t.length){let c=!1,f=!1,l=!1;if(c=picomatch.scan(t[s]).isGlob,c===!1)try{f=fs.lstatSync(path.normalize(t[s])).isDirectory(),l=fs.lstatSync(path.normalize(t[s])).isFile()}catch(o){throw o}if(c||l){let o=fg.sync(t[s],{dot:!0}).map(i=>path.normalize(i));e.push(...o),s=s+1,expandGlob(t,r,s,e)}else if(f){let o=t[s];fs.readdir(o,(i,n)=>{if(i)throw i;n.forEach(h=>{let a=path.join(o,h);fs.lstatSync(a).isDirectory()||e.push(a)}),s=s+1,expandGlob(t,r,s,e)})}}else r(e)}function createDestination(t,r,s,e,c,f){let l="",o="";return r||(r=""),c||(c=".css"),f===!0?r.length>0?l=r:l="":(s||(s=""),e||(e=""),s.length>0?(e.length>0&&(o=path.dirname(t.replace(path.join(e,"/"),""))),l=path.join(s,o,path.basename(t,path.extname(t))+c)):r.length>0?l=r:l=""),l}exports.expandGlob=expandGlob,exports.createDestination=createDestination,exports.generatePostcssConfig=generatePostcssConfig;