@scaffscript/core 0.2.0 → 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/dist/index.cjs +103 -15
- package/package.json +41 -41
package/dist/index.cjs
CHANGED
|
@@ -124,7 +124,7 @@ async function parseArgs(...args) {
|
|
|
124
124
|
noIntegration: optionList.includes("-!i") || optionList.includes("--no-integration")
|
|
125
125
|
};
|
|
126
126
|
if (options.integrate && options.noIntegration) {
|
|
127
|
-
log.error("Cannot specify both \x1B[33m--integrate\x1B[0m and \x1B[33m--no-
|
|
127
|
+
log.error("Cannot specify both \x1B[33m--integrate\x1B[0m and \x1B[33m--no-integration\x1B[0m. Aborting...");
|
|
128
128
|
return null;
|
|
129
129
|
}
|
|
130
130
|
const exists = await fileExists(normalizePath(resolvePath(yypPath)));
|
|
@@ -232,6 +232,10 @@ var CONFIG_FILES = [
|
|
|
232
232
|
"scaff.config.cjs",
|
|
233
233
|
"scaff.config.json"
|
|
234
234
|
];
|
|
235
|
+
function dirIsIgnored(dir) {
|
|
236
|
+
const slugs = normalizePath(dir).split("/");
|
|
237
|
+
return slugs.find((slug) => slug.startsWith("_")) ? true : false;
|
|
238
|
+
}
|
|
235
239
|
async function findConfig(filename) {
|
|
236
240
|
let dir = process.cwd();
|
|
237
241
|
while (true) {
|
|
@@ -249,7 +253,7 @@ async function findConfig(filename) {
|
|
|
249
253
|
async function getScaffFiles(path3) {
|
|
250
254
|
log.debug(`Scanning for \x1B[34m*.ss\x1B[0m and \x1B[34m*.gml\x1B[0m files in \x1B[32m${path3}\x1B[0m...`);
|
|
251
255
|
const files = await import_promises2.readdir(path3, { withFileTypes: true, recursive: true });
|
|
252
|
-
const vFiles = files.filter((file) => file.isFile() && (file.name.endsWith(".ss") || file.name.endsWith(".gml"))).map((file) => {
|
|
256
|
+
const vFiles = files.filter((file) => file.isFile() && !file.name.startsWith("_") && !dirIsIgnored(file.parentPath) && (file.name.endsWith(".ss") || file.name.endsWith(".gml"))).map((file) => {
|
|
253
257
|
return {
|
|
254
258
|
name: file.name,
|
|
255
259
|
path: normalizePath(resolvePath(file.parentPath)),
|
|
@@ -314,7 +318,7 @@ var commentRegex = /\/\/[^\n]*|\/\*(?!\*)[\s\S]*?\*\//g;
|
|
|
314
318
|
var implRegex = /impl\s+(?<name>[\w+]+)\s+\{\s+(?<body>[.\s\S]+?)\}/g;
|
|
315
319
|
var implHeaderRegex = /impl\s+(?<name>\w+)\s*\{/g;
|
|
316
320
|
var fnParamsRegex = /\((?<params>[^)]*)\)/g;
|
|
317
|
-
var arrowFnHeaderRegex =
|
|
321
|
+
var arrowFnHeaderRegex = /\b(?:(?:const|let|var)\s+)?(?<name>\w+)\s*=\s*(?<params>\([^)]*\)|\w+)\s*=>/g;
|
|
318
322
|
var modControlRegex = /(?<cmd>export|import|include)\s+(?<mod>\*|\{[^}]+\}|[A-Za-z0-9_]+)\s+(?<src>from)\s+(?<path>["'][^"']+["'])\s*;?/g;
|
|
319
323
|
var contentModRegex = /@(?<cmd>content|valueof|typeof|nameof)\s+(?<mod>[A-Za-z0-9_]+)/g;
|
|
320
324
|
var useModRegex = /@use\s+(?<mod>[A-Za-z0-9_]+)\s+(?<body>\{[.\s\S]+?\})/g;
|
|
@@ -340,7 +344,7 @@ function getTabLevels(str, tabType) {
|
|
|
340
344
|
// package.json
|
|
341
345
|
var package_default = {
|
|
342
346
|
name: "@scaffscript/core",
|
|
343
|
-
version: "0.1
|
|
347
|
+
version: "0.2.1",
|
|
344
348
|
repository: {
|
|
345
349
|
type: "git",
|
|
346
350
|
url: "https://github.com/undervolta/scaffscript"
|
|
@@ -450,9 +454,22 @@ async function readAndSplitFiles(files, config) {
|
|
|
450
454
|
implRegex.lastIndex = 0;
|
|
451
455
|
if (matchExport.length)
|
|
452
456
|
exports2.push({ file, depth: file.path.split("/").filter(Boolean).length });
|
|
453
|
-
else if (implRegex.test(file.content))
|
|
454
|
-
|
|
455
|
-
|
|
457
|
+
else if (implRegex.test(file.content)) {
|
|
458
|
+
implRegex.lastIndex = 0;
|
|
459
|
+
const implMatches = [...file.content.matchAll(implRegex)];
|
|
460
|
+
if (implMatches.length) {
|
|
461
|
+
for (const match of implMatches) {
|
|
462
|
+
const className = match.groups.name;
|
|
463
|
+
if (className && file.content.includes(`class ${className} {`)) {
|
|
464
|
+
file.childs.push(file);
|
|
465
|
+
res.scaff.push(file);
|
|
466
|
+
} else
|
|
467
|
+
implFiles.push(file);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
} else
|
|
471
|
+
implFiles.push(file);
|
|
472
|
+
} else if (file.isScaff && file.toGenerate)
|
|
456
473
|
res.generate.push(file);
|
|
457
474
|
else if (file.isScaff)
|
|
458
475
|
res.scaff.push(file);
|
|
@@ -491,10 +508,10 @@ async function readAndSplitFiles(files, config) {
|
|
|
491
508
|
classFile.childs.push(file);
|
|
492
509
|
else {
|
|
493
510
|
if (config.onNotFound === "error") {
|
|
494
|
-
log.error(`Class \x1B[33m${className}\x1B[0m not found for file ${file.name}. Aborting...`);
|
|
511
|
+
log.error(`Class \x1B[33m${className}\x1B[0m not found for file \x1B[34m${file.name}\x1B[0m. Aborting...`);
|
|
495
512
|
return null;
|
|
496
513
|
}
|
|
497
|
-
log.warn(`Class \x1B[33m${className}\x1B[0m not found for file ${file.name}. Skipping this file...`);
|
|
514
|
+
log.warn(`Class \x1B[33m${className}\x1B[0m not found for file \x1B[34m${file.name}\x1B[0m. Skipping this file...`);
|
|
498
515
|
}
|
|
499
516
|
}
|
|
500
517
|
return res;
|
|
@@ -985,22 +1002,69 @@ function implementClass(module2, fileGroup, config) {
|
|
|
985
1002
|
if (file.childs.length > 0)
|
|
986
1003
|
file.childs.forEach((child) => toImpl.push({ parent: file, file: child }));
|
|
987
1004
|
}
|
|
988
|
-
for (const
|
|
1005
|
+
for (const fileImpl of toImpl) {
|
|
989
1006
|
const filePath = fileImpl.parent.isIndex ? fileImpl.parent.path : `${fileImpl.parent.path}/${fileImpl.parent.name}`;
|
|
990
1007
|
const match = parseHeader(fileImpl.file.content);
|
|
991
|
-
|
|
1008
|
+
const classNames = [];
|
|
1009
|
+
for (const [mIdx, m] of match.entries()) {
|
|
992
1010
|
const { name: className } = m;
|
|
993
1011
|
let { body } = m;
|
|
994
1012
|
body = convertClassMethods(body);
|
|
995
1013
|
body = convertArrowFn(body);
|
|
996
1014
|
if (!className || !body)
|
|
997
1015
|
continue;
|
|
998
|
-
|
|
999
|
-
|
|
1016
|
+
classNames.push(className);
|
|
1017
|
+
if (!module2[filePath] || !module2[filePath][className]) {
|
|
1018
|
+
let newFilePath = null;
|
|
1019
|
+
for (const file of fileGroup.scaff) {
|
|
1020
|
+
if (file.content.includes(`class ${className} {`)) {
|
|
1021
|
+
newFilePath = file.isIndex ? file.path : `${file.path}/${file.name}`;
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
if (!newFilePath) {
|
|
1026
|
+
for (const file of fileGroup.generate) {
|
|
1027
|
+
if (file.content.includes(`class ${className} {`)) {
|
|
1028
|
+
newFilePath = file.isIndex ? file.path : `${file.path}/${file.name}`;
|
|
1029
|
+
break;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
if (!newFilePath) {
|
|
1034
|
+
if (config.onNotFound === "error") {
|
|
1035
|
+
log.error(`Class \x1B[33m${className}\x1B[0m not found for file \x1B[34m${fileImpl.file.name}\x1B[0m. Aborting...`);
|
|
1036
|
+
return false;
|
|
1037
|
+
} else {
|
|
1038
|
+
log.warn(`Class \x1B[33m${className}\x1B[0m not found for file \x1B[34m${fileImpl.file.name}\x1B[0m. Skipping this class...`);
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
const classCloseBracket = module2[newFilePath][className].parsedStr.lastIndexOf("}");
|
|
1043
|
+
module2[newFilePath][className].parsedStr = module2[newFilePath][className].parsedStr.slice(0, classCloseBracket) + `${body.replace(`
|
|
1044
|
+
`, "")}` + (mIdx < match.length - 1 ? `
|
|
1045
|
+
|
|
1046
|
+
` : `
|
|
1047
|
+
}
|
|
1048
|
+
`);
|
|
1049
|
+
if (mIdx === match.length - 1) {
|
|
1050
|
+
for (const name of classNames) {
|
|
1051
|
+
if (!module2[filePath] || !module2[filePath][name])
|
|
1052
|
+
continue;
|
|
1053
|
+
module2[filePath][name].parsedStr += `}
|
|
1054
|
+
`;
|
|
1055
|
+
}
|
|
1056
|
+
} else
|
|
1057
|
+
classNames.splice(classNames.indexOf(className), 1);
|
|
1058
|
+
continue;
|
|
1059
|
+
} else {
|
|
1060
|
+
const classCloseBracket = module2[filePath][className].parsedStr.lastIndexOf("}");
|
|
1061
|
+
module2[filePath][className].parsedStr = module2[filePath][className].parsedStr.slice(0, classCloseBracket) + `${body.replace(`
|
|
1062
|
+
`, "")}` + (mIdx < match.length - 1 ? `
|
|
1000
1063
|
|
|
1001
1064
|
` : `
|
|
1002
1065
|
}
|
|
1003
1066
|
`);
|
|
1067
|
+
}
|
|
1004
1068
|
}
|
|
1005
1069
|
}
|
|
1006
1070
|
return true;
|
|
@@ -1022,6 +1086,30 @@ function countTabsBeforeSubstring(str, sub, tabChar) {
|
|
|
1022
1086
|
}
|
|
1023
1087
|
return count;
|
|
1024
1088
|
}
|
|
1089
|
+
function resolveImportPath(filePath, importPath, config) {
|
|
1090
|
+
if (!config.path)
|
|
1091
|
+
return resolvePath(`${filePath}/${importPath}`);
|
|
1092
|
+
const useWildcard = Object.keys(config.path).filter((k) => k.endsWith("*")).find((k) => importPath.startsWith(k.slice(0, -1)));
|
|
1093
|
+
if (useWildcard) {
|
|
1094
|
+
const pathAlias = config.path[useWildcard]?.replace("*", "");
|
|
1095
|
+
const dynPath = importPath.replace(useWildcard.slice(0, -2), "");
|
|
1096
|
+
if (!pathAlias) {
|
|
1097
|
+
log.error(`Path \x1B[33m${importPath}\x1B[0m not found in path aliases. Aborting...`);
|
|
1098
|
+
return "";
|
|
1099
|
+
}
|
|
1100
|
+
if (pathAlias.startsWith("~")) {
|
|
1101
|
+
return resolvePath(`${config.source}/${pathAlias.replace("~/", "").replace("~", "")}${dynPath}`);
|
|
1102
|
+
}
|
|
1103
|
+
return resolvePath(`${filePath}/${pathAlias}${dynPath}`);
|
|
1104
|
+
} else if (config.path[importPath]) {
|
|
1105
|
+
const pathAlias = config.path[importPath];
|
|
1106
|
+
if (pathAlias.startsWith("~")) {
|
|
1107
|
+
return resolvePath(`${config.source}/${pathAlias.replace("~/", "").replace("~", "")}`);
|
|
1108
|
+
}
|
|
1109
|
+
return resolvePath(`${filePath}/${pathAlias}`);
|
|
1110
|
+
}
|
|
1111
|
+
return resolvePath(`${filePath}/${importPath}`);
|
|
1112
|
+
}
|
|
1025
1113
|
async function getModuleUsage(module2, fileGroup, file, config) {
|
|
1026
1114
|
const matches = [...file.content.matchAll(modControlRegex)];
|
|
1027
1115
|
const limit = 10;
|
|
@@ -1043,7 +1131,7 @@ async function getModuleUsage(module2, fileGroup, file, config) {
|
|
|
1043
1131
|
isInvalid = true;
|
|
1044
1132
|
return null;
|
|
1045
1133
|
}
|
|
1046
|
-
const fromPath = normalizePath(
|
|
1134
|
+
const fromPath = normalizePath(resolveImportPath(file.path, path3.slice(1, -1), config));
|
|
1047
1135
|
const modList = {};
|
|
1048
1136
|
const alias = {};
|
|
1049
1137
|
if (!module2[fromPath]) {
|
|
@@ -2302,7 +2390,7 @@ async function main() {
|
|
|
2302
2390
|
}, []);
|
|
2303
2391
|
log.debug("Integration data extracted successfully.");
|
|
2304
2392
|
const genFiles = await generateSourceCode(intgData, config, input.projectPath);
|
|
2305
|
-
if (!config.noIntegration && !input.options.noIntegration) {
|
|
2393
|
+
if (!config.noIntegration && !input.options.noIntegration || input.options.integrate) {
|
|
2306
2394
|
log.debug("Integrating source code...");
|
|
2307
2395
|
const modified = await integrateSourceCodes(genFiles, config, input.projectPath);
|
|
2308
2396
|
if (modified === null) {
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@scaffscript/core",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"repository": {
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "https://github.com/undervolta/scaffscript"
|
|
7
|
-
},
|
|
8
|
-
"main": "dist/index.cjs",
|
|
9
|
-
"devDependencies": {
|
|
10
|
-
"@types/bun": "latest"
|
|
11
|
-
},
|
|
12
|
-
"peerDependencies": {
|
|
13
|
-
"typescript": "^5"
|
|
14
|
-
},
|
|
15
|
-
"bin": {
|
|
16
|
-
"scaff": "./dist/index.cjs"
|
|
17
|
-
},
|
|
18
|
-
"description": "A minimal superset language of GML with TypeScript-like module system",
|
|
19
|
-
"files": [
|
|
20
|
-
"dist"
|
|
21
|
-
],
|
|
22
|
-
"keywords": [
|
|
23
|
-
"gamemaker",
|
|
24
|
-
"gml",
|
|
25
|
-
"scaff",
|
|
26
|
-
"script",
|
|
27
|
-
"superset",
|
|
28
|
-
"module",
|
|
29
|
-
"cli"
|
|
30
|
-
],
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "bun run build:all",
|
|
34
|
-
"build:node": "bun build src/index-node.ts --outfile dist/index.cjs --target node --format cjs",
|
|
35
|
-
"build:bun": "bun build src/index-bun.ts --outfile build/index.mjs --target bun --format esm",
|
|
36
|
-
"build:all": "bun run build:node && bun run build:bun",
|
|
37
|
-
"dev": "bun run src/index-node.ts",
|
|
38
|
-
"prelink": "bun run build"
|
|
39
|
-
},
|
|
40
|
-
"type": "module"
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@scaffscript/core",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/undervolta/scaffscript"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/bun": "latest"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"scaff": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"description": "A minimal superset language of GML with TypeScript-like module system",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"gamemaker",
|
|
24
|
+
"gml",
|
|
25
|
+
"scaff",
|
|
26
|
+
"script",
|
|
27
|
+
"superset",
|
|
28
|
+
"module",
|
|
29
|
+
"cli"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "bun run build:all",
|
|
34
|
+
"build:node": "bun build src/index-node.ts --outfile dist/index.cjs --target node --format cjs",
|
|
35
|
+
"build:bun": "bun build src/index-bun.ts --outfile build/index.mjs --target bun --format esm",
|
|
36
|
+
"build:all": "bun run build:node && bun run build:bun",
|
|
37
|
+
"dev": "bun run src/index-node.ts",
|
|
38
|
+
"prelink": "bun run build"
|
|
39
|
+
},
|
|
40
|
+
"type": "module"
|
|
41
|
+
}
|