@scaffscript/core 0.1.6 → 0.2.0

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/dist/index.cjs CHANGED
@@ -110,12 +110,7 @@ async function parseArgs(...args) {
110
110
  switch (cmd) {
111
111
  case "gen":
112
112
  case "generate":
113
- const path3 = args[1];
114
- if (!path3) {
115
- log.error("No source path specified. Please specify a valid source path. Aborting...");
116
- return null;
117
- }
118
- const yypPath = args[2];
113
+ const yypPath = args[1];
119
114
  if (!yypPath) {
120
115
  log.error("No project path specified. Please specify a valid project path. Aborting...");
121
116
  return null;
@@ -123,6 +118,15 @@ async function parseArgs(...args) {
123
118
  log.error(`Invalid project path: \x1B[33m${yypPath}\x1B[0m. Please specify a valid \x1B[32m.yyp\x1B[0m file. Aborting...`);
124
119
  return null;
125
120
  }
121
+ const optionList = [...args].slice(2);
122
+ const options = {
123
+ integrate: optionList.includes("-i") || optionList.includes("--integrate"),
124
+ noIntegration: optionList.includes("-!i") || optionList.includes("--no-integration")
125
+ };
126
+ if (options.integrate && options.noIntegration) {
127
+ log.error("Cannot specify both \x1B[33m--integrate\x1B[0m and \x1B[33m--no-integrate\x1B[0m. Aborting...");
128
+ return null;
129
+ }
126
130
  const exists = await fileExists(normalizePath(resolvePath(yypPath)));
127
131
  if (!exists) {
128
132
  log.error(`Project path \x1B[33m${yypPath}\x1B[0m not found. Aborting...`);
@@ -130,7 +134,7 @@ async function parseArgs(...args) {
130
134
  }
131
135
  return {
132
136
  cmd: "generate",
133
- scanPath: normalizePath(resolvePath(path3)),
137
+ options,
134
138
  projectPath: normalizePath(resolvePath(yypPath))
135
139
  };
136
140
  case "help":
@@ -295,10 +299,11 @@ async function getScaffConfig() {
295
299
  debugLevel: conf.debugLevel ?? 0,
296
300
  integrationOption: conf.integrationOption ?? {},
297
301
  noBackup: conf.noBackup ?? false,
298
- noIntegration: conf.noIntegration ?? false,
302
+ noIntegration: conf.noIntegration ?? true,
299
303
  onNotFound: conf.onNotFound ?? "error",
300
304
  path: conf.path ?? {},
301
305
  production: conf.production ?? false,
306
+ source: conf.source ?? "./src",
302
307
  tabType: conf.tabType ?? "1t",
303
308
  targetPlatform: conf.targetPlatform ?? "all",
304
309
  useGmAssetPath: conf.useGmAssetPath ?? false
@@ -335,7 +340,7 @@ function getTabLevels(str, tabType) {
335
340
  // package.json
336
341
  var package_default = {
337
342
  name: "@scaffscript/core",
338
- version: "0.1.5",
343
+ version: "0.1.6",
339
344
  repository: {
340
345
  type: "git",
341
346
  url: "https://github.com/undervolta/scaffscript"
@@ -369,7 +374,8 @@ var package_default = {
369
374
  "build:node": "bun build src/index-node.ts --outfile dist/index.cjs --target node --format cjs",
370
375
  "build:bun": "bun build src/index-bun.ts --outfile build/index.mjs --target bun --format esm",
371
376
  "build:all": "bun run build:node && bun run build:bun",
372
- dev: "bun run src/index-node.ts"
377
+ dev: "bun run src/index-node.ts",
378
+ prelink: "bun run build"
373
379
  },
374
380
  type: "module"
375
381
  };
@@ -441,6 +447,7 @@ async function readAndSplitFiles(files, config) {
441
447
  continue;
442
448
  }
443
449
  const matchExport = [...file.content.matchAll(modControlRegex)];
450
+ implRegex.lastIndex = 0;
444
451
  if (matchExport.length)
445
452
  exports2.push({ file, depth: file.path.split("/").filter(Boolean).length });
446
453
  else if (implRegex.test(file.content))
@@ -455,6 +462,7 @@ async function readAndSplitFiles(files, config) {
455
462
  exports2.sort((a, b) => b.depth - a.depth);
456
463
  indexes.sort((a, b) => b.depth - a.depth);
457
464
  for (const fileHandle of exports2) {
465
+ implRegex.lastIndex = 0;
458
466
  if (implRegex.test(fileHandle.file.content))
459
467
  implFiles.push(fileHandle.file);
460
468
  else if (fileHandle.file.isScaff && fileHandle.file.toGenerate)
@@ -463,6 +471,7 @@ async function readAndSplitFiles(files, config) {
463
471
  res.scaff.push(fileHandle.file);
464
472
  }
465
473
  for (const fileHandle of indexes) {
474
+ implRegex.lastIndex = 0;
466
475
  if (implRegex.test(fileHandle.file.content))
467
476
  implFiles.push(fileHandle.file);
468
477
  else if (fileHandle.file.isScaff && fileHandle.file.toGenerate)
@@ -831,14 +840,14 @@ ${insertTabs(1, config.tabType)}${classBody}
831
840
  const parsedStr = `${name} = function(${params.combined.join(", ")}) ${arrowBlock}`;
832
841
  if (!module2[filePath])
833
842
  module2[filePath] = {};
834
- module2[filePath][name] = { name, value: arrowBlock.slice(1, -1), type: "method", parsedStr };
843
+ module2[filePath][name] = { name, value: arrowBlock.slice(1, -1), type: "arrow-fn", parsedStr };
835
844
  } else {
836
845
  const params = parseFnParams(valuePart);
837
846
  const body = valuePart.split("=>")[1].trim();
838
847
  const parsedStr = `${name} = function(${params.combined.join(", ")}) { return ${body}; }`;
839
848
  if (!module2[filePath])
840
849
  module2[filePath] = {};
841
- module2[filePath][name] = { name, value: body, type: "method", parsedStr };
850
+ module2[filePath][name] = { name, value: body, type: "arrow-fn", parsedStr };
842
851
  }
843
852
  } else if (valuePart.startsWith("function")) {
844
853
  if (valuePart.trim().endsWith("{")) {
@@ -879,7 +888,7 @@ ${insertTabs(1, config.tabType)}${classBody}
879
888
  if (!module2[filePath])
880
889
  module2[filePath] = {};
881
890
  const parsedStr = varType !== "const" ? `${varType === "let" ? "" : "var "}${name} = ${valuePart};` : `#macro ${name} ${valuePart}`;
882
- module2[filePath][name] = { name, value: valuePart, type: valueType, parsedStr };
891
+ module2[filePath][name] = { name, value: valuePart, type: varType === "const" ? "constant" : "variable", parsedStr };
883
892
  }
884
893
  }
885
894
  }
@@ -976,7 +985,7 @@ function implementClass(module2, fileGroup, config) {
976
985
  if (file.childs.length > 0)
977
986
  file.childs.forEach((child) => toImpl.push({ parent: file, file: child }));
978
987
  }
979
- for (const fileImpl of toImpl) {
988
+ for (const [idx, fileImpl] of toImpl.entries()) {
980
989
  const filePath = fileImpl.parent.isIndex ? fileImpl.parent.path : `${fileImpl.parent.path}/${fileImpl.parent.name}`;
981
990
  const match = parseHeader(fileImpl.file.content);
982
991
  for (const m of match) {
@@ -987,9 +996,11 @@ function implementClass(module2, fileGroup, config) {
987
996
  if (!className || !body)
988
997
  continue;
989
998
  module2[filePath][className].parsedStr = module2[filePath][className].parsedStr.slice(0, -1) + `${body.replace(`
990
- `, "")}
999
+ `, "")}` + (idx < toImpl.length - 1 ? `
1000
+
1001
+ ` : `
991
1002
  }
992
- `;
1003
+ `);
993
1004
  }
994
1005
  }
995
1006
  return true;
@@ -1573,6 +1584,7 @@ function getEventFile(eventInput, numInput) {
1573
1584
  dynNum = true;
1574
1585
  break;
1575
1586
  case "keydown":
1587
+ case "key_down":
1576
1588
  case "keyboard":
1577
1589
  event = 5 /* KEY_DOWN */;
1578
1590
  break;
@@ -1580,18 +1592,22 @@ function getEventFile(eventInput, numInput) {
1580
1592
  event = 6 /* MOUSE */;
1581
1593
  break;
1582
1594
  case "other":
1595
+ case "async":
1583
1596
  event = 7 /* OTHER */;
1584
1597
  break;
1585
1598
  case "draw":
1586
1599
  event = 8 /* DRAW */;
1587
1600
  break;
1588
1601
  case "keypress":
1602
+ case "key_press":
1589
1603
  event = 9 /* KEY_PRESS */;
1590
1604
  break;
1591
1605
  case "keyrelease":
1606
+ case "key_release":
1592
1607
  event = 10 /* KEY_RELEASE */;
1593
1608
  break;
1594
1609
  case "cleanup":
1610
+ case "clean_up":
1595
1611
  event = 12 /* CLEAN_UP */;
1596
1612
  break;
1597
1613
  case "gesture":
@@ -1928,7 +1944,7 @@ function createYYScript(projectYyp, rescName, dir, options) {
1928
1944
  "name":"${rescName}",
1929
1945
  "parent":{
1930
1946
  "name":"${dir !== "" ? dirSplit.pop() : projectYyp.replace(".yyp", "")}",
1931
- "path":"${dir !== "" ? `folders/${dir}.yy` : projectYyp}",
1947
+ "path":"${dir !== "" ? `folders/${dir}.yy` : `${projectYyp}.yyp`}",
1932
1948
  },
1933
1949
  "resourceType":"GMScript",
1934
1950
  "resourceVersion":"2.0",
@@ -1949,7 +1965,7 @@ function createYYObject(projectYyp, rescName, dir, eventList, options) {
1949
1965
  "overriddenProperties":[],
1950
1966
  "parent":{
1951
1967
  "name":"${dir !== "" ? dirSplit.pop() : projectYyp.replace(".yyp", "")}",
1952
- "path":"${dir !== "" ? `folders/${dir}.yy` : projectYyp}",
1968
+ "path":"${dir !== "" ? `folders/${dir}.yy` : `${projectYyp}.yyp`}",
1953
1969
  },
1954
1970
  "parentObjectId":null,
1955
1971
  "persistent":false,
@@ -2090,9 +2106,9 @@ async function modifyYyProject(type, projectPath, resource = null, folder = null
2090
2106
  if (type === "add") {
2091
2107
  let addedFolderCnt = 0;
2092
2108
  if (toAddFolders) {
2093
- const folderStartIdx = rawLines.findIndex((line) => line.includes("Folders"));
2094
- const folderEndIdx = rawLines.findIndex((line, idx) => idx > folderStartIdx && line.includes("]"));
2095
- const existsFolders = rawLines.slice(folderStartIdx + 1, folderEndIdx);
2109
+ let folderStartIdx = rawLines.findIndex((line) => line.includes("Folders"));
2110
+ let folderEndIdx = rawLines.findIndex((line, idx) => idx >= folderStartIdx && line.includes("]"));
2111
+ const existsFolders = folderEndIdx > folderStartIdx ? rawLines.slice(folderStartIdx + 1, folderEndIdx) : [];
2096
2112
  for (const folderDir of toAddFolders) {
2097
2113
  const folderSplit = folderDir.split("/");
2098
2114
  for (let i = 0;i < folderSplit.length; i++) {
@@ -2103,6 +2119,11 @@ async function modifyYyProject(type, projectPath, resource = null, folder = null
2103
2119
  name = name.slice(0, -1);
2104
2120
  const dupe = existsFolders.find((line) => line.includes(`"%Name":"${name}"`));
2105
2121
  if (!dupe) {
2122
+ if (!existsFolders.length) {
2123
+ rawLines[folderStartIdx] = ' "Folders":[';
2124
+ rawLines.splice(folderStartIdx + 1, 0, " ],");
2125
+ folderEndIdx = folderStartIdx + 1;
2126
+ }
2106
2127
  rawLines.splice(folderEndIdx + addedFolderCnt, 0, createGMFolderStr(name));
2107
2128
  addedFolderCnt++;
2108
2129
  }
@@ -2176,7 +2197,8 @@ async function integrateSourceCodes(genFile, config, projectPath) {
2176
2197
  log.debug(`File \x1B[32m${relPath}\x1B[0m not found. Creating new resource...`);
2177
2198
  const { type, name } = await createGMResource(gmProject, path3, data, config.integrationOption);
2178
2199
  if (type && name) {
2179
- newFolders.push(data.dirPath);
2200
+ if (data.dirPath !== "")
2201
+ newFolders.push(data.dirPath);
2180
2202
  newResources.push(createGMResourceStr(type, name));
2181
2203
  data.isNew = true;
2182
2204
  }
@@ -2243,7 +2265,7 @@ async function main() {
2243
2265
  case "generate":
2244
2266
  log.debug("Getting Scaff config...");
2245
2267
  const config = await getScaffConfig();
2246
- const files = await getScaffFiles(resolvePath(input.scanPath));
2268
+ const files = await getScaffFiles(resolvePath(config.source));
2247
2269
  log.debug("Processing files...");
2248
2270
  const fileGroup = await readAndSplitFiles(files, config);
2249
2271
  if (!fileGroup) {
@@ -2280,7 +2302,7 @@ async function main() {
2280
2302
  }, []);
2281
2303
  log.debug("Integration data extracted successfully.");
2282
2304
  const genFiles = await generateSourceCode(intgData, config, input.projectPath);
2283
- if (!config.noIntegration) {
2305
+ if (!config.noIntegration && !input.options.noIntegration) {
2284
2306
  log.debug("Integrating source code...");
2285
2307
  const modified = await integrateSourceCodes(genFiles, config, input.projectPath);
2286
2308
  if (modified === null) {
@@ -2295,7 +2317,10 @@ async function main() {
2295
2317
  log.info("Program executed successfully. Thanks for using ScaffScript!");
2296
2318
  } else {
2297
2319
  console.log("---");
2298
- log.info("\x1B[34mnoIntegration\x1B[0m flag is set to \x1B[33mtrue\x1B[0m in the \x1B[32mscaff.config\x1B[0m. No source code will be integrated. Thanks for using ScaffScript!");
2320
+ if (input.options.noIntegration)
2321
+ log.info("\x1B[34m--no-integration\x1B[0m option is set. No source code will be integrated. Thanks for using ScaffScript!");
2322
+ else
2323
+ log.info("\x1B[34mnoIntegration\x1B[0m flag is set to \x1B[33mtrue\x1B[0m in the \x1B[32mscaff.config\x1B[0m. No source code will be integrated. Thanks for using ScaffScript!");
2299
2324
  }
2300
2325
  console.log("");
2301
2326
  break;
package/dist/index.d.ts CHANGED
@@ -47,7 +47,12 @@ export type ScaffConfig = {
47
47
  /**
48
48
  * whether the script is running in production mode (default = false)
49
49
  */
50
- production: boolean;
50
+ production: boolean;
51
+
52
+ /**
53
+ * source directory (default = "./src")
54
+ */
55
+ source: string;
51
56
 
52
57
  /**
53
58
  * tab type to use when generating source code (default = "1t")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaffscript/core",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/undervolta/scaffscript"
@@ -34,7 +34,8 @@
34
34
  "build:node": "bun build src/index-node.ts --outfile dist/index.cjs --target node --format cjs",
35
35
  "build:bun": "bun build src/index-bun.ts --outfile build/index.mjs --target bun --format esm",
36
36
  "build:all": "bun run build:node && bun run build:bun",
37
- "dev": "bun run src/index-node.ts"
37
+ "dev": "bun run src/index-node.ts",
38
+ "prelink": "bun run build"
38
39
  },
39
40
  "type": "module"
40
41
  }