@tenjuu99/blog 0.2.32 → 0.2.34

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,9 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from 'child_process'
4
- import { srcDir, watch as watchDir, packageDir, packageDirCore, watchCallback } from '../lib/dir.js'
4
+ import { srcDir, watch as watchDir, packageDir, packageDirCore } from '../lib/dir.js'
5
5
  import { watchers, watch } from '../lib/watcher.js'
6
- import generate from '../lib/generate.js'
7
6
  import path from 'path'
8
7
  import { fileURLToPath } from 'url';
9
8
 
@@ -12,23 +11,15 @@ const libDir = path.dirname(__filename) + '/../lib/'
12
11
  const binDir = path.dirname(__filename) + '/../bin/'
13
12
 
14
13
  watchers.push({
15
- paths: [srcDir],
14
+ paths: [srcDir, libDir, packageDirCore],
16
15
  event: ['change', 'add', 'unlink'],
17
- callback: (path) => {
18
- watchCallback(path)
19
- generate()
20
- },
21
- watchOptions: {
22
- ignoreInitial: true
23
- },
24
- prior: true,
25
- })
26
- watchers.push({
27
- paths: [watchDir.serverDir, watchDir.helperDir, libDir, packageDir, packageDirCore],
28
- callback: () => {
16
+ callback: async (path) => {
29
17
  childProcess.kill('SIGINT')
30
18
  childProcess = proceed()
31
19
  console.error('restarting')
20
+ },
21
+ watchOptions: {
22
+ ignoreInitial: true
32
23
  }
33
24
  })
34
25
  watch()
@@ -1,11 +1,10 @@
1
1
  "use strict"
2
2
  import applyCss from './cssGenerator.js'
3
3
  import includeFilter from './includeFilter.js'
4
- import { watch } from './dir.js'
5
- import { staticFile, staticFiles, warmUp, reload } from './files.js'
6
- import { watchers } from './watcher.js'
4
+ import { staticFile, staticFiles, warmUp } from './files.js'
7
5
 
8
6
  let templates = {}
7
+ let loaded = false
9
8
 
10
9
  const applyTemplate = async (name = 'default.html') => {
11
10
  if (templates[name]) {
@@ -19,20 +18,17 @@ const applyTemplate = async (name = 'default.html') => {
19
18
  }
20
19
 
21
20
  const warmUpTemplate = async () => {
21
+ if (loaded) {
22
+ console.log('template is already warmed up.')
23
+ return
24
+ }
25
+ console.log('warming up template')
22
26
  await warmUp()
23
27
  const templates = staticFiles()
24
28
  .filter(file => file[0].indexOf('template/') === 0)
25
29
  .map(f => applyTemplate(f[0].split('/')[1]))
26
30
  await Promise.all(templates)
31
+ loaded = true
27
32
  }
28
33
 
29
- watchers.push({
30
- paths: [watch.cssDir, watch.templateDir],
31
- callback: async () => {
32
- templates = {}
33
- await reload()
34
- await warmUpTemplate()
35
- }
36
- })
37
-
38
34
  export { applyTemplate, warmUpTemplate }
@@ -4,8 +4,7 @@ import { staticFile } from './files.js'
4
4
  import { minifyCss } from './minify.js'
5
5
  import { createHash } from 'crypto'
6
6
  import path from 'path'
7
- import { distDir, watch } from './dir.js'
8
- import { watchers } from './watcher.js'
7
+ import { distDir } from './dir.js'
9
8
  import { styleText } from 'node:util'
10
9
  import config from './config.js'
11
10
 
@@ -62,9 +61,4 @@ const applyCss = async (text) => {
62
61
  return text
63
62
  }
64
63
 
65
- watchers.push({
66
- paths: watch.cssDir,
67
- callback: () => { cacheBuster = {} }
68
- })
69
-
70
64
  export default applyCss
package/lib/dir.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import config from './config.js'
2
- import { watchers } from './watcher.js'
3
2
  import fs from 'node:fs'
4
3
  import { styleText } from 'node:util'
5
4
  import path from 'path'
@@ -64,58 +63,6 @@ const cache = () => {
64
63
  // generate の中でもコールしているが、同一プロセスであれば alreadyCached 変数で制御される
65
64
  cache()
66
65
 
67
- let packageDirectoriesLoaded = []
68
- const packageDirectories = () => {
69
- if (packageDirectoriesLoaded.length > 0) {
70
- return packageDirectoriesLoaded
71
- }
72
- const watchTargetDir = ['pages', 'template', 'css', 'helper', 'server', 'js']
73
- const packages = config.packages.split(',').reduce((prev, packageName) => {
74
- if (fs.existsSync(`${packageDir}/${packageName}`)) {
75
- prev.push(fs.realpathSync(`${packageDir}/${packageName}`))
76
- }
77
- prev.push(fs.realpathSync(`${packageDirCore}/${packageName}`))
78
- return prev
79
- }, [srcDir])
80
-
81
- for (const baseDir of packages) {
82
- for (const target of watchTargetDir) {
83
- if (!fs.existsSync(`${baseDir}/${target}`)) {
84
- continue;
85
- }
86
- const targetDir = `${baseDir}/${target}`
87
- packageDirectoriesLoaded.push(targetDir)
88
- }
89
- }
90
- return packageDirectoriesLoaded
91
- }
92
-
93
- const resolveDestinationPath = (path) => {
94
- for (const targetDir of packageDirectories()) {
95
- if (path.startsWith(targetDir)) {
96
- const dir = targetDir.split('/').pop()
97
- const srcFile = `${dir}${path.replace(targetDir, '')}`
98
- return `${cacheDir}/${srcFile}`
99
- }
100
- }
101
- }
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
-
119
66
  export {
120
67
  rootDir,
121
68
  srcDir,
@@ -129,6 +76,5 @@ export {
129
76
  watch,
130
77
  cache,
131
78
  packageDir,
132
- packageDirCore,
133
- watchCallback
79
+ packageDirCore
134
80
  }
package/lib/distribute.js CHANGED
@@ -7,7 +7,7 @@ import render from './render.js'
7
7
  import { styleText } from 'node:util'
8
8
  import config from './config.js'
9
9
  import { cacheDir } from './dir.js'
10
- import { applyTemplate, warmUpTemplate } from './applyTemplate.js'
10
+ import { applyTemplate } from './applyTemplate.js'
11
11
 
12
12
  const indexFile = `${cacheDir}/index.json`
13
13
 
@@ -17,7 +17,6 @@ const renderPage = async (page) => {
17
17
  }
18
18
 
19
19
  const distribute = async (data, srcDir, distDir) => {
20
- await warmUpTemplate()
21
20
  const promises = []
22
21
  const newIndex = []
23
22
  for (const name in data) {
package/lib/files.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import fs from "node:fs/promises";
2
- import { templateDir, cssDir, watch } from './dir.js'
3
- import { watchers } from './watcher.js'
2
+ import { templateDir, cssDir } from './dir.js'
4
3
 
5
4
  let staticFilesContainer = {}
6
5
  let loaded = false
@@ -32,9 +31,4 @@ const staticFile = (name) => {
32
31
  const staticFiles = () => {
33
32
  return Object.entries(staticFilesContainer)
34
33
  }
35
- const reload = async () => {
36
- loaded = false
37
- return await warmUp()
38
- }
39
-
40
- export { staticFile, staticFiles, warmUp, reload }
34
+ export { staticFile, staticFiles, warmUp }
package/lib/generate.js CHANGED
@@ -2,11 +2,16 @@
2
2
  import distribute from './distribute.js'
3
3
  import { indexing, allData } from './indexer.js'
4
4
  import { srcDir, distDir, cache } from './dir.js'
5
+ import { warmUpTemplate } from './applyTemplate.js'
5
6
  import { styleText } from 'node:util'
6
7
 
8
+ const beforeGenerate = async () => {
9
+ cache()
10
+ await warmUpTemplate()
11
+ }
7
12
  const generate = async () => {
8
13
  let start = performance.now()
9
- cache()
14
+ await beforeGenerate()
10
15
  await indexing()
11
16
  let end = performance.now()
12
17
  console.log(styleText('blue', '[indexing: ' + (end - start) + "ms]"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {