@tenjuu99/blog 0.2.30 → 0.2.32

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/bin/dev-server CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from 'child_process'
4
- import { srcDir, watch as watchDir, packageDir, packageDirCore } from '../lib/dir.js'
4
+ import { srcDir, watch as watchDir, packageDir, packageDirCore, watchCallback } from '../lib/dir.js'
5
5
  import { watchers, watch } from '../lib/watcher.js'
6
6
  import generate from '../lib/generate.js'
7
7
  import path from 'path'
@@ -12,19 +12,16 @@ const libDir = path.dirname(__filename) + '/../lib/'
12
12
  const binDir = path.dirname(__filename) + '/../bin/'
13
13
 
14
14
  watchers.push({
15
- paths: srcDir,
16
- watchOptions: {
17
- ignored: [watchDir.pageDir, watchDir.serverDir, watchDir.helperDir],
15
+ paths: [srcDir],
16
+ event: ['change', 'add', 'unlink'],
17
+ callback: (path) => {
18
+ watchCallback(path)
19
+ generate()
18
20
  },
19
- callback: generate
20
- })
21
- watchers.push({
22
- paths: watchDir.pageDir,
23
- callback: generate,
24
21
  watchOptions: {
25
22
  ignoreInitial: true
26
23
  },
27
- event: ['change', 'unlink', 'add']
24
+ prior: true,
28
25
  })
29
26
  watchers.push({
30
27
  paths: [watchDir.serverDir, watchDir.helperDir, libDir, packageDir, packageDirCore],
@@ -2,7 +2,7 @@
2
2
  import applyCss from './cssGenerator.js'
3
3
  import includeFilter from './includeFilter.js'
4
4
  import { watch } from './dir.js'
5
- import { staticFile, staticFiles, warmUp } from './files.js'
5
+ import { staticFile, staticFiles, warmUp, reload } from './files.js'
6
6
  import { watchers } from './watcher.js'
7
7
 
8
8
  let templates = {}
@@ -28,7 +28,11 @@ const warmUpTemplate = async () => {
28
28
 
29
29
  watchers.push({
30
30
  paths: [watch.cssDir, watch.templateDir],
31
- callback: () => { templates = {} }
31
+ callback: async () => {
32
+ templates = {}
33
+ await reload()
34
+ await warmUpTemplate()
35
+ }
32
36
  })
33
37
 
34
38
  export { applyTemplate, warmUpTemplate }
package/lib/dir.js CHANGED
@@ -99,30 +99,23 @@ const resolveDestinationPath = (path) => {
99
99
  }
100
100
  }
101
101
  }
102
- watchers.push({
103
- paths: [srcDir, packageDir, packageDirCore],
104
- event: ['change', 'add', 'unlink'],
105
- callback: ( path ) => {
106
- const dest = resolveDestinationPath(path)
107
- if (!dest) {
108
- console.log(styleText('red', `[watcher] cannot resolve destination path: ${path}`))
109
- alreadyCached = false
110
- cache()
111
- return true
112
- }
113
- if (fs.existsSync(path)) {
114
- fs.cpSync(path, dest, { force: true })
115
- console.log(styleText('blue', `update ${path} => ${dest}`))
116
- } else {
117
- fs.unlinkSync(dest)
118
- console.log(styleText('red', `unlink ${dest}`))
119
- }
120
- },
121
- watchOptions: {
122
- ignoreInitial: true
123
- },
124
- prior: true,
125
- })
102
+ const watchCallback = ( path ) => {
103
+ const dest = resolveDestinationPath(path)
104
+ if (!dest) {
105
+ console.log(styleText('red', `[watcher] cannot resolve destination path: ${path}`))
106
+ alreadyCached = false
107
+ cache()
108
+ return true
109
+ }
110
+ if (fs.existsSync(path)) {
111
+ fs.cpSync(path, dest, { force: true })
112
+ console.log(styleText('blue', `update ${path} => ${dest}`))
113
+ } else {
114
+ fs.unlinkSync(dest)
115
+ console.log(styleText('red', `unlink ${dest}`))
116
+ }
117
+ }
118
+
126
119
  export {
127
120
  rootDir,
128
121
  srcDir,
@@ -136,5 +129,6 @@ export {
136
129
  watch,
137
130
  cache,
138
131
  packageDir,
139
- packageDirCore
132
+ packageDirCore,
133
+ watchCallback
140
134
  }
package/lib/files.js CHANGED
@@ -32,12 +32,9 @@ const staticFile = (name) => {
32
32
  const staticFiles = () => {
33
33
  return Object.entries(staticFilesContainer)
34
34
  }
35
- watchers.push({
36
- paths: [watch.cssDir, watch.templateDir],
37
- callback: async () => {
35
+ const reload = async () => {
38
36
  loaded = false
39
- await warmUp()
40
- }
41
- })
37
+ return await warmUp()
38
+ }
42
39
 
43
- export { staticFile, staticFiles, warmUp }
40
+ export { staticFile, staticFiles, warmUp, reload }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {