sheetloaf 1.2.0 → 1.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -8
- package/dist/sources.js +37 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -45,12 +45,14 @@ const sass_1 = __importDefault(require("sass"));
|
|
|
45
45
|
const postcss_1 = __importDefault(require("postcss"));
|
|
46
46
|
const configs = __importStar(require("./configs"));
|
|
47
47
|
const fileFinder = __importStar(require("./fileFinder"));
|
|
48
|
+
const sources = __importStar(require("./sources"));
|
|
48
49
|
const sheetloaf = new commander_1.Command();
|
|
49
|
-
sheetloaf.version("1.
|
|
50
|
+
sheetloaf.version("1.3.0", '-v, --version', 'Print the version of Sheetloaf.');
|
|
50
51
|
let usingStdin = false;
|
|
51
52
|
let postcssConfig = {
|
|
52
53
|
plugins: []
|
|
53
54
|
};
|
|
55
|
+
let sourcesChecker = [];
|
|
54
56
|
sheetloaf
|
|
55
57
|
.arguments('[sources...]')
|
|
56
58
|
.description('📃🍞 Compile Sass to CSS and transform the output using PostCSS, all in one command.')
|
|
@@ -108,6 +110,18 @@ function renderAllFiles(source) {
|
|
|
108
110
|
});
|
|
109
111
|
});
|
|
110
112
|
}
|
|
113
|
+
function renderPartially(fileName) {
|
|
114
|
+
if (path_1.default.basename(fileName).charAt(0) !== '_') {
|
|
115
|
+
renderSass(fileName);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
for (let i = 0; i < sourcesChecker.length; i++) {
|
|
119
|
+
if (sourcesChecker[i].containsPartial(fileName)) {
|
|
120
|
+
renderSass(sourcesChecker[i].getMain());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
111
125
|
function watch(source) {
|
|
112
126
|
if (sheetloaf.opts().watch === true) {
|
|
113
127
|
chokidar_1.default
|
|
@@ -122,30 +136,31 @@ function watch(source) {
|
|
|
122
136
|
})
|
|
123
137
|
.on('change', (changed) => {
|
|
124
138
|
console.log(`File changed: ${changed}`);
|
|
125
|
-
|
|
139
|
+
renderPartially(changed);
|
|
126
140
|
})
|
|
127
141
|
.on('add', (added) => {
|
|
128
142
|
console.log(`File added: ${added}`);
|
|
143
|
+
sourcesChecker.splice(0, sourcesChecker.length);
|
|
129
144
|
renderAllFiles(source);
|
|
130
145
|
});
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
148
|
function renderSass(fileName) {
|
|
134
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
|
|
136
|
-
console.log(`Rendering ${fileName}...`);
|
|
137
|
-
}
|
|
150
|
+
console.log(`Rendering ${fileName}...`);
|
|
138
151
|
const destination = fileFinder.buildDestinationPath(fileName, sheetloaf.opts().output, sheetloaf.opts().dir, sheetloaf.opts().base, sheetloaf.opts().ext, usingStdin);
|
|
139
152
|
try {
|
|
140
153
|
if (sheetloaf.opts().async === true) {
|
|
141
154
|
const options = configs.generateSassOptionsAsync(sheetloaf.opts());
|
|
142
155
|
const result = yield sass_1.default.compileAsync(fileName, options);
|
|
143
156
|
renderPost(fileName, destination, result);
|
|
157
|
+
addResultToSourcesChecker(fileName, result);
|
|
144
158
|
}
|
|
145
159
|
else {
|
|
146
160
|
const options = configs.generateSassOptions(sheetloaf.opts());
|
|
147
161
|
const result = sass_1.default.compile(fileName, options);
|
|
148
162
|
renderPost(fileName, destination, result);
|
|
163
|
+
addResultToSourcesChecker(fileName, result);
|
|
149
164
|
}
|
|
150
165
|
}
|
|
151
166
|
catch (e) {
|
|
@@ -205,9 +220,12 @@ function renderPost(fileName, destination, sassResult) {
|
|
|
205
220
|
throw err;
|
|
206
221
|
}
|
|
207
222
|
fs_1.default.writeFile(destination, postedResult.css, (err) => {
|
|
208
|
-
if (err)
|
|
209
|
-
|
|
210
|
-
|
|
223
|
+
if (err) {
|
|
224
|
+
console.log(err);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
console.log(picocolors_1.default.green(`Successfully written to ${destination}`));
|
|
228
|
+
}
|
|
211
229
|
});
|
|
212
230
|
if (postedResult.map) {
|
|
213
231
|
fs_1.default.writeFile(destination + '.map', postedResult.map.toString(), (err) => {
|
|
@@ -284,3 +302,14 @@ function emitSassError(err) {
|
|
|
284
302
|
`;
|
|
285
303
|
return css;
|
|
286
304
|
}
|
|
305
|
+
function addResultToSourcesChecker(fileName, result) {
|
|
306
|
+
let alreadyExists = false;
|
|
307
|
+
for (let i = 0; i < sourcesChecker.length; i++) {
|
|
308
|
+
if (sourcesChecker[i].getAbsoluteMain() === path_1.default.resolve(fileName)) {
|
|
309
|
+
alreadyExists = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (alreadyExists === false) {
|
|
313
|
+
sourcesChecker.push(new sources.SassSources(fileName, result));
|
|
314
|
+
}
|
|
315
|
+
}
|
package/dist/sources.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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.SassSources = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
class SassSources {
|
|
9
|
+
constructor(filename, sassResult) {
|
|
10
|
+
this.sources = [];
|
|
11
|
+
this.main = filename;
|
|
12
|
+
this.absoluteMain = path_1.default.resolve(filename);
|
|
13
|
+
sassResult.loadedUrls.forEach(url => {
|
|
14
|
+
if (url.pathname !== this.absoluteMain) {
|
|
15
|
+
this.sources.push(url.pathname);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
containsPartial(filename) {
|
|
20
|
+
if (this.sources.indexOf(path_1.default.resolve(filename)) >= 0) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
getSources() {
|
|
28
|
+
return this.sources;
|
|
29
|
+
}
|
|
30
|
+
getAbsoluteMain() {
|
|
31
|
+
return this.absoluteMain;
|
|
32
|
+
}
|
|
33
|
+
getMain() {
|
|
34
|
+
return this.main;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SassSources = SassSources;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sheetloaf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.0",
|
|
4
4
|
"description": "freshmade stylesheets for the whole family.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build:development": "tsc --watch",
|
|
11
11
|
"build:production": "tsc",
|
|
12
12
|
"test": "mocha -r ts-node/register test/*.test.ts",
|
|
13
|
-
"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
|
+
"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 --watch",
|
|
14
14
|
"test3": "cat test/samples/styles/file.scss | node . --style compressed --use autoprefixer --load-path test/samples/styles > test/samples/render/file.css",
|
|
15
15
|
"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"
|
|
16
16
|
},
|