dazscript-framework 0.1.17 → 0.2.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.
- 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 +156 -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/webpack.config.js +28 -7
- package/dist/babel/trace-babel-plugin.js +0 -243
- package/dist/babel/trace-log-babel-plugin.js +0 -164
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
const t = require('@babel/types');
|
|
2
|
-
const pathModule = require('path');
|
|
3
|
-
let globalEnable = true;
|
|
4
|
-
let enabled = false;
|
|
5
|
-
|
|
6
|
-
function wrapWithLogMethod(t, logMethodName, expression) {
|
|
7
|
-
return t.callExpression(
|
|
8
|
-
t.memberExpression(t.identifier('log'), t.identifier(logMethodName)),
|
|
9
|
-
[t.stringLiteral(expression)]
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createLogMessage(path) {
|
|
14
|
-
// Ensure that the parent is a function before accessing its name
|
|
15
|
-
if (
|
|
16
|
-
t.isFunctionDeclaration(path.parent) ||
|
|
17
|
-
t.isFunctionExpression(path.parent)
|
|
18
|
-
) {
|
|
19
|
-
const functionName = path.parent.id ? path.parent.id.name : 'anonymous';
|
|
20
|
-
const filename = path.hub.file.opts.filename || 'unknown';
|
|
21
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
22
|
-
const filenameWithoutPath = pathModule.basename(filename);
|
|
23
|
-
|
|
24
|
-
return `${filenameWithoutPath}.${functionName}(${lineNumber + 2}): ${
|
|
25
|
-
path.node.arguments[0].value
|
|
26
|
-
}`;
|
|
27
|
-
} else {
|
|
28
|
-
// If the parent is not a function, use "anonymous"
|
|
29
|
-
const filename = path.hub.file.opts.filename || 'unknown';
|
|
30
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
31
|
-
const filenameWithoutPath = pathModule.basename(filename);
|
|
32
|
-
const lineNumberStr = lineNumber === 'unknown' ? '' : `(${lineNumber + 2})`;
|
|
33
|
-
|
|
34
|
-
return `${filenameWithoutPath}${lineNumberStr}: ${path.node.arguments[0].value}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function isNonStringLiteralOrTemplateLiteral(node) {
|
|
39
|
-
// Check if the node is not a string literal or is a template literal
|
|
40
|
-
return !(t.isStringLiteral(node) || t.isTemplateLiteral(node));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function replaceLogStatements(path, logMethodName) {
|
|
44
|
-
if (!enabled) return;
|
|
45
|
-
if (t.isCallExpression(path.node) && !path.node.processed) {
|
|
46
|
-
const callee = path.node.callee;
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
isNonStringLiteralOrTemplateLiteral(path.node.arguments[0]) &&
|
|
50
|
-
t.isIdentifier(callee) &&
|
|
51
|
-
callee.name === logMethodName
|
|
52
|
-
) {
|
|
53
|
-
// Handle non-string literal or template literal here
|
|
54
|
-
const functionName = path.parent.id ? `.${path.parent.id.name}` : '';
|
|
55
|
-
const filename = path.hub.file.opts.filename || 'unknown';
|
|
56
|
-
const lineNumber = path.node.loc?.start?.line || 'unknown';
|
|
57
|
-
const filenameWithoutPath = pathModule.basename(filename);
|
|
58
|
-
|
|
59
|
-
let logMessage = `[TRACE] ${filenameWithoutPath}${functionName}(${
|
|
60
|
-
lineNumber + 2
|
|
61
|
-
})`;
|
|
62
|
-
|
|
63
|
-
const logLine = t.blockStatement([
|
|
64
|
-
t.expressionStatement(
|
|
65
|
-
t.callExpression(
|
|
66
|
-
t.memberExpression(t.identifier('App'), t.identifier('debug')),
|
|
67
|
-
[t.stringLiteral(logMessage)]
|
|
68
|
-
)
|
|
69
|
-
),
|
|
70
|
-
t.expressionStatement(
|
|
71
|
-
t.callExpression(
|
|
72
|
-
t.memberExpression(
|
|
73
|
-
t.identifier('App'),
|
|
74
|
-
t.identifier('flushLogBuffer')
|
|
75
|
-
),
|
|
76
|
-
[]
|
|
77
|
-
)
|
|
78
|
-
),
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
path.insertBefore(logLine);
|
|
82
|
-
path.node.processed = true;
|
|
83
|
-
} else if (
|
|
84
|
-
t.isMemberExpression(callee) &&
|
|
85
|
-
t.isIdentifier(callee.object, { name: 'log' })
|
|
86
|
-
) {
|
|
87
|
-
// It's log.debug or similar, wrap it with wrapWithLogMethod
|
|
88
|
-
const logMessage = createLogMessage(path, logMethodName);
|
|
89
|
-
path.replaceWith(wrapWithLogMethod(t, logMethodName, logMessage));
|
|
90
|
-
path.node.processed = true;
|
|
91
|
-
} else if (t.isIdentifier(callee) && callee.name === logMethodName) {
|
|
92
|
-
// It's just the specified method, update the argument directly
|
|
93
|
-
path.node.arguments[0].value = createLogMessage(path, logMethodName);
|
|
94
|
-
path.node.processed = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = function () {
|
|
100
|
-
let declarationFound = false;
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
pre() {
|
|
104
|
-
if (this.opts && typeof this.opts.default === 'boolean') {
|
|
105
|
-
enabled = globalEnable = this.opts.default;
|
|
106
|
-
}
|
|
107
|
-
enabled = globalEnable;
|
|
108
|
-
declarationFound = false;
|
|
109
|
-
},
|
|
110
|
-
visitor: {
|
|
111
|
-
VariableDeclaration(path, state) {
|
|
112
|
-
const declarations = path.node.declarations;
|
|
113
|
-
const traceDeclaration = declarations.find(
|
|
114
|
-
(declaration) => declaration.id.name === 'TRACE'
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (!declarationFound) {
|
|
118
|
-
if (traceDeclaration) {
|
|
119
|
-
enabled = traceDeclaration.init
|
|
120
|
-
? traceDeclaration.init.value
|
|
121
|
-
: false;
|
|
122
|
-
declarationFound = true;
|
|
123
|
-
} else {
|
|
124
|
-
enabled = globalEnable;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
FunctionDeclaration(path, state) {
|
|
129
|
-
path.traverse({
|
|
130
|
-
CallExpression(callPath) {
|
|
131
|
-
//replaceLogStatements(callPath, 'trace');
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
FunctionExpression(path, state) {
|
|
136
|
-
path.traverse({
|
|
137
|
-
CallExpression(callPath) {
|
|
138
|
-
replaceLogStatements(callPath, 'debug');
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
path.traverse({
|
|
142
|
-
CallExpression(callPath) {
|
|
143
|
-
replaceLogStatements(callPath, 'error');
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
path.traverse({
|
|
147
|
-
CallExpression(callPath) {
|
|
148
|
-
replaceLogStatements(callPath, 'info');
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
path.traverse({
|
|
152
|
-
CallExpression(callPath) {
|
|
153
|
-
replaceLogStatements(callPath, 'dump');
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
path.traverse({
|
|
157
|
-
CallExpression(callPath) {
|
|
158
|
-
replaceLogStatements(callPath, 'trace');
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
};
|