dazscript-framework 1.0.5 → 1.0.6
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 +5 -1
- package/dist/scripts/build.js +1 -0
- package/dist/scripts/cli.js +8 -0
- package/dist/scripts/init.js +1 -0
- package/package.json +1 -1
- package/src/common/log.test.ts +45 -0
- package/src/common/log.ts +62 -14
- package/webpack.config.js +5 -0
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ npm install dazscript-framework dazscript-types
|
|
|
53
53
|
npx dazscript init
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Follow the prompt for your AppData author namespace (e.g. `YourName/my-project`). This creates `dazscript.config.ts`, `tsconfig.json`, and wires the `build`, `build:encrypted`, `watch`, `encrypt`, `icons`, and `installer` scripts into `package.json`.
|
|
56
|
+
Follow the prompt for your AppData author namespace (e.g. `YourName/my-project`). This creates `dazscript.config.ts`, `tsconfig.json`, and wires the `build`, `build:encrypted`, `build:release`, `watch`, `encrypt`, `icons`, and `installer` scripts into `package.json`.
|
|
57
57
|
|
|
58
58
|
### 3. Write the script
|
|
59
59
|
|
|
@@ -160,6 +160,7 @@ This generates:
|
|
|
160
160
|
- `dazscript.config.ts`
|
|
161
161
|
- `tsconfig.json`
|
|
162
162
|
- `package.json` script wiring for `build`, `build:encrypted`, `watch`, `encrypt`, `icons`, and `installer`
|
|
163
|
+
- `build:release` uses `--log-level warn` before encryption so release packages suppress debug and trace output
|
|
163
164
|
|
|
164
165
|
Available `init` flags:
|
|
165
166
|
|
|
@@ -174,6 +175,8 @@ npx dazscript init --menu-path /MyScripts --scripts-path ./src --out-dir ./out -
|
|
|
174
175
|
| `--out-dir` | Where `build` writes `.dsa` files and copies icons |
|
|
175
176
|
| `--app-data-path` | AppData namespace for launcher fallback (`Author/Product` format) |
|
|
176
177
|
|
|
178
|
+
Builds also accept `--log-level <trace|debug|info|warn|error|off>`. This sets the minimum runtime log level for the compiled scripts. Use `debug` or `trace` during development and `warn` for release packages.
|
|
179
|
+
|
|
177
180
|
Use `--scripts-path ./src/scripts` when runnable files live under a subfolder; use `--scripts-path ./src` when they are at the source root.
|
|
178
181
|
|
|
179
182
|
---
|
|
@@ -517,6 +520,7 @@ Files ending in `.dsa.ts` are treated as runnable entry points and compiled to `
|
|
|
517
520
|
| Command | What it does |
|
|
518
521
|
|---|---|
|
|
519
522
|
| `npm run build` | Compile TypeScript → Daz Script |
|
|
523
|
+
| `npm run build:release` | Build with `--log-level warn`, then encrypt implementation bundles |
|
|
520
524
|
| `npm run watch` | Recompile on every save |
|
|
521
525
|
| `npm run installer` | Generate the setup dialog |
|
|
522
526
|
| `npm run icons` | Copy icon assets to the output folder |
|
package/dist/scripts/build.js
CHANGED
package/dist/scripts/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ Options:
|
|
|
26
26
|
--scripts-path <path> Source directory to scan. Default: ./src
|
|
27
27
|
--out-dir <path> Build output directory. Default: ./out
|
|
28
28
|
--app-data-path <path> AppData namespace used by launcher fallbacks. Example: Author/Product
|
|
29
|
+
--log-level <level> Minimum runtime log level: trace, debug, info, warn, error, off
|
|
29
30
|
--daz-studio <path> Daz Studio executable for encrypt
|
|
30
31
|
--keep-source Keep source script.dsa files after encrypting
|
|
31
32
|
--timeout-ms <value> Daz Studio encrypt timeout. Default: 300000
|
|
@@ -115,6 +116,12 @@ function parseOptions(args, defaults) {
|
|
|
115
116
|
continue;
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
if (arg === '--log-level') {
|
|
120
|
+
options.logLevel = args[index + 1];
|
|
121
|
+
index += 1;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
if (arg === '--daz-studio') {
|
|
119
126
|
options.dazStudio = args[index + 1];
|
|
120
127
|
index += 1;
|
|
@@ -179,6 +186,7 @@ async function main(argv) {
|
|
|
179
186
|
scriptsPath: undefined,
|
|
180
187
|
outDir: undefined,
|
|
181
188
|
appDataPath: undefined,
|
|
189
|
+
logLevel: undefined,
|
|
182
190
|
file: undefined,
|
|
183
191
|
dazStudio: undefined,
|
|
184
192
|
keepSource: false,
|
package/dist/scripts/init.js
CHANGED
|
@@ -94,6 +94,7 @@ function updatePackageJson(workdir, options) {
|
|
|
94
94
|
prebuild: 'npm run installer',
|
|
95
95
|
build: 'dazscript build',
|
|
96
96
|
'build:encrypted': 'npm run build && npm run encrypt',
|
|
97
|
+
'build:release': 'npm run build -- --log-level warn && npm run encrypt',
|
|
97
98
|
postbuild: 'npm run icons',
|
|
98
99
|
watch: 'dazscript watch',
|
|
99
100
|
encrypt: 'dazscript encrypt --out-dir ./out --daz-studio "C:\\Program Files\\DAZ 3D\\DAZStudio4\\DAZStudio.exe"',
|
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { debug, error, getLogLevel, info, setLogLevel, shouldLog, trace, warn } from './log'
|
|
3
|
+
|
|
4
|
+
describe('log levels', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
;(globalThis as any).App = {
|
|
7
|
+
debug: vi.fn(),
|
|
8
|
+
log: vi.fn(),
|
|
9
|
+
warning: vi.fn(),
|
|
10
|
+
flushLogBuffer: vi.fn(),
|
|
11
|
+
statusLine: vi.fn()
|
|
12
|
+
}
|
|
13
|
+
setLogLevel('debug')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('filters messages below the active level', () => {
|
|
17
|
+
setLogLevel('warn')
|
|
18
|
+
|
|
19
|
+
debug('hidden debug')
|
|
20
|
+
info('hidden info')
|
|
21
|
+
warn('visible warn')
|
|
22
|
+
error('visible error')
|
|
23
|
+
|
|
24
|
+
expect((globalThis as any).App.debug).not.toHaveBeenCalled()
|
|
25
|
+
expect((globalThis as any).App.log).not.toHaveBeenCalled()
|
|
26
|
+
expect((globalThis as any).App.warning).toHaveBeenCalledTimes(2)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('allows trace only when active level is trace', () => {
|
|
30
|
+
setLogLevel('debug')
|
|
31
|
+
trace('hidden trace')
|
|
32
|
+
|
|
33
|
+
setLogLevel('trace')
|
|
34
|
+
trace('visible trace')
|
|
35
|
+
|
|
36
|
+
expect((globalThis as any).App.debug).toHaveBeenCalledTimes(1)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('normalizes invalid levels to debug', () => {
|
|
40
|
+
setLogLevel('not-a-level')
|
|
41
|
+
|
|
42
|
+
expect(getLogLevel()).toBe('debug')
|
|
43
|
+
expect(shouldLog('debug')).toBe(true)
|
|
44
|
+
})
|
|
45
|
+
})
|
package/src/common/log.ts
CHANGED
|
@@ -1,32 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off'
|
|
2
|
+
|
|
3
|
+
declare const __DAZSCRIPT_LOG_LEVEL__: string | undefined
|
|
4
|
+
|
|
5
|
+
const logLevels: LogLevel[] = ['trace', 'debug', 'info', 'warn', 'error', 'off']
|
|
6
|
+
const logLevelWeights: { [key in LogLevel]: number } = {
|
|
7
|
+
trace: 0,
|
|
8
|
+
debug: 1,
|
|
9
|
+
info: 2,
|
|
10
|
+
warn: 3,
|
|
11
|
+
error: 4,
|
|
12
|
+
off: 5
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let currentLogLevel: LogLevel = normalizeLogLevel(
|
|
16
|
+
typeof __DAZSCRIPT_LOG_LEVEL__ === 'string'
|
|
17
|
+
? __DAZSCRIPT_LOG_LEVEL__
|
|
18
|
+
: 'debug'
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export const setLogLevel = (level: string): LogLevel => {
|
|
22
|
+
currentLogLevel = normalizeLogLevel(level)
|
|
23
|
+
return currentLogLevel
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const getLogLevel = (): LogLevel => currentLogLevel
|
|
27
|
+
|
|
28
|
+
export function normalizeLogLevel(level: string): LogLevel {
|
|
29
|
+
if (!level) return 'debug'
|
|
30
|
+
const normalized = level.toLowerCase() as LogLevel
|
|
31
|
+
return logLevels.indexOf(normalized) >= 0 ? normalized : 'debug'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const shouldLog = (level: LogLevel): boolean => {
|
|
35
|
+
return logLevelWeights[level] >= logLevelWeights[currentLogLevel]
|
|
36
|
+
&& currentLogLevel !== 'off'
|
|
37
|
+
}
|
|
2
38
|
|
|
3
39
|
export const debug = (message: any) => {
|
|
4
|
-
|
|
5
|
-
|
|
40
|
+
if (!shouldLog('debug')) return
|
|
41
|
+
app().debug(format(message))
|
|
42
|
+
flush()
|
|
6
43
|
}
|
|
7
44
|
|
|
8
45
|
export const info = (message: any) => {
|
|
9
|
-
|
|
10
|
-
|
|
46
|
+
if (!shouldLog('info')) return
|
|
47
|
+
app().log(format(message))
|
|
48
|
+
flush()
|
|
11
49
|
}
|
|
12
50
|
|
|
13
51
|
export const error = (message: any) => {
|
|
14
|
-
|
|
15
|
-
|
|
52
|
+
if (!shouldLog('error')) return
|
|
53
|
+
app().warning(format(message, "ERROR"))
|
|
54
|
+
flush()
|
|
16
55
|
}
|
|
17
56
|
|
|
18
57
|
export const warn = (message: any) => {
|
|
19
|
-
|
|
20
|
-
|
|
58
|
+
if (!shouldLog('warn')) return
|
|
59
|
+
app().warning(message)
|
|
60
|
+
flush()
|
|
21
61
|
}
|
|
22
62
|
|
|
23
63
|
export const trace = (message: any) => {
|
|
24
|
-
|
|
25
|
-
|
|
64
|
+
if (!shouldLog('trace')) return
|
|
65
|
+
app().debug(format(message, "TRACE"))
|
|
66
|
+
flush()
|
|
26
67
|
}
|
|
27
68
|
|
|
28
69
|
export const status = (message: any, log: boolean = true) => {
|
|
29
|
-
|
|
70
|
+
app().statusLine(message, log)
|
|
30
71
|
}
|
|
31
72
|
|
|
32
73
|
/**
|
|
@@ -39,8 +80,9 @@ export const raise = (err: string) => {
|
|
|
39
80
|
}
|
|
40
81
|
|
|
41
82
|
export const dump = (obj: any) => {
|
|
42
|
-
|
|
43
|
-
|
|
83
|
+
if (!shouldLog('debug')) return
|
|
84
|
+
app().debug(`[DUMP]\r\n${JSON.stringify(obj, null, 2)}`)
|
|
85
|
+
flush()
|
|
44
86
|
}
|
|
45
87
|
|
|
46
88
|
const format = (message: string, level?: 'ERROR' | 'TRACE' | 'DUMP' | 'INFO') => {
|
|
@@ -54,3 +96,9 @@ const format = (message: string, level?: 'ERROR' | 'TRACE' | 'DUMP' | 'INFO') =>
|
|
|
54
96
|
return text
|
|
55
97
|
}
|
|
56
98
|
|
|
99
|
+
const app = (): any => App
|
|
100
|
+
|
|
101
|
+
const flush = () => {
|
|
102
|
+
app().flushLogBuffer()
|
|
103
|
+
}
|
|
104
|
+
|
package/webpack.config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const glob = require('glob');
|
|
3
|
+
const webpack = require('webpack');
|
|
3
4
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
4
5
|
const { createActionLaunchers } = require('./dist/scripts/launchers');
|
|
5
6
|
const { validateAppDataPath } = require('./dist/scripts/app-data-path');
|
|
@@ -29,6 +30,7 @@ module.exports = (env, argv) => {
|
|
|
29
30
|
(env && env.appDataPath) || projectConfig.appDataPath,
|
|
30
31
|
projectRoot
|
|
31
32
|
);
|
|
33
|
+
const logLevel = (env && env.logLevel) || '';
|
|
32
34
|
const sourceRoot = path.resolve(projectRoot, 'src');
|
|
33
35
|
const projectNodeModules = path.resolve(projectRoot, 'node_modules');
|
|
34
36
|
const frameworkSourceRoot = path.resolve(
|
|
@@ -120,6 +122,9 @@ module.exports = (env, argv) => {
|
|
|
120
122
|
},
|
|
121
123
|
},
|
|
122
124
|
plugins: [
|
|
125
|
+
new webpack.DefinePlugin({
|
|
126
|
+
__DAZSCRIPT_LOG_LEVEL__: JSON.stringify(logLevel),
|
|
127
|
+
}),
|
|
123
128
|
new ActionLauncherPlugin({
|
|
124
129
|
workdir: projectRoot,
|
|
125
130
|
outDir: outputPath,
|