dazscript-framework 0.2.5 → 0.3.2

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.
@@ -2,6 +2,8 @@ const ts = require('typescript');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const glob = require('glob');
5
+ const { loadConfig } = require('./config-loader');
6
+ const { validateAppDataPath } = require('./app-data-path');
5
7
 
6
8
  const nameofActionFunction = 'action';
7
9
 
@@ -19,19 +21,14 @@ function stringOrDefault(str, defaultValue) {
19
21
  return str !== undefined && str !== null && str !== '' ? str : defaultValue;
20
22
  }
21
23
 
22
- function generateInstallerTemplate(data) {
24
+ function generateInstallerTemplate(data, settingsPath, bundleName) {
23
25
  return `
24
- import { installCustomActions as install } from '@dsf/helpers/custom-action-helper';
26
+ import { showSetupCustomActionsDialog as setup } from '@dsf/helpers/custom-action-installer-helper';
25
27
 
26
- install(${data});
27
- `;
28
- }
29
-
30
- function generateUninstallerTemplate(data) {
31
- return `
32
- import { uninstallCustomActions as uninstall } from '@dsf/helpers/custom-action-helper';
33
-
34
- uninstall(${data});
28
+ setup(${data}, ${JSON.stringify({
29
+ settingsPath,
30
+ bundleName,
31
+ })});
35
32
  `;
36
33
  }
37
34
 
@@ -154,7 +151,7 @@ function findActionEntryFiles(workdir, options) {
154
151
  });
155
152
  }
156
153
 
157
- function processScript(filePath, container, defaultMenuPath) {
154
+ function processScript(filePath, container, defaultMenuPath, settingsPath, bundleName) {
158
155
  const fileInfo = path.parse(filePath);
159
156
  const content = fs.readFileSync(filePath, 'utf-8').toString();
160
157
  const actionCall = findTopLevelActionCall(content, filePath);
@@ -208,38 +205,29 @@ function processScript(filePath, container, defaultMenuPath) {
208
205
  container.scripts.push(script);
209
206
 
210
207
  if (decorator.bundle !== undefined) {
211
- let packageInstallerFilePath = `Install.dsa.ts`;
212
- let packageUninstallerFilePath = `Uninstall.dsa.ts`;
208
+ let packageSetupFilePath = `Setup.dsa.ts`;
213
209
 
214
210
  if (decorator.bundle !== true) {
215
- packageInstallerFilePath = `Install ${decorator.bundle}.dsa.ts`;
216
- packageUninstallerFilePath = `Uninstall ${decorator.bundle}.dsa.ts`;
211
+ packageSetupFilePath = `Setup ${decorator.bundle}.dsa.ts`;
217
212
  }
218
213
 
219
214
  let bundleScriptContent = generateInstallerTemplate(
220
- JSON.stringify(container.scripts, null, 4)
215
+ JSON.stringify(container.scripts, null, 4),
216
+ settingsPath,
217
+ bundleName
221
218
  );
222
219
  let bundleScriptFilePath = path.join(
223
220
  path.parse(filePath).dir,
224
- packageInstallerFilePath
225
- );
226
- fs.writeFileSync(bundleScriptFilePath, bundleScriptContent);
227
-
228
- bundleScriptContent = generateUninstallerTemplate(
229
- JSON.stringify(container.scripts, null, 4)
230
- );
231
- bundleScriptFilePath = path.join(
232
- path.parse(filePath).dir,
233
- packageUninstallerFilePath
221
+ packageSetupFilePath
234
222
  );
235
223
  fs.writeFileSync(bundleScriptFilePath, bundleScriptContent);
236
224
  }
237
225
  }
238
226
 
239
- function processScripts(paths, container, defaultMenuPath) {
227
+ function processScripts(paths, container, defaultMenuPath, settingsPath, bundleName) {
240
228
  paths.forEach((filePath) => {
241
229
  console.log(`Processing ${filePath}`);
242
- processScript(filePath, container, defaultMenuPath);
230
+ processScript(filePath, container, defaultMenuPath, settingsPath, bundleName);
243
231
  });
244
232
  }
245
233
 
@@ -247,10 +235,16 @@ function generateInstallerFiles(workdir, options) {
247
235
  const defaultMenuPath = options.defaultMenuPath.endsWith('/')
248
236
  ? options.defaultMenuPath
249
237
  : `${options.defaultMenuPath}/`;
238
+ const { config } = loadConfig(workdir);
239
+ const appDataPath = validateAppDataPath(options.appDataPath || config.appDataPath, workdir);
240
+ const settingsPath = `${appDataPath}/Installer`;
241
+ const bundleName = typeof config.bundleName === 'string' && config.bundleName.trim()
242
+ ? config.bundleName.trim()
243
+ : undefined;
250
244
  const container = { scripts: [] };
251
245
  const matches = findActionEntryFiles(workdir, options);
252
246
 
253
- processScripts(matches, container, defaultMenuPath);
247
+ processScripts(matches, container, defaultMenuPath, settingsPath, bundleName);
254
248
 
255
249
  container.scripts = container.scripts.sort((a, b) => {
256
250
  const aKey = a.menuPath + a.filePath;
@@ -259,17 +253,16 @@ function generateInstallerFiles(workdir, options) {
259
253
  });
260
254
 
261
255
  const installerScriptContent = generateInstallerTemplate(
262
- JSON.stringify(container.scripts, null, 4)
256
+ JSON.stringify(container.scripts, null, 4),
257
+ settingsPath,
258
+ bundleName
263
259
  );
264
- fs.writeFileSync(path.join(workdir, 'src', 'Install.dsa.ts'), installerScriptContent);
260
+ fs.writeFileSync(path.join(workdir, 'src', 'Setup.dsa.ts'), installerScriptContent);
265
261
 
266
- const uninstallerScriptContent = generateUninstallerTemplate(
267
- JSON.stringify(container.scripts, null, 4)
268
- );
269
- fs.writeFileSync(
270
- path.join(workdir, 'src', 'Uninstall.dsa.ts'),
271
- uninstallerScriptContent
272
- );
262
+ const installPath = path.join(workdir, 'src', 'Install.dsa.ts');
263
+ const uninstallPath = path.join(workdir, 'src', 'Uninstall.dsa.ts');
264
+ if (fs.existsSync(installPath)) fs.unlinkSync(installPath);
265
+ if (fs.existsSync(uninstallPath)) fs.unlinkSync(uninstallPath);
273
266
  }
274
267
 
275
268
  if (require.main === module) {
@@ -277,6 +270,7 @@ if (require.main === module) {
277
270
  const options = {
278
271
  scriptsPath: './src',
279
272
  defaultMenuPath: 'My Scripts',
273
+ appDataPath: undefined,
280
274
  };
281
275
 
282
276
  for (let index = 0; index < args.length; index += 1) {
@@ -294,6 +288,12 @@ if (require.main === module) {
294
288
  continue;
295
289
  }
296
290
 
291
+ if (arg === '--app-data-path') {
292
+ options.appDataPath = args[index + 1];
293
+ index += 1;
294
+ continue;
295
+ }
296
+
297
297
  throw new Error(`Unknown option: ${arg}`);
298
298
  }
299
299
 
@@ -3,6 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const { findActionEntryFiles } = require('./install-generator');
6
+ const { validateAppDataPath } = require('./app-data-path');
6
7
 
7
8
  function toPosix(filePath) {
8
9
  return filePath.replace(/\\/g, '/');
@@ -25,47 +26,6 @@ function getImplementationRelativePath(outputRelativePath) {
25
26
  return path.posix.join(implementationDirectory, 'script.dsa');
26
27
  }
27
28
 
28
- function validateAppDataPath(appDataPath, workdir) {
29
- if (!appDataPath || typeof appDataPath !== 'string') {
30
- throw new Error(
31
- `[dazscript] Missing required appDataPath in ${workdir}. ` +
32
- `Set appDataPath: 'Author/Product' in dazscript.config.ts.`
33
- );
34
- }
35
-
36
- const normalized = toPosix(appDataPath).trim().replace(/^\/+|\/+$/g, '');
37
- const segments = normalized.split('/').filter(Boolean);
38
-
39
- if (segments.length < 2) {
40
- throw new Error(
41
- `[dazscript] Invalid appDataPath "${appDataPath}" in ${workdir}. ` +
42
- `Use at least two segments, for example 'Author/Product'.`
43
- );
44
- }
45
-
46
- const blockedSegments = new Set([
47
- 'appdata',
48
- 'cache',
49
- 'data',
50
- 'lib',
51
- 'libs',
52
- 'script',
53
- 'scripts',
54
- 'temp',
55
- 'tmp',
56
- ]);
57
-
58
- const invalidSegment = segments.find((segment) => blockedSegments.has(segment.toLowerCase()));
59
- if (invalidSegment) {
60
- throw new Error(
61
- `[dazscript] Invalid appDataPath "${appDataPath}" in ${workdir}. ` +
62
- `Path segments like "${invalidSegment}" are too generic. Use a unique Author/Product path.`
63
- );
64
- }
65
-
66
- return normalized;
67
- }
68
-
69
29
  function makeLauncherSource(implementationRelativePath, appDataImplementationRelativePath) {
70
30
  return [
71
31
  '// Auto-generated launcher shim.',
@@ -158,5 +118,4 @@ function createActionLaunchers(workdir, options) {
158
118
 
159
119
  module.exports = {
160
120
  createActionLaunchers,
161
- validateAppDataPath,
162
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dazscript-framework",
3
- "version": "0.2.5",
3
+ "version": "0.3.2",
4
4
  "author": "Freddy Diaz",
5
5
  "license": "MPL-2.0",
6
6
  "description": "",
@@ -41,7 +41,7 @@
41
41
  "url": "git+https://github.com/fjdiazt/dazscript-framework.git"
42
42
  },
43
43
  "peerDependencies": {
44
- "dazscript-types": "^0.2.3"
44
+ "dazscript-types": "^1.0.0"
45
45
  },
46
46
  "dependencies": {
47
47
  "@babel/core": "^7.23.2",
@@ -67,6 +67,7 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/node": "^22.10.5",
70
+ "dazscript-types": "^1.0.1",
70
71
  "eslint": "^9.17.0",
71
72
  "typescript": "^5.7.3"
72
73
  }
@@ -1,7 +1,7 @@
1
1
 
2
- import { installCustomActions as install } from '@dsf/helpers/custom-action-helper';
2
+ import { showSetupCustomActionsDialog as setup } from '@dsf/helpers/custom-action-installer-helper';
3
3
 
4
- install([
4
+ setup([
5
5
  {
6
6
  "name": null,
7
7
  "text": "Hello World",
@@ -16,4 +16,4 @@ install([
16
16
  "menuPath": "/DazScriptFramework/samples",
17
17
  "description": "sample-dialog"
18
18
  }
19
- ]);
19
+ ], {"settingsPath":"DazScriptFramework/samples/Installer","bundleName":"Samples"});
@@ -384,7 +384,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
384
384
 
385
385
  if (context.doubleClicked) {
386
386
  listView.doubleClicked.scriptConnect((listItem) => {
387
- context.doubleClicked.value = listItem?.getDataItem('data')
387
+ context.doubleClicked.value = listItem?.getDataItem('data') as TData
388
388
  })
389
389
  }
390
390
 
@@ -16,7 +16,7 @@ export default class SliderBuilder extends WidgetBuilderBase<DzFloatSlider | DzI
16
16
  value$.connect((value) => {
17
17
  this.widget.value = value
18
18
  });
19
- (this.widget.valueChanged as unknown as ISignalT<number>).scriptConnect((value) => {
19
+ (this.widget.valueChanged as unknown as ISignal<number>).scriptConnect((value) => {
20
20
  value$.value = value
21
21
  })
22
22
  }
@@ -37,7 +37,7 @@ const shortcutTokenMap: { [key: string]: string } = {
37
37
  'DOWN': 'Down',
38
38
  }
39
39
 
40
- const normalizeShortcut = (shortcut: string): string => {
40
+ export const normalizeShortcut = (shortcut: string): string => {
41
41
  if (!shortcut) return ''
42
42
 
43
43
  return shortcut
@@ -53,6 +53,19 @@ const normalizeShortcut = (shortcut: string): string => {
53
53
  .join('+')
54
54
  }
55
55
 
56
+ export const getActionShortcut = (name: string): string => {
57
+ const action = findAction(name)
58
+ if (!action) return ''
59
+
60
+ if (isCustomAction(action)) {
61
+ const index = actionMgr.findCustomAction(name)
62
+ if (index < 0) return ''
63
+ return normalizeShortcut(String(actionMgr.getCustomActionShortcut(index) ?? '').trim())
64
+ }
65
+
66
+ return normalizeShortcut(String(action.shortcut?.toString() ?? '').trim())
67
+ }
68
+
56
69
  type ActionShortcutEntry = {
57
70
  action: DzAction
58
71
  shortcut: string
@@ -182,7 +195,7 @@ export const clearActionShorcut = (name: string) => {
182
195
  }
183
196
  }
184
197
 
185
- export const getActionPixmap = (action: string, icon: string, maxSize?: number): QPixmap | null => {
198
+ export const getActionPixmap = (action: string, icon: string, maxSize?: number): Pixmap | null => {
186
199
  try {
187
200
  if (!action) return null;
188
201
  let isCustom = isCustomAction(action)
@@ -191,7 +204,7 @@ export const getActionPixmap = (action: string, icon: string, maxSize?: number):
191
204
  let image: DzImageTexture = (App.getImageMgr() as any)['getImage(QString)'](icon)
192
205
  if (image) {
193
206
  let size = image.getOriginalImageSize();
194
- let pixmap: QPixmap
207
+ let pixmap: Pixmap
195
208
  // Only clamp if maxSize is provided and image is larger
196
209
  if (maxSize && (size.width > maxSize || size.height > maxSize)) {
197
210
  pixmap = image.getPreviewPixmap(Math.min(size.width, maxSize), Math.min(size.height, maxSize))