chisel-scripts 2.0.0-alpha.1 → 2.0.0-alpha.3.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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  <!-- INSERT-NEW-ENTRIES-HERE -->
4
4
 
5
+ ## 2.0.0-alpha.3.1 (2024-10-31)
6
+
7
+ - add assets index ([fed4fd3](https://github.com/xfiveco/generator-chisel/commit/fed4fd3))
8
+
9
+ ## 2.0.0-alpha.3.0 (2024-10-07)
10
+
11
+ - update chisel-scripts version ([2957e4c](https://github.com/xfiveco/generator-chisel/commit/2957e4c))
12
+
13
+ ## 2.0.0-alpha.2 (2024-10-07)
14
+
15
+ - fix styles file watching on mac ([d2cfca8](https://github.com/xfiveco/generator-chisel/commit/d2cfca8))
16
+
5
17
  ## 2.0.0-alpha.1 (2024-09-10)
6
18
 
7
19
  - copy twig files ([67ff991](https://github.com/xfiveco/generator-chisel/commit/67ff991))
package/composer.phar CHANGED
Binary file
@@ -0,0 +1,68 @@
1
+ import { relative, join } from 'path';
2
+ import { relative as relativePosix } from 'path/posix';
3
+ import fastGlob from 'fast-glob';
4
+ import fs from 'fs/promises';
5
+ import { createHash } from 'crypto';
6
+ import json2php from 'json2php';
7
+
8
+ const { convertPathToPattern } = fastGlob;
9
+
10
+ const hashesCache = {};
11
+
12
+ export const build = async (api, { fromWatch = false } = {}) => {
13
+ const assetsDir = api.resolve('assets');
14
+ const assetsDirPattern = convertPathToPattern(assetsDir);
15
+ const pattern = assetsDirPattern + '/**';
16
+ const files = (
17
+ await fastGlob(pattern, {
18
+ onlyFiles: true,
19
+ stats: true,
20
+ })
21
+ ).sort((a, b) => a.path.localeCompare(b.path));
22
+ const hashesFile = join(assetsDir, 'hashes.php');
23
+ const hashesFilePattern = convertPathToPattern(hashesFile);
24
+
25
+ const hashes = {};
26
+
27
+ for (const file of files) {
28
+ if (file.path === hashesFilePattern) continue;
29
+
30
+ const id = `${file.path}-${file.stats.size}-${file.stats.mtimeMs}`;
31
+ const key = convertPathToPattern(relative(assetsDirPattern, file.path));
32
+
33
+ if (fromWatch) {
34
+ if (hashesCache[id]) {
35
+ hashes[key] = hashesCache[id];
36
+ continue;
37
+ }
38
+ }
39
+
40
+ const content = await fs.readFile(file.path);
41
+ const hash = createHash('md5').update(content).digest('hex');
42
+ hashes[key] = hash;
43
+ hashesCache[id] = hash;
44
+ }
45
+
46
+ const phpArray = json2php.make({ indent: ' ', linebreak: '\n' })(hashes);
47
+ const content = `<?php return ${phpArray};\n`;
48
+ await fs.writeFile(hashesFile, content);
49
+ };
50
+
51
+ export const start = async (api) => {
52
+ const { default: chokidar } = await import('chokidar');
53
+
54
+ const assetsDir = api.resolve('assets');
55
+ const hashesFile = join(assetsDir, 'hashes.php');
56
+ const pattern = convertPathToPattern(assetsDir);
57
+
58
+ const watcher = chokidar.watch(pattern, {
59
+ ignoreInitial: true,
60
+ awaitWriteFinish: true,
61
+ });
62
+ watcher.on('add', () => build(api, { fromWatch: true }));
63
+ watcher.on('unlink', () => build(api, { fromWatch: true }));
64
+ watcher.on('change', (file) => {
65
+ if (file === hashesFile) return;
66
+ build(api, { fromWatch: true });
67
+ });
68
+ };
@@ -42,8 +42,7 @@ export const start = async (api) => {
42
42
  const stylesDir = api.resolve('src/styles');
43
43
  const pattern = convertPathToPattern(stylesDir) + '/*/**/*.scss';
44
44
 
45
- const watcher = chokidar.watch(convertPathToPattern(pattern), {
46
- persistent: false,
45
+ const watcher = chokidar.watch(pattern, {
47
46
  ignoreInitial: true,
48
47
  });
49
48
  watcher.on('add', () => build(api));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chisel-scripts",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3.1",
4
4
  "description": "TODO",
5
5
  "bin": {
6
6
  "chisel-scripts": "bin/chisel-scripts.js"
@@ -32,10 +32,11 @@
32
32
  "fs-extra": "^9.0.1",
33
33
  "globby": "^11.0.1",
34
34
  "inquirer": "^7.1.0",
35
+ "json2php": "^0.0.9",
35
36
  "lodash": "^4.17.15"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "@wordpress/scripts": "^27.9.0"
39
40
  },
40
- "gitHead": "dc7eef31741ec96dfa1b73a9bb6b2b9e05d79908"
41
+ "gitHead": "92466fd4d8e4a29e588345c304f5040d428b567a"
41
42
  }