@tenjuu99/blog 0.2.33 → 0.2.35

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,36 +1,25 @@
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
- import { warmUpTemplateCallback } from '../lib/applyTemplate.js'
10
8
 
11
9
  const __filename = fileURLToPath(import.meta.url);
12
10
  const libDir = path.dirname(__filename) + '/../lib/'
13
11
  const binDir = path.dirname(__filename) + '/../bin/'
14
12
 
15
13
  watchers.push({
16
- paths: [srcDir],
14
+ paths: [srcDir, libDir, packageDirCore],
17
15
  event: ['change', 'add', 'unlink'],
18
16
  callback: async (path) => {
19
- watchCallback(path)
20
- await warmUpTemplateCallback()
21
- generate()
22
- },
23
- watchOptions: {
24
- ignoreInitial: true
25
- },
26
- prior: true,
27
- })
28
- watchers.push({
29
- paths: [watchDir.serverDir, watchDir.helperDir, libDir, packageDir, packageDirCore],
30
- callback: () => {
31
17
  childProcess.kill('SIGINT')
32
18
  childProcess = proceed()
33
19
  console.error('restarting')
20
+ },
21
+ watchOptions: {
22
+ ignoreInitial: true
34
23
  }
35
24
  })
36
25
  watch()
@@ -1,9 +1,7 @@
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 = {}
9
7
  let loaded = false
@@ -33,11 +31,4 @@ const warmUpTemplate = async () => {
33
31
  loaded = true
34
32
  }
35
33
 
36
- const warmUpTemplateCallback = async () => {
37
- templates = {}
38
- loaded = false
39
- await reload()
40
- await warmUpTemplate()
41
- }
42
-
43
- export { applyTemplate, warmUpTemplate, warmUpTemplateCallback }
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/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -73,9 +73,6 @@ const transition = async (href) => {
73
73
  script.remove()
74
74
  }
75
75
  })
76
- for (let k in window.after_transition) {
77
- window.after_transition[k].apply()
78
- }
79
76
  }
80
77
 
81
78
  const urlFromHref = (href) => {
@@ -102,7 +99,13 @@ const turbolinks = () => {
102
99
  if (`${url.pathname}${url.search}` === `${current.pathname}${current.search}`) {
103
100
  return;
104
101
  }
102
+ for (let k in window.turbolink_before_transition) {
103
+ window.turbolink_before_transition[k].apply()
104
+ }
105
105
  await transition(href)
106
+ for (let k in window.turbolink_after_transition) {
107
+ window.turbolink_after_transition[k].apply()
108
+ }
106
109
  history.pushState({}, '', href)
107
110
  turbolinks()
108
111
  }