@neuxnet/neux-cli 0.2.3
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/README.md +438 -0
- package/README.zh-CN.md +554 -0
- package/assets/container/assets/index.css +1 -0
- package/assets/container/assets/index.js +137 -0
- package/assets/container/assets/pageFrame.css +1 -0
- package/assets/container/assets/pageFrame.js +56 -0
- package/assets/container/assets/service.js +6 -0
- package/assets/container/assets/vconsole.js +931 -0
- package/assets/container/favicon.ico +0 -0
- package/assets/container/images/icon-arrow.png +0 -0
- package/assets/container/images/mini-action-white.png +0 -0
- package/assets/container/images/mini-action.png +0 -0
- package/assets/container/images/mini-arrow-left-white.png +0 -0
- package/assets/container/images/mini-arrow-left.jpg +0 -0
- package/assets/container/images/mini-arrow-left.png +0 -0
- package/assets/container/images/mini-close-white.png +0 -0
- package/assets/container/images/mini-close.png +0 -0
- package/assets/container/images/more.png +0 -0
- package/assets/container/images/search.jpg +0 -0
- package/assets/container/index.html +1 -0
- package/assets/container/pageFrame.html +1 -0
- package/assets/init/tabbar/home-active.png +0 -0
- package/assets/init/tabbar/home.png +0 -0
- package/assets/init/tabbar/list-active.png +0 -0
- package/assets/init/tabbar/list.png +0 -0
- package/assets/init/types/neux-api.d.ts +1402 -0
- package/package.json +68 -0
- package/scripts/generate-init-types.js +210 -0
- package/scripts/sync-compiler.js +22 -0
- package/scripts/sync-web-container.js +34 -0
- package/src/bin/cli.js +646 -0
- package/src/core/brand.js +11 -0
- package/src/core/compiler.js +305 -0
- package/src/core/defaults.js +12 -0
- package/src/core/dev.js +15 -0
- package/src/core/errors.js +17 -0
- package/src/core/fs.js +66 -0
- package/src/core/i18n.js +37 -0
- package/src/core/init.js +866 -0
- package/src/core/lifecycle.js +32 -0
- package/src/core/manifest.js +72 -0
- package/src/core/pack.js +156 -0
- package/src/core/package-info.js +27 -0
- package/src/core/preview-server.js +123 -0
- package/src/core/project.js +101 -0
- package/src/core/prompts.js +71 -0
- package/src/core/proxy-security.js +141 -0
- package/src/core/proxy.js +156 -0
- package/src/core/qr.js +41 -0
- package/src/core/terminal-qr.js +72 -0
- package/src/core/update.js +278 -0
- package/src/core/watch.js +113 -0
- package/src/core/web.js +649 -0
- package/src/core/zip.js +120 -0
- package/src/index.js +20 -0
- package/src/providers/service-client.js +149 -0
- package/src/providers/service-config.js +264 -0
- package/src/providers/service.js +146 -0
- package/src/providers/upload.js +112 -0
- package/vendor/dimina-compiler/bin/index.cjs +265 -0
- package/vendor/dimina-compiler/bin/index.js +263 -0
- package/vendor/dimina-compiler/compatibility-B-DoZtUX.cjs +395 -0
- package/vendor/dimina-compiler/compatibility-Cl3-DO6V.js +366 -0
- package/vendor/dimina-compiler/core/logic-compiler.cjs +378 -0
- package/vendor/dimina-compiler/core/logic-compiler.js +374 -0
- package/vendor/dimina-compiler/core/style-compiler.cjs +392 -0
- package/vendor/dimina-compiler/core/style-compiler.js +377 -0
- package/vendor/dimina-compiler/core/view-compiler.cjs +1601 -0
- package/vendor/dimina-compiler/core/view-compiler.js +1582 -0
- package/vendor/dimina-compiler/index.cjs +762 -0
- package/vendor/dimina-compiler/index.js +751 -0
- package/vendor/dimina-compiler/sourcemap-BgtIgqkC.cjs +1377 -0
- package/vendor/dimina-compiler/sourcemap-CKjhV9h7.js +1135 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import chokidar from 'chokidar'
|
|
4
|
+
import { DiminaCliError } from './errors.js'
|
|
5
|
+
|
|
6
|
+
const DEFAULT_IGNORES = new Set(['.git', 'node_modules', 'dist', 'artifacts'])
|
|
7
|
+
|
|
8
|
+
function isInsidePath(filePath, roots) {
|
|
9
|
+
return roots.some((root) => {
|
|
10
|
+
const relative = path.relative(root, filePath)
|
|
11
|
+
return relative === '' || (!!relative && !relative.startsWith('..') && !path.isAbsolute(relative))
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hasIgnoredSegment(filePath, projectRoot, ignoredNames) {
|
|
16
|
+
const relative = path.relative(projectRoot, filePath)
|
|
17
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return false
|
|
18
|
+
return relative.split(path.sep).some(name => ignoredNames.has(name) || name.startsWith('.DS_Store'))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function createProjectWatcher(options = {}) {
|
|
22
|
+
const projectRoot = path.resolve(options.project || options.projectPath || process.cwd())
|
|
23
|
+
const debounceMs = Number.parseInt(options.debounceMs ?? 120, 10)
|
|
24
|
+
const ignoredNames = new Set([...DEFAULT_IGNORES, ...(options.ignoreNames || [])])
|
|
25
|
+
const ignoredPaths = (options.ignorePaths || []).map(target => path.resolve(target))
|
|
26
|
+
const onChange = options.onChange
|
|
27
|
+
|
|
28
|
+
if (typeof onChange !== 'function') {
|
|
29
|
+
throw new DiminaCliError('DIMINA_WATCH_INVALID', 'createProjectWatcher requires an onChange callback')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const watcher = chokidar.watch(projectRoot, {
|
|
33
|
+
ignored: target => {
|
|
34
|
+
const filePath = path.resolve(String(target))
|
|
35
|
+
return isInsidePath(filePath, ignoredPaths) || hasIgnoredSegment(filePath, projectRoot, ignoredNames)
|
|
36
|
+
},
|
|
37
|
+
ignoreInitial: true,
|
|
38
|
+
atomic: true,
|
|
39
|
+
persistent: options.persistent !== false,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
let closed = false
|
|
43
|
+
let timer = null
|
|
44
|
+
let pendingEvents = []
|
|
45
|
+
const knownMtimes = new Map()
|
|
46
|
+
|
|
47
|
+
const emit = (event) => {
|
|
48
|
+
pendingEvents.push(event)
|
|
49
|
+
clearTimeout(timer)
|
|
50
|
+
timer = setTimeout(() => {
|
|
51
|
+
if (!closed && pendingEvents.length) {
|
|
52
|
+
const events = pendingEvents
|
|
53
|
+
if (!closed) onChange({ ...events[0], events })
|
|
54
|
+
}
|
|
55
|
+
pendingEvents = []
|
|
56
|
+
}, debounceMs)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const handleChange = async (eventType, changedPath) => {
|
|
60
|
+
if (closed) return
|
|
61
|
+
const filePath = path.resolve(changedPath)
|
|
62
|
+
if (isInsidePath(filePath, ignoredPaths) || hasIgnoredSegment(filePath, projectRoot, ignoredNames)) return
|
|
63
|
+
try {
|
|
64
|
+
const stat = await fs.stat(filePath)
|
|
65
|
+
const previousMtime = knownMtimes.get(filePath)
|
|
66
|
+
knownMtimes.set(filePath, stat.mtimeMs)
|
|
67
|
+
if (eventType === 'change' && previousMtime === stat.mtimeMs) return
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
knownMtimes.delete(filePath)
|
|
71
|
+
}
|
|
72
|
+
emit({ eventType, path: filePath, projectPath: projectRoot })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
watcher.on('add', filePath => handleChange('rename', filePath))
|
|
76
|
+
watcher.on('change', filePath => handleChange('change', filePath))
|
|
77
|
+
watcher.on('unlink', filePath => handleChange('rename', filePath))
|
|
78
|
+
|
|
79
|
+
await new Promise((resolve, reject) => {
|
|
80
|
+
const onReady = () => {
|
|
81
|
+
watcher.off('error', onError)
|
|
82
|
+
resolve()
|
|
83
|
+
}
|
|
84
|
+
const onError = error => {
|
|
85
|
+
watcher.off('ready', onReady)
|
|
86
|
+
reject(error)
|
|
87
|
+
}
|
|
88
|
+
watcher.once('ready', onReady)
|
|
89
|
+
watcher.once('error', onError)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const watched = watcher.getWatched()
|
|
93
|
+
await Promise.all(Object.entries(watched).flatMap(([directory, names]) => names.map(async name => {
|
|
94
|
+
const filePath = path.resolve(directory, name)
|
|
95
|
+
try {
|
|
96
|
+
knownMtimes.set(filePath, (await fs.stat(filePath)).mtimeMs)
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// The file may have disappeared between chokidar's ready event and stat.
|
|
100
|
+
}
|
|
101
|
+
})))
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
projectPath: projectRoot,
|
|
105
|
+
async close() {
|
|
106
|
+
if (closed) return
|
|
107
|
+
closed = true
|
|
108
|
+
clearTimeout(timer)
|
|
109
|
+
pendingEvents = []
|
|
110
|
+
await watcher.close()
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
}
|