@jamesblanksby/toolkit 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/build/sass.js +32 -44
- package/package.json +1 -1
- package/toolkit.config.js +2 -2
package/build/sass.js
CHANGED
|
@@ -5,72 +5,60 @@ import * as sass from 'sass';
|
|
|
5
5
|
|
|
6
6
|
import { MemoryFile } from './../src/file.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
async function findMainPaths(source) {
|
|
9
|
+
const partialDir = path.dirname(source);
|
|
9
10
|
|
|
10
|
-
async function
|
|
11
|
-
const partialDir = path.dirname(partialPath);
|
|
12
|
-
|
|
13
|
-
async function findMainPathRec(directory) {
|
|
11
|
+
async function findMainPathsRec(directory, matches = []) {
|
|
14
12
|
const files = await fs.readdir(directory);
|
|
15
13
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const matchedFiles = files.filter((file) => !file.startsWith('_') && file.endsWith('.scss'));
|
|
15
|
+
const fullPaths = matchedFiles.map((file) => path.join(directory, file));
|
|
16
|
+
|
|
17
|
+
matches.push(...fullPaths);
|
|
20
18
|
|
|
21
19
|
const parentDir = path.dirname(directory);
|
|
22
20
|
if (parentDir !== directory) {
|
|
23
|
-
return
|
|
21
|
+
return findMainPathsRec(parentDir, matches);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
return
|
|
24
|
+
return matches;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function createCssFile(css, target) {
|
|
33
|
-
return new MemoryFile(target, css);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function createMapFile(map, target) {
|
|
37
|
-
const sassDir = path.resolve(sassPath, './../..');
|
|
38
|
-
|
|
39
|
-
map.sources = map.sources.map((source) => source.replace(`file://${sassDir}`, '..'));
|
|
40
|
-
|
|
41
|
-
await fs.writeFile(target, JSON.stringify(map));
|
|
27
|
+
return findMainPathsRec(partialDir);
|
|
42
28
|
}
|
|
43
29
|
|
|
44
|
-
async function
|
|
45
|
-
const
|
|
30
|
+
async function createCssAndMapFile(css, map, source) {
|
|
31
|
+
const cssPath = source.replace(/sass|scss/g, 'css');
|
|
32
|
+
const mapPath = `${cssPath}.map`;
|
|
33
|
+
const mapName = path.basename(mapPath);
|
|
46
34
|
|
|
47
|
-
file =
|
|
48
|
-
|
|
49
|
-
file = new MemoryFile(file.path, [
|
|
50
|
-
file.contents,
|
|
35
|
+
const file = new MemoryFile(cssPath, [
|
|
36
|
+
css,
|
|
51
37
|
`/*# sourceMappingURL=${mapName} */`,
|
|
52
38
|
].join('\n'));
|
|
53
39
|
|
|
40
|
+
const sassDir = path.resolve(source, './../..');
|
|
41
|
+
map.sources = map.sources.map((source) => source.replace(`file://${sassDir}`, '..'));
|
|
42
|
+
|
|
43
|
+
await fs.writeFile(mapPath, JSON.stringify(map));
|
|
44
|
+
|
|
54
45
|
return file;
|
|
55
46
|
}
|
|
56
47
|
|
|
48
|
+
|
|
57
49
|
export default async function* sassCompile(files) {
|
|
58
50
|
for await (const file of files) {
|
|
59
|
-
|
|
51
|
+
const sassPaths = await findMainPaths(file.path);
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const cssPath = sassPath.replace(/sass|scss/g, 'css');
|
|
69
|
-
let cssFile = createCssFile(result.css, cssPath);
|
|
53
|
+
for (const sassPath of sassPaths) {
|
|
54
|
+
let result;
|
|
55
|
+
try {
|
|
56
|
+
result = sass.compile(sassPath, { sourceMap: true, });
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new Error(error.message);
|
|
59
|
+
}
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
yield await createCssFileWithMap(cssFile, mapPath);
|
|
61
|
+
yield await createCssAndMapFile(result.css, result.sourceMap, sassPath);
|
|
62
|
+
}
|
|
75
63
|
}
|
|
76
64
|
}
|
package/package.json
CHANGED
package/toolkit.config.js
CHANGED
|
@@ -13,8 +13,8 @@ const { PWD, } = process.env;
|
|
|
13
13
|
const pattern = {
|
|
14
14
|
html: `${PWD}/**/*.{html,php}`,
|
|
15
15
|
sass: `${PWD}/**/{sass,scss}/**/*.{sass,scss}`,
|
|
16
|
-
css: `${PWD}/**/css
|
|
17
|
-
script: `${PWD}/**/script
|
|
16
|
+
css: `${PWD}/**/css/**/*.css`,
|
|
17
|
+
script: `${PWD}/**/script/**/*.js`,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
function sync() {
|