sheetloaf 1.2.0 → 1.3.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 +39 -8
- package/dist/sources.js +41 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -46,11 +46,12 @@ const postcss_1 = __importDefault(require("postcss"));
|
|
|
46
46
|
const configs = __importStar(require("./configs"));
|
|
47
47
|
const fileFinder = __importStar(require("./fileFinder"));
|
|
48
48
|
const sheetloaf = new commander_1.Command();
|
|
49
|
-
sheetloaf.version("1.
|
|
49
|
+
sheetloaf.version("1.3.0", '-v, --version', 'Print the version of Sheetloaf.');
|
|
50
50
|
let usingStdin = false;
|
|
51
51
|
let postcssConfig = {
|
|
52
52
|
plugins: []
|
|
53
53
|
};
|
|
54
|
+
let sourcesChecker = [];
|
|
54
55
|
sheetloaf
|
|
55
56
|
.arguments('[sources...]')
|
|
56
57
|
.description('📃🍞 Compile Sass to CSS and transform the output using PostCSS, all in one command.')
|
|
@@ -108,6 +109,25 @@ function renderAllFiles(source) {
|
|
|
108
109
|
});
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
function renderPartially(source, fileName) {
|
|
113
|
+
if (path_1.default.basename(fileName).charAt(0) !== '_') {
|
|
114
|
+
renderSass(fileName);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
let partialExistsInSassSources = false;
|
|
118
|
+
for (let i = 0; i < sourcesChecker.length; i++) {
|
|
119
|
+
if (sourcesChecker[i].containsPartial(fileName)) {
|
|
120
|
+
partialExistsInSassSources = true;
|
|
121
|
+
renderSass(sourcesChecker[i].getMain());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (partialExistsInSassSources === false) {
|
|
125
|
+
console.log(fileName);
|
|
126
|
+
sourcesChecker.splice(0, sourcesChecker.length);
|
|
127
|
+
renderAllFiles(source);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
111
131
|
function watch(source) {
|
|
112
132
|
if (sheetloaf.opts().watch === true) {
|
|
113
133
|
chokidar_1.default
|
|
@@ -122,30 +142,31 @@ function watch(source) {
|
|
|
122
142
|
})
|
|
123
143
|
.on('change', (changed) => {
|
|
124
144
|
console.log(`File changed: ${changed}`);
|
|
125
|
-
|
|
145
|
+
renderPartially(source, changed);
|
|
126
146
|
})
|
|
127
147
|
.on('add', (added) => {
|
|
128
148
|
console.log(`File added: ${added}`);
|
|
149
|
+
sourcesChecker.splice(0, sourcesChecker.length);
|
|
129
150
|
renderAllFiles(source);
|
|
130
151
|
});
|
|
131
152
|
}
|
|
132
153
|
}
|
|
133
154
|
function renderSass(fileName) {
|
|
134
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
|
|
136
|
-
console.log(`Rendering ${fileName}...`);
|
|
137
|
-
}
|
|
156
|
+
console.log(`Rendering ${fileName}...`);
|
|
138
157
|
const destination = fileFinder.buildDestinationPath(fileName, sheetloaf.opts().output, sheetloaf.opts().dir, sheetloaf.opts().base, sheetloaf.opts().ext, usingStdin);
|
|
139
158
|
try {
|
|
140
159
|
if (sheetloaf.opts().async === true) {
|
|
141
160
|
const options = configs.generateSassOptionsAsync(sheetloaf.opts());
|
|
142
161
|
const result = yield sass_1.default.compileAsync(fileName, options);
|
|
143
162
|
renderPost(fileName, destination, result);
|
|
163
|
+
addResultToSourcesChecker(fileName, result);
|
|
144
164
|
}
|
|
145
165
|
else {
|
|
146
166
|
const options = configs.generateSassOptions(sheetloaf.opts());
|
|
147
167
|
const result = sass_1.default.compile(fileName, options);
|
|
148
168
|
renderPost(fileName, destination, result);
|
|
169
|
+
addResultToSourcesChecker(fileName, result);
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
172
|
catch (e) {
|
|
@@ -205,9 +226,12 @@ function renderPost(fileName, destination, sassResult) {
|
|
|
205
226
|
throw err;
|
|
206
227
|
}
|
|
207
228
|
fs_1.default.writeFile(destination, postedResult.css, (err) => {
|
|
208
|
-
if (err)
|
|
209
|
-
|
|
210
|
-
|
|
229
|
+
if (err) {
|
|
230
|
+
console.log(err);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
console.log(picocolors_1.default.green(`Successfully written to ${destination}`));
|
|
234
|
+
}
|
|
211
235
|
});
|
|
212
236
|
if (postedResult.map) {
|
|
213
237
|
fs_1.default.writeFile(destination + '.map', postedResult.map.toString(), (err) => {
|
|
@@ -284,3 +308,10 @@ function emitSassError(err) {
|
|
|
284
308
|
`;
|
|
285
309
|
return css;
|
|
286
310
|
}
|
|
311
|
+
function addResultToSourcesChecker(fileName, result) {
|
|
312
|
+
for (let i = 0; i < sourcesChecker.length; i++) {
|
|
313
|
+
if (sourcesChecker[i].getAbsoluteMain() === path_1.default.resolve(fileName)) {
|
|
314
|
+
sourcesChecker[i].setSources(result.loadedUrls);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
package/dist/sources.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
this.setSources(sassResult.loadedUrls);
|
|
14
|
+
}
|
|
15
|
+
setSources(urls) {
|
|
16
|
+
this.sources.splice(0, this.sources.length);
|
|
17
|
+
urls.forEach(url => {
|
|
18
|
+
if (url.pathname !== this.absoluteMain) {
|
|
19
|
+
this.sources.push(url.pathname);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
containsPartial(filename) {
|
|
24
|
+
if (this.sources.indexOf(path_1.default.resolve(filename)) >= 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getSources() {
|
|
32
|
+
return this.sources;
|
|
33
|
+
}
|
|
34
|
+
getAbsoluteMain() {
|
|
35
|
+
return this.absoluteMain;
|
|
36
|
+
}
|
|
37
|
+
getMain() {
|
|
38
|
+
return this.main;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
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",
|
|
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
|
},
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"fast-glob": "^3.2.11",
|
|
55
55
|
"picocolors": "^1.0.0",
|
|
56
56
|
"picomatch": "^2.3.1",
|
|
57
|
-
"sass": "^1.54.
|
|
57
|
+
"sass": "^1.54.4"
|
|
58
58
|
}
|
|
59
59
|
}
|