@tenjuu99/blog 0.2.17 → 0.2.19

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/lib/dir.js CHANGED
@@ -114,7 +114,8 @@ watchers.push({
114
114
  },
115
115
  watchOptions: {
116
116
  ignoreInitial: true
117
- }
117
+ },
118
+ prior: true,
118
119
  })
119
120
  export {
120
121
  rootDir,
package/lib/distribute.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict"
2
2
  import fs from "node:fs/promises";
3
- import { existsSync, mkdirSync } from "node:fs";
3
+ import { existsSync, mkdirSync, cpSync } from "node:fs";
4
4
  import path from 'path'
5
5
  import { minifyHtml } from './minify.js'
6
6
  import render from './render.js'
@@ -41,13 +41,8 @@ const distribute = async (data, srcDir, distDir) => {
41
41
  if (!existsSync(`${cacheDir}/${copyDir}`)) {
42
42
  return
43
43
  }
44
- fs.readdir(`${cacheDir}/${copyDir}/`).then(async files => {
45
- await fs.stat(`${distDir}/${copyDir}/`).catch(async err => await fs.mkdir(`${distDir}/${copyDir}/`))
46
- files.forEach(file => {
47
- fs.copyFile(`${cacheDir}/${copyDir}/${file}`, `${distDir}/${copyDir}/${file}`)
48
- console.log(styleText('green', '[copy]'), `${cacheDir}/${copyDir}/${file} => ${distDir}/${copyDir}/${file}`)
49
- })
50
- })
44
+ cpSync(`${cacheDir}/${copyDir}/`, `${distDir}/${copyDir}/`, { recursive: true, force: true })
45
+ console.log(styleText('green', '[copy]'), `${cacheDir}/${copyDir}/ => ${distDir}/${copyDir}/`)
51
46
  })
52
47
 
53
48
  if (!existsSync(cacheDir)) {
package/lib/watcher.js CHANGED
@@ -1,18 +1,23 @@
1
1
  import chokidar from 'chokidar'
2
2
 
3
3
  const container = []
4
+ const containerPrior = []
4
5
 
5
6
  const watchers = {
6
- push({ paths, event = 'change', callback, watchOptions }) {
7
+ push({ paths, event = 'change', callback, watchOptions, prior = false }) {
7
8
  if (!paths || !callback || typeof callback !== 'function') {
8
9
  throw new Error('Invalid object type for watcher.')
9
10
  }
10
- container.push({ paths, event, callback, watchOptions })
11
+ if (prior) {
12
+ containerPrior.push({ paths, event, callback, watchOptions })
13
+ } else {
14
+ container.push({ paths, event, callback, watchOptions })
15
+ }
11
16
  }
12
17
  }
13
18
 
14
19
  const watch = () => {
15
- container.forEach((watcher) => {
20
+ const callback = (watcher) => {
16
21
  const { paths, event, callback, watchOptions } = watcher
17
22
  const cwatcher = chokidar.watch(paths, watchOptions)
18
23
  if (Array.isArray(event)) {
@@ -22,7 +27,9 @@ const watch = () => {
22
27
  } else {
23
28
  throw new Error('Invalid event for watcher.')
24
29
  }
25
- })
30
+ }
31
+ containerPrior.forEach(callback)
32
+ container.forEach(callback)
26
33
  }
27
34
 
28
35
  export { watchers , watch }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {