dazscript-framework 0.1.16 → 0.2.1
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 +49 -60
- package/babel.config.js +10 -18
- package/dist/config.js +9 -0
- package/dist/scripts/build.js +82 -0
- package/dist/scripts/cli.js +155 -0
- package/dist/scripts/config-loader.js +83 -0
- package/dist/scripts/icons.js +27 -0
- package/dist/scripts/init.js +120 -0
- package/dist/scripts/install-generator.js +67 -54
- package/package.json +18 -17
- package/src/helpers/http-helper.ts +4 -0
- package/webpack.config.js +28 -7
- package/dist/babel/trace-babel-plugin.js +0 -243
- package/dist/babel/trace-log-babel-plugin.js +0 -164
|
@@ -2,36 +2,13 @@ const tsFileParser = require('ts-file-parser');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const glob = require('glob');
|
|
5
|
-
const { program } = require('commander');
|
|
6
|
-
|
|
7
|
-
program
|
|
8
|
-
.requiredOption(
|
|
9
|
-
'-p, --scriptsPath <path>',
|
|
10
|
-
'Specify the path to your scripts'
|
|
11
|
-
)
|
|
12
|
-
.option(
|
|
13
|
-
'-m, --defaultMenuPath [path]',
|
|
14
|
-
'Specify the default menu path',
|
|
15
|
-
'My Scripts'
|
|
16
|
-
)
|
|
17
|
-
.parse(process.argv);
|
|
18
|
-
let options = program.opts();
|
|
19
5
|
|
|
20
6
|
const nameofActionDecorator = 'action';
|
|
21
7
|
|
|
22
|
-
const scriptsPath = options.scriptsPath.endsWith('/')
|
|
23
|
-
? options.scriptsPath
|
|
24
|
-
: options.scriptsPath + '/';
|
|
25
|
-
const defaultMenuPath = options.defaultMenuPath.endsWith('/')
|
|
26
|
-
? options.defaultMenuPath
|
|
27
|
-
: options.defaultMenuPath + '/';
|
|
28
|
-
|
|
29
|
-
const container = { scripts: [] };
|
|
30
|
-
|
|
31
8
|
function getPartialPath(filePath) {
|
|
32
9
|
const fileInfo = path.parse(filePath);
|
|
33
10
|
const dir = fileInfo.dir.replace('/src', '').replace(/^\.\//, '');
|
|
34
|
-
return `${dir}/${fileInfo.name}
|
|
11
|
+
return dir ? `${dir}/${fileInfo.name}` : fileInfo.name;
|
|
35
12
|
}
|
|
36
13
|
|
|
37
14
|
function compareStrings(a, b) {
|
|
@@ -58,7 +35,7 @@ uninstall(${data});
|
|
|
58
35
|
`;
|
|
59
36
|
}
|
|
60
37
|
|
|
61
|
-
function processScript(filePath) {
|
|
38
|
+
function processScript(filePath, container, defaultMenuPath) {
|
|
62
39
|
const fileInfo = path.parse(filePath);
|
|
63
40
|
const content = fs.readFileSync(filePath, 'utf-8').toString();
|
|
64
41
|
const json = tsFileParser.parseStruct(content, {}, filePath);
|
|
@@ -79,7 +56,12 @@ function processScript(filePath) {
|
|
|
79
56
|
decorator.bundle === undefined
|
|
80
57
|
? getPartialPath(filePath)
|
|
81
58
|
: fileInfo.name.replace('.ts', ''),
|
|
82
|
-
menuPath:
|
|
59
|
+
menuPath: (() => {
|
|
60
|
+
const relativeDir = path.parse(getPartialPath(filePath)).dir;
|
|
61
|
+
return relativeDir && relativeDir !== '.'
|
|
62
|
+
? `${defaultMenuPath}${relativeDir}`
|
|
63
|
+
: defaultMenuPath.replace(/\/$/, '');
|
|
64
|
+
})(),
|
|
83
65
|
description: fileInfo.name.replace('.dsa', ''),
|
|
84
66
|
group: stringOrDefault(decorator.group, undefined),
|
|
85
67
|
shortcut: stringOrDefault(decorator.shortcut),
|
|
@@ -144,42 +126,73 @@ function processScript(filePath) {
|
|
|
144
126
|
});
|
|
145
127
|
}
|
|
146
128
|
|
|
147
|
-
function processScripts(paths) {
|
|
129
|
+
function processScripts(paths, container, defaultMenuPath) {
|
|
148
130
|
paths.forEach((filePath) => {
|
|
149
131
|
console.log(`Processing ${filePath}`);
|
|
150
|
-
processScript(filePath);
|
|
132
|
+
processScript(filePath, container, defaultMenuPath);
|
|
151
133
|
});
|
|
152
134
|
}
|
|
153
135
|
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
136
|
+
function generateInstallerFiles(workdir, options) {
|
|
137
|
+
const scriptsPath = options.scriptsPath.endsWith('/')
|
|
138
|
+
? options.scriptsPath
|
|
139
|
+
: `${options.scriptsPath}/`;
|
|
140
|
+
const defaultMenuPath = options.defaultMenuPath.endsWith('/')
|
|
141
|
+
? options.defaultMenuPath
|
|
142
|
+
: `${options.defaultMenuPath}/`;
|
|
143
|
+
const container = { scripts: [] };
|
|
144
|
+
const matches = glob.sync(`${scriptsPath}/**/*.dsa.ts`, { cwd: workdir });
|
|
145
|
+
|
|
146
|
+
processScripts(matches, container, defaultMenuPath);
|
|
147
|
+
|
|
148
|
+
container.scripts = container.scripts.sort((a, b) => {
|
|
149
|
+
const aKey = a.menuPath + a.filePath;
|
|
150
|
+
const bKey = b.menuPath + b.filePath;
|
|
151
|
+
return compareStrings(aKey, bKey);
|
|
152
|
+
});
|
|
160
153
|
|
|
161
|
-
|
|
154
|
+
const installerScriptContent = generateInstallerTemplate(
|
|
155
|
+
JSON.stringify(container.scripts, null, 4)
|
|
156
|
+
);
|
|
157
|
+
fs.writeFileSync(path.join(workdir, 'src', 'Install.dsa.ts'), installerScriptContent);
|
|
158
|
+
|
|
159
|
+
const uninstallerScriptContent = generateUninstallerTemplate(
|
|
160
|
+
JSON.stringify(container.scripts, null, 4)
|
|
161
|
+
);
|
|
162
|
+
fs.writeFileSync(
|
|
163
|
+
path.join(workdir, 'src', 'Uninstall.dsa.ts'),
|
|
164
|
+
uninstallerScriptContent
|
|
165
|
+
);
|
|
166
|
+
}
|
|
162
167
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
if (require.main === module) {
|
|
169
|
+
const args = process.argv.slice(2);
|
|
170
|
+
const options = {
|
|
171
|
+
scriptsPath: './src',
|
|
172
|
+
defaultMenuPath: 'My Scripts',
|
|
173
|
+
};
|
|
168
174
|
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
JSON.stringify(container.scripts, null, 4)
|
|
172
|
-
);
|
|
173
|
-
let outputFilePath = './src/Install.dsa.ts';
|
|
174
|
-
fs.writeFileSync(outputFilePath, installerScriptContent);
|
|
175
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
176
|
+
const arg = args[index];
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
if (arg === '--scripts-path' || arg === '-p') {
|
|
179
|
+
options.scriptsPath = args[index + 1];
|
|
180
|
+
index += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (arg === '--menu-path' || arg === '--defaultMenuPath' || arg === '-m') {
|
|
185
|
+
options.defaultMenuPath = args[index + 1];
|
|
186
|
+
index += 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
generateInstallerFiles(process.cwd(), options);
|
|
182
194
|
}
|
|
183
195
|
|
|
184
|
-
|
|
185
|
-
|
|
196
|
+
module.exports = {
|
|
197
|
+
generateInstallerFiles,
|
|
198
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dazscript-framework",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"author": "Freddy Diaz",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"description": "",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"prepare": "node ./scripts/install-git-hooks.js",
|
|
9
|
-
"prebuild": "
|
|
10
|
-
"build": "
|
|
11
|
-
"postbuild": "
|
|
12
|
-
"watch": "
|
|
13
|
-
"icons": "
|
|
14
|
-
"installer": "node ./dist/scripts/
|
|
9
|
+
"prebuild": "node ./dist/scripts/cli.js installer --scripts-path ./src/samples --menu-path /DazScriptFramework",
|
|
10
|
+
"build": "node ./dist/scripts/cli.js build --out-dir ./out",
|
|
11
|
+
"postbuild": "node ./dist/scripts/cli.js icons --out-dir ./out",
|
|
12
|
+
"watch": "node ./dist/scripts/cli.js watch --out-dir ./out",
|
|
13
|
+
"icons": "node ./dist/scripts/cli.js icons --out-dir ./out",
|
|
14
|
+
"installer": "node ./dist/scripts/cli.js installer --scripts-path ./src/samples --menu-path /DazScriptFramework"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"dazscript": "./dist/scripts/cli.js"
|
|
15
18
|
},
|
|
16
19
|
"keywords": [
|
|
17
20
|
"daz3d",
|
|
@@ -24,8 +27,7 @@
|
|
|
24
27
|
"exports": {
|
|
25
28
|
"./webpack": "./webpack.config.js",
|
|
26
29
|
"./babel": "./babel.config.js",
|
|
27
|
-
"./
|
|
28
|
-
"./babel/trace-log-babel-plugin": "./dist/babel/trace-log-babel-plugin.js"
|
|
30
|
+
"./config": "./dist/config.js"
|
|
29
31
|
},
|
|
30
32
|
"files": [
|
|
31
33
|
"tsconfig.json",
|
|
@@ -39,33 +41,32 @@
|
|
|
39
41
|
"url": "git+https://github.com/fjdiazt/dazscript-framework.git"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|
|
44
|
+
"dazscript-types": "^0.2.3"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
42
47
|
"@babel/core": "^7.23.2",
|
|
43
48
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
44
49
|
"@babel/plugin-proposal-decorators": "^7.23.2",
|
|
45
50
|
"@babel/plugin-transform-arrow-functions": "^7.22.5",
|
|
46
51
|
"@babel/plugin-transform-block-scoping": "^7.23.0",
|
|
52
|
+
"@babel/plugin-transform-class-properties": "^7.25.9",
|
|
53
|
+
"@babel/plugin-transform-private-methods": "^7.27.1",
|
|
54
|
+
"@babel/plugin-transform-private-property-in-object": "^7.27.1",
|
|
47
55
|
"@babel/preset-env": "^7.23.2",
|
|
48
56
|
"@babel/preset-typescript": "^7.23.2",
|
|
49
|
-
"@babel/types": "^7.26.3",
|
|
50
57
|
"babel-core": "^6.26.3",
|
|
51
58
|
"babel-loader": "^9.1.3",
|
|
52
|
-
"babel-loader-exclude-node-modules-except": "^1.2.1",
|
|
53
59
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
54
60
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
55
|
-
"commander": "^11.1.0",
|
|
56
|
-
"cross-env": "^7.0.3",
|
|
57
|
-
"dazscript-types": "^0.2.3",
|
|
58
61
|
"glob": "^7.2.0",
|
|
59
62
|
"ts-file-parser": "^0.0.21",
|
|
60
63
|
"ts-loader": "^9.5.0",
|
|
61
64
|
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
|
62
65
|
"typescript": "^5.2.2",
|
|
63
|
-
"webpack": "^5.88.2"
|
|
64
|
-
"webpack-cli": "^5.1.4"
|
|
66
|
+
"webpack": "^5.88.2"
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
67
69
|
"@types/node": "^22.10.5",
|
|
68
|
-
"copyfiles": "^2.4.1",
|
|
69
70
|
"eslint": "^9.17.0",
|
|
70
71
|
"typescript": "^5.7.3"
|
|
71
72
|
}
|
|
@@ -17,6 +17,7 @@ export interface HttpRequestOptions {
|
|
|
17
17
|
path: string
|
|
18
18
|
method?: HttpMethod
|
|
19
19
|
connectionMode?: HttpConnectionMode
|
|
20
|
+
timeoutMs?: number
|
|
20
21
|
responseType?: HttpResponseType
|
|
21
22
|
queryString?: string
|
|
22
23
|
headers?: Record<string, string>
|
|
@@ -76,6 +77,9 @@ export const request = <T = any>(options: HttpRequestOptions): HttpResponse<T> =
|
|
|
76
77
|
const http = options.transport ?? new DzHttpHelper()
|
|
77
78
|
http.setConnectionMode(options.connectionMode ?? 'https')
|
|
78
79
|
http.setHost(hostOnly)
|
|
80
|
+
if (typeof http.setTimeoutMs === 'function' && options.timeoutMs && options.timeoutMs > 0) {
|
|
81
|
+
http.setTimeoutMs(options.timeoutMs)
|
|
82
|
+
}
|
|
79
83
|
if (port > 0) {
|
|
80
84
|
http.setPort(port)
|
|
81
85
|
}
|
package/webpack.config.js
CHANGED
|
@@ -3,24 +3,33 @@ const glob = require('glob');
|
|
|
3
3
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
4
4
|
|
|
5
5
|
module.exports = (env, argv) => {
|
|
6
|
+
const projectRoot =
|
|
7
|
+
env && env.context ? path.resolve(env.context) : process.cwd();
|
|
8
|
+
const sourceRoot = path.resolve(projectRoot, 'src');
|
|
6
9
|
const isFileSpecified = env && env.file;
|
|
7
10
|
const entryFiles = isFileSpecified
|
|
8
|
-
? [
|
|
9
|
-
: glob
|
|
11
|
+
? [path.resolve(sourceRoot, `${env.file}.dsa.ts`)]
|
|
12
|
+
: glob
|
|
13
|
+
.sync(path.join(sourceRoot, '**/*.dsa.ts').replace(/\\/g, '/'))
|
|
14
|
+
.map((filePath) => path.resolve(filePath));
|
|
10
15
|
|
|
11
16
|
const outputPath =
|
|
12
17
|
env && env.outputPath
|
|
13
|
-
? path.resolve(env.outputPath)
|
|
18
|
+
? path.resolve(projectRoot, env.outputPath)
|
|
14
19
|
: path.resolve(__dirname, 'out');
|
|
15
20
|
|
|
16
21
|
return {
|
|
22
|
+
context: projectRoot,
|
|
17
23
|
mode: 'production',
|
|
18
24
|
optimization: {
|
|
19
25
|
usedExports: true,
|
|
20
26
|
},
|
|
21
27
|
entry: entryFiles.reduce((acc, filePath) => {
|
|
22
|
-
const entry =
|
|
23
|
-
|
|
28
|
+
const entry = path
|
|
29
|
+
.relative(sourceRoot, filePath)
|
|
30
|
+
.replace(/\\/g, '/')
|
|
31
|
+
.replace('.dsa.ts', '');
|
|
32
|
+
acc[entry] = filePath;
|
|
24
33
|
return acc;
|
|
25
34
|
}, {}),
|
|
26
35
|
module: {
|
|
@@ -30,6 +39,7 @@ module.exports = (env, argv) => {
|
|
|
30
39
|
use: [
|
|
31
40
|
{
|
|
32
41
|
loader: 'babel-loader',
|
|
42
|
+
options: require('./babel.config.js'),
|
|
33
43
|
},
|
|
34
44
|
{
|
|
35
45
|
loader: 'ts-loader',
|
|
@@ -40,7 +50,7 @@ module.exports = (env, argv) => {
|
|
|
40
50
|
],
|
|
41
51
|
exclude: [
|
|
42
52
|
{
|
|
43
|
-
and: [path.resolve(
|
|
53
|
+
and: [path.resolve(projectRoot, 'node_modules')],
|
|
44
54
|
not: [
|
|
45
55
|
path.resolve(__dirname, 'node_modules/dazscript-framework/src'),
|
|
46
56
|
],
|
|
@@ -51,7 +61,18 @@ module.exports = (env, argv) => {
|
|
|
51
61
|
},
|
|
52
62
|
resolve: {
|
|
53
63
|
extensions: ['.ts'],
|
|
54
|
-
plugins: [
|
|
64
|
+
plugins: [
|
|
65
|
+
new TsconfigPathsPlugin({
|
|
66
|
+
configFile: path.resolve(projectRoot, 'tsconfig.json'),
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
resolveLoader: {
|
|
71
|
+
modules: [
|
|
72
|
+
path.resolve(__dirname, 'node_modules'),
|
|
73
|
+
path.resolve(projectRoot, 'node_modules'),
|
|
74
|
+
'node_modules',
|
|
75
|
+
],
|
|
55
76
|
},
|
|
56
77
|
output: {
|
|
57
78
|
filename: '[name].dsa',
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
const t = require('@babel/types');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
let globalEnable = true;
|
|
4
|
-
let enabled = false;
|
|
5
|
-
|
|
6
|
-
function isTraceDecorator(node) {
|
|
7
|
-
return false; // Your existing isTraceDecorator logic
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function isTraceComment(node) {
|
|
11
|
-
return false; // Your existing isTraceComment logic
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function createConsoleLogStatement(
|
|
15
|
-
location,
|
|
16
|
-
filename,
|
|
17
|
-
lineNumber,
|
|
18
|
-
functionName,
|
|
19
|
-
parameters
|
|
20
|
-
) {
|
|
21
|
-
const filenameWithoutPath = path.basename(filename);
|
|
22
|
-
let logMessage = `[TRACE] ${location}: ${filenameWithoutPath}(${lineNumber}): ${functionName}`;
|
|
23
|
-
|
|
24
|
-
if (parameters.length > 0) {
|
|
25
|
-
logMessage += `(${parameters.join(', ')})`;
|
|
26
|
-
} else {
|
|
27
|
-
logMessage += '()';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return t.blockStatement([
|
|
31
|
-
t.expressionStatement(
|
|
32
|
-
t.callExpression(
|
|
33
|
-
t.memberExpression(t.identifier('App'), t.identifier('debug')),
|
|
34
|
-
[t.stringLiteral(logMessage)]
|
|
35
|
-
)
|
|
36
|
-
),
|
|
37
|
-
t.expressionStatement(
|
|
38
|
-
t.callExpression(
|
|
39
|
-
t.memberExpression(t.identifier('App'), t.identifier('flushLogBuffer')),
|
|
40
|
-
[]
|
|
41
|
-
)
|
|
42
|
-
),
|
|
43
|
-
]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function processFunction(enabled, path, state) {
|
|
47
|
-
const filename = state.file.opts.filename || 'unknown';
|
|
48
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
49
|
-
const functionName = path.node.id ? path.node.id.name : 'anonymous';
|
|
50
|
-
const parameters = path.node.params.map((param) => param.name);
|
|
51
|
-
|
|
52
|
-
if (!enabled || functionName === 'anonymous' || lineNumber === 'unknown')
|
|
53
|
-
return;
|
|
54
|
-
|
|
55
|
-
const enteringLogStatement = createConsoleLogStatement(
|
|
56
|
-
'Entering',
|
|
57
|
-
filename,
|
|
58
|
-
lineNumber,
|
|
59
|
-
functionName,
|
|
60
|
-
parameters
|
|
61
|
-
);
|
|
62
|
-
const exitingLogStatement = createConsoleLogStatement(
|
|
63
|
-
'Exiting',
|
|
64
|
-
filename,
|
|
65
|
-
lineNumber,
|
|
66
|
-
functionName,
|
|
67
|
-
parameters
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// Process the return statements within the function body
|
|
71
|
-
path.get('body').traverse({
|
|
72
|
-
ReturnStatement(returnPath) {
|
|
73
|
-
returnPath.insertBefore(exitingLogStatement);
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (enteringLogStatement) {
|
|
78
|
-
if (t.isBlockStatement(path.node.body)) {
|
|
79
|
-
path.node.body.body.unshift(enteringLogStatement);
|
|
80
|
-
} else {
|
|
81
|
-
path.node.body = t.blockStatement([enteringLogStatement, path.node.body]);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function processAssignmentExpression(path, state) {
|
|
87
|
-
const filename = state.file.opts.filename || 'unknown';
|
|
88
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
89
|
-
let functionName = 'anonymous'; // Default value for function name
|
|
90
|
-
const parameters = [];
|
|
91
|
-
|
|
92
|
-
if (!enabled || lineNumber === 'unknown') return;
|
|
93
|
-
|
|
94
|
-
if (t.isMemberExpression(path.node.left)) {
|
|
95
|
-
functionName = path.node.left.property.name;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const enteringLogStatement = createConsoleLogStatement(
|
|
99
|
-
'Entering',
|
|
100
|
-
filename,
|
|
101
|
-
lineNumber,
|
|
102
|
-
functionName,
|
|
103
|
-
parameters
|
|
104
|
-
);
|
|
105
|
-
const exitingLogStatement = createConsoleLogStatement(
|
|
106
|
-
'Exiting',
|
|
107
|
-
filename,
|
|
108
|
-
lineNumber,
|
|
109
|
-
functionName,
|
|
110
|
-
parameters
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Process the return statements within the function body
|
|
114
|
-
path.get('right').traverse({
|
|
115
|
-
ReturnStatement(returnPath) {
|
|
116
|
-
returnPath.insertBefore(exitingLogStatement);
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
t.isFunctionExpression(path.node.right) ||
|
|
122
|
-
t.isArrowFunctionExpression(path.node.right)
|
|
123
|
-
) {
|
|
124
|
-
// Handle the case where the right-hand side is a function expression or arrow function expression
|
|
125
|
-
if (t.isBlockStatement(path.node.right.body)) {
|
|
126
|
-
path.node.right.body.body.unshift(enteringLogStatement);
|
|
127
|
-
path.node.right.body.body.push(exitingLogStatement);
|
|
128
|
-
} else {
|
|
129
|
-
path.node.right.body = t.blockStatement([
|
|
130
|
-
enteringLogStatement,
|
|
131
|
-
t.returnStatement(path.node.right.body),
|
|
132
|
-
exitingLogStatement,
|
|
133
|
-
]);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function processVariableDeclaration(path, state) {
|
|
139
|
-
const filename = state.file.opts.filename || 'unknown';
|
|
140
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
141
|
-
|
|
142
|
-
path.node.declarations.forEach((declarator) => {
|
|
143
|
-
if (
|
|
144
|
-
t.isFunctionExpression(declarator.init) ||
|
|
145
|
-
t.isArrowFunctionExpression(declarator.init)
|
|
146
|
-
) {
|
|
147
|
-
const functionName = declarator.id.name;
|
|
148
|
-
const parameters = declarator.init.params.map((param) => param.name);
|
|
149
|
-
|
|
150
|
-
if (!enabled || lineNumber === 'unknown') return;
|
|
151
|
-
|
|
152
|
-
const enteringLogStatement = createConsoleLogStatement(
|
|
153
|
-
'Entering',
|
|
154
|
-
filename,
|
|
155
|
-
lineNumber,
|
|
156
|
-
functionName,
|
|
157
|
-
parameters
|
|
158
|
-
);
|
|
159
|
-
const exitingLogStatement = createConsoleLogStatement(
|
|
160
|
-
'Exiting',
|
|
161
|
-
filename,
|
|
162
|
-
lineNumber,
|
|
163
|
-
functionName,
|
|
164
|
-
parameters
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
// Ensure the Exiting statement is added to the end of the function body
|
|
168
|
-
if (t.isBlockStatement(declarator.init.body)) {
|
|
169
|
-
declarator.init.body.body.push(exitingLogStatement);
|
|
170
|
-
} else {
|
|
171
|
-
declarator.init.body = t.blockStatement([
|
|
172
|
-
declarator.init.body,
|
|
173
|
-
exitingLogStatement,
|
|
174
|
-
]);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Process the return statements within the function body
|
|
178
|
-
declarator.init.body.body.forEach((statement, index) => {
|
|
179
|
-
if (t.isReturnStatement(statement)) {
|
|
180
|
-
// Add Exiting statement before the return statement
|
|
181
|
-
declarator.init.body.body.splice(index, 0, exitingLogStatement);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Add the Entering statement at the beginning of the function body
|
|
186
|
-
if (t.isBlockStatement(declarator.init.body)) {
|
|
187
|
-
declarator.init.body.body.unshift(enteringLogStatement);
|
|
188
|
-
} else {
|
|
189
|
-
declarator.init.body = t.blockStatement([
|
|
190
|
-
enteringLogStatement,
|
|
191
|
-
t.returnStatement(declarator.init.body),
|
|
192
|
-
]);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
module.exports = function () {
|
|
199
|
-
let declarationFound = false;
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
pre() {
|
|
203
|
-
if (this.opts && typeof this.opts.default === 'boolean') {
|
|
204
|
-
enabled = globalEnable = this.opts.default;
|
|
205
|
-
}
|
|
206
|
-
enabled = globalEnable;
|
|
207
|
-
declarationFound = false;
|
|
208
|
-
},
|
|
209
|
-
visitor: {
|
|
210
|
-
VariableDeclaration(path, state) {
|
|
211
|
-
const declarations = path.node.declarations;
|
|
212
|
-
const traceDeclaration = declarations.find(
|
|
213
|
-
(declaration) => declaration.id.name === 'TRACE'
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
if (!declarationFound) {
|
|
217
|
-
if (traceDeclaration) {
|
|
218
|
-
enabled = traceDeclaration.init
|
|
219
|
-
? traceDeclaration.init.value
|
|
220
|
-
: false;
|
|
221
|
-
declarationFound = true;
|
|
222
|
-
} else {
|
|
223
|
-
enabled = globalEnable;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
processVariableDeclaration(path, state);
|
|
228
|
-
},
|
|
229
|
-
FunctionDeclaration(path, state) {
|
|
230
|
-
//processFunction(path, state);
|
|
231
|
-
},
|
|
232
|
-
FunctionExpression(path, state) {
|
|
233
|
-
processFunction(enabled, path, state);
|
|
234
|
-
},
|
|
235
|
-
ArrowFunctionExpression(path, state) {
|
|
236
|
-
//processFunction(path, state);
|
|
237
|
-
},
|
|
238
|
-
AssignmentExpression(path, state) {
|
|
239
|
-
processAssignmentExpression(path, state);
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
};
|