@jamesblanksby/toolkit 1.2.0 → 1.4.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 CHANGED
@@ -1,76 +1,69 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
+ import url from 'url';
3
4
 
4
5
  import * as sass from 'sass';
5
6
 
6
7
  import { MemoryFile } from './../src/file.js';
7
8
 
8
- let sassPath = null;
9
+ async function findMainPaths(source) {
10
+ const partialDir = path.dirname(source);
9
11
 
10
- async function findMainPath(partialPath) {
11
- const partialDir = path.dirname(partialPath);
12
-
13
- async function findMainPathRec(directory) {
12
+ async function findMainPathsRec(directory, matches = []) {
14
13
  const files = await fs.readdir(directory);
15
14
 
16
- const mainPath = files.find((file) => !file.startsWith('_') && file.endsWith('.scss'));
17
- if (mainPath) {
18
- return path.join(directory, mainPath);
19
- }
15
+ const matchedFiles = files.filter((file) => !file.startsWith('_') && file.endsWith('.scss'));
16
+ const fullPaths = matchedFiles.map((file) => path.join(directory, file));
17
+
18
+ matches.push(...fullPaths);
20
19
 
21
20
  const parentDir = path.dirname(directory);
22
21
  if (parentDir !== directory) {
23
- return findMainPathRec(parentDir);
22
+ return findMainPathsRec(parentDir, matches);
24
23
  }
25
24
 
26
- return null;
25
+ return matches;
27
26
  }
28
27
 
29
- return findMainPathRec(partialDir);
28
+ return findMainPathsRec(partialDir);
30
29
  }
31
30
 
32
- function createCssFile(css, target) {
33
- return new MemoryFile(target, css);
34
- }
31
+ async function createCssAndMapFile(css, map, source) {
32
+ const cssPath = source.replace(/sass|scss/g, 'css');
33
+ const mapPath = `${cssPath}.map`;
34
+ const mapName = path.basename(mapPath);
35
35
 
36
- async function createMapFile(map, target) {
37
- const sassDir = path.resolve(sassPath, './../..');
36
+ const file = new MemoryFile(cssPath, [
37
+ css,
38
+ `/*# sourceMappingURL=${mapName} */`,
39
+ ].join('\n'));
38
40
 
41
+ const sassDir = path.resolve(source, './../..');
39
42
  map.sources = map.sources.map((source) => source.replace(`file://${sassDir}`, '..'));
40
43
 
41
- await fs.writeFile(target, JSON.stringify(map));
42
- }
43
-
44
- async function createCssFileWithMap(file, source) {
45
- const mapName = path.basename(source);
46
-
47
- file = await file.read();
48
-
49
- file = new MemoryFile(file.path, [
50
- file.contents,
51
- `/*# sourceMappingURL=${mapName} */`,
52
- ].join('\n'));
44
+ await fs.writeFile(mapPath, JSON.stringify(map));
53
45
 
54
46
  return file;
55
47
  }
56
48
 
57
49
  export default async function* sassCompile(files) {
58
50
  for await (const file of files) {
59
- sassPath = await findMainPath(file.path);
60
-
61
- let result;
62
- try {
63
- result = sass.compile(sassPath, { sourceMap: true, });
64
- } catch (error) {
65
- throw error.message;
51
+ const sassPaths = await findMainPaths(file.path);
52
+
53
+ const modulesDir = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), './../../..');
54
+
55
+ for (const sassPath of sassPaths) {
56
+ let result;
57
+ try {
58
+ result = sass.compile(sassPath, {
59
+ loadPaths: [modulesDir,],
60
+ sourceMap: true,
61
+ });
62
+ } catch (error) {
63
+ throw new Error(error.message);
64
+ }
65
+
66
+ yield await createCssAndMapFile(result.css, result.sourceMap, sassPath);
66
67
  }
67
-
68
- const cssPath = sassPath.replace(/sass|scss/g, 'css');
69
- let cssFile = createCssFile(result.css, cssPath);
70
-
71
- const mapPath = `${cssPath}.map`;
72
- await createMapFile(result.sourceMap, mapPath);
73
-
74
- yield await createCssFileWithMap(cssFile, mapPath);
75
68
  }
76
69
  }
package/build/script.js CHANGED
@@ -6,11 +6,14 @@ import uglifyjs from 'uglify-js';
6
6
 
7
7
  import { MemoryFile } from './../src/file.js';
8
8
 
9
+ const { PWD, } = process.env;
10
+
9
11
  async function scriptLint(files) {
10
12
  const configDir = path.dirname(url.fileURLToPath(import.meta.url));
11
13
 
12
14
  const eslint = new ESLint({
13
- overrideConfigFile: `${configDir}/../.eslintrc.json`,
15
+ cwd: PWD,
16
+ overrideConfigFile: `${configDir}/../eslint.config.mjs`,
14
17
  });
15
18
 
16
19
  let results = [];
@@ -19,7 +22,7 @@ async function scriptLint(files) {
19
22
  file = await file.read();
20
23
 
21
24
  const fileResult = await eslint.lintText(file.contents, { filePath: file.path, });
22
- results = results.concat(fileResult);
25
+ results.push(...fileResult);
23
26
  }
24
27
 
25
28
  const formatter = await eslint.loadFormatter();
@@ -0,0 +1,36 @@
1
+ import globals from 'globals';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import js from '@eslint/js';
5
+ import { FlatCompat } from '@eslint/eslintrc';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const compat = new FlatCompat({
10
+ baseDirectory: __dirname,
11
+ recommendedConfig: js.configs.recommended,
12
+ allConfig: js.configs.all
13
+ });
14
+
15
+ export default [...compat.extends('eslint:recommended'), {
16
+ ignores: [
17
+ 'node_modules/*',
18
+ ],
19
+
20
+ languageOptions: {
21
+ globals: {
22
+ ...globals.browser,
23
+ ...globals.jquery,
24
+ ...globals.node,
25
+ },
26
+
27
+ ecmaVersion: 'latest',
28
+ sourceType: 'module',
29
+ },
30
+
31
+ rules: {
32
+ 'no-async-promise-executor': 'off',
33
+ 'no-empty': 'off',
34
+ 'no-unused-vars': 'warn',
35
+ },
36
+ }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesblanksby/toolkit",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
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/*.css`,
17
- script: `${PWD}/**/script/*.js`,
16
+ css: `${PWD}/**/css/**/*.css`,
17
+ script: `${PWD}/**/script/**/*.js`,
18
18
  };
19
19
 
20
20
  function sync() {
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true,
5
- "jquery": true,
6
- "node": true
7
- },
8
- "extends": "eslint:recommended",
9
- "parserOptions": {
10
- "ecmaVersion": "latest",
11
- "sourceType": "module"
12
- },
13
- "rules": {
14
- "no-async-promise-executor": "off",
15
- "no-empty": "off",
16
- "no-unused-vars": "warn"
17
- }
18
- }