@winccoa-tools-pack/npm-winccoa-ctrl-code-style 0.1.1 → 0.1.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/LICENSE +21 -21
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/paths.js +67 -0
- package/dist/cjs/paths.js.map +1 -1
- package/dist/cjs/register.js +10 -3
- package/dist/cjs/register.js.map +1 -1
- package/dist/cjs/style-check.js +12 -2
- package/dist/cjs/style-check.js.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/paths.js +67 -0
- package/dist/esm/paths.js.map +1 -1
- package/dist/esm/register.js +10 -3
- package/dist/esm/register.js.map +1 -1
- package/dist/esm/style-check.js +12 -2
- package/dist/esm/style-check.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/paths.d.ts +26 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/register.d.ts.map +1 -1
- package/dist/style-check.d.ts +3 -0
- package/dist/style-check.d.ts.map +1 -1
- package/package.json +1 -1
- package/scripts/check-changelog-version.mjs +37 -37
- package/scripts/fix-esm-imports.mjs +115 -115
- package/scripts/generate-changelog.mjs +190 -190
- package/winccoa/StyleCheck/scripts/astyle.ctl +156 -141
|
@@ -1,142 +1,157 @@
|
|
|
1
|
-
//-----------------------------------------------------------------------------
|
|
2
|
-
/**
|
|
3
|
-
@file $relPath
|
|
4
|
-
@copyright Copyright 2026 winccoa-tools-pack
|
|
5
|
-
SPDX-License-Identifier: MIT
|
|
6
|
-
@brief Run astyle against CTL sources from the worker (source) project.
|
|
7
|
-
@details Resolves astyle.config via getPath (source project, StyleCheck
|
|
8
|
-
sub-project, then WinCC OA installation). Logs via throwError.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
1
|
+
//-----------------------------------------------------------------------------
|
|
2
|
+
/**
|
|
3
|
+
@file $relPath
|
|
4
|
+
@copyright Copyright 2026 winccoa-tools-pack
|
|
5
|
+
SPDX-License-Identifier: MIT
|
|
6
|
+
@brief Run astyle against CTL sources from the worker (source) project.
|
|
7
|
+
@details Resolves astyle.config via getPath (source project, StyleCheck
|
|
8
|
+
sub-project, then WinCC OA installation). Logs via throwError.
|
|
9
|
+
sourcePath must be a full native absolute directory path —
|
|
10
|
+
getFileNamesRecursive does not resolve CWD-relative paths.
|
|
11
|
+
@AIgeneratedHelpContent
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#uses "fileSystem"
|
|
15
|
+
|
|
16
|
+
//-----------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
@brief Emit a CTRL log line via throwError for CI log parsers.
|
|
19
|
+
@param prio Error priority (PRIO_INFO / PRIO_WARNING / PRIO_SEVERE).
|
|
20
|
+
@param text Message text.
|
|
21
|
+
*/
|
|
22
|
+
void logMsg(int prio, const string &text)
|
|
23
|
+
{
|
|
24
|
+
throwError(makeError("", prio, ERR_CONTROL, prio == PRIO_INFO ? 0 : 54, text));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//-----------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
Run astyle for all CTL files below the given source path.
|
|
30
|
+
|
|
31
|
+
@param sourcePath Full native absolute directory to scan for CTL files.
|
|
32
|
+
@param applyChanges If true, format files in place. If false, dry-run only.
|
|
33
|
+
*/
|
|
34
|
+
main(string sourcePath, bool applyChanges = FALSE)
|
|
35
|
+
{
|
|
36
|
+
dyn_string args;
|
|
37
|
+
string stdErr;
|
|
38
|
+
string stdOut;
|
|
39
|
+
|
|
40
|
+
if (sourcePath.isEmpty())
|
|
41
|
+
{
|
|
42
|
+
logMsg(PRIO_SEVERE, "sourcePath must not be empty");
|
|
43
|
+
exit(2);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// getFileNamesRecursive needs a full native path (not CWD-relative).
|
|
47
|
+
sourcePath = makeNativePath(sourcePath);
|
|
48
|
+
|
|
49
|
+
if (!isdir(sourcePath))
|
|
50
|
+
{
|
|
51
|
+
logMsg(PRIO_SEVERE,
|
|
52
|
+
"sourcePath is not an existing directory (need full native path): " +
|
|
53
|
+
sourcePath);
|
|
54
|
+
exit(2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
logMsg(PRIO_INFO, "Scanning CTL sources under: " + sourcePath);
|
|
58
|
+
|
|
59
|
+
dyn_string files = getFileNamesRecursive(sourcePath, "*.ctl");
|
|
60
|
+
dyn_string filesToCheck;
|
|
61
|
+
|
|
62
|
+
for (int i = 1; i <= dynlen(files); i++)
|
|
63
|
+
{
|
|
64
|
+
// Keep full native paths for astyle argv.
|
|
65
|
+
dynAppend(filesToCheck, makeNativePath(files[i]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
int fileCount = dynlen(filesToCheck);
|
|
69
|
+
if (fileCount == 0)
|
|
70
|
+
{
|
|
71
|
+
logMsg(PRIO_WARNING, "No .ctl files found below " + sourcePath);
|
|
72
|
+
exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
string astyleBin = getPath(BIN_REL_PATH, _WIN32 ? "astyle.exe" : "astyle");
|
|
76
|
+
if (astyleBin.isEmpty())
|
|
77
|
+
{
|
|
78
|
+
logMsg(PRIO_SEVERE, "astyle executable not found in WinCC OA bin path");
|
|
79
|
+
exit(2);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Search order: worker project config, StyleCheck sub-project, OA install.
|
|
83
|
+
string optionsFile = getPath(CONFIG_REL_PATH, "astyle.config");
|
|
84
|
+
if (optionsFile.isEmpty())
|
|
85
|
+
{
|
|
86
|
+
logMsg(PRIO_SEVERE, "astyle.config not found via getPath(CONFIG_REL_PATH)");
|
|
87
|
+
exit(2);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
args[1] = astyleBin;
|
|
91
|
+
args[2] = "--options=" + makeNativePath(optionsFile);
|
|
92
|
+
args[3] = "--suffix=none";
|
|
93
|
+
if (!applyChanges)
|
|
94
|
+
args[4] = "--dry-run";
|
|
95
|
+
|
|
96
|
+
dynAppend(args, "--formatted");
|
|
97
|
+
dynAppend(args, filesToCheck);
|
|
98
|
+
|
|
99
|
+
// Cast numerics/bools so CTRL string concat cannot drop the count.
|
|
100
|
+
logMsg(PRIO_INFO,
|
|
101
|
+
"Running astyle on " + (string)fileCount +
|
|
102
|
+
" file(s); applyChanges=" + (string)applyChanges +
|
|
103
|
+
"; options=" + optionsFile);
|
|
104
|
+
|
|
105
|
+
int rc = system(args, stdOut, stdErr);
|
|
106
|
+
|
|
107
|
+
strreplace(stdOut, "\r", "");
|
|
108
|
+
strreplace(stdErr, "\r", "");
|
|
109
|
+
|
|
110
|
+
if (stdOut != "")
|
|
111
|
+
{
|
|
112
|
+
dyn_string lines = strsplit(stdOut, "\n");
|
|
113
|
+
int n = 0;
|
|
114
|
+
for (int i = 1; i <= dynlen(lines); i++)
|
|
115
|
+
{
|
|
116
|
+
const string line = lines[i];
|
|
117
|
+
if (!line.isEmpty())
|
|
118
|
+
{
|
|
119
|
+
n++;
|
|
120
|
+
const int firstSpace = strpos(line, " ");
|
|
121
|
+
string path = firstSpace > 0 ? strltrim(strrtrim(substr(line, firstSpace))) : line;
|
|
122
|
+
logMsg(applyChanges ? PRIO_INFO : PRIO_WARNING, "formatted: " + path);
|
|
123
|
+
|
|
124
|
+
if (applyChanges)
|
|
125
|
+
{
|
|
126
|
+
logMsg(PRIO_INFO, "The file has been formatted: " + path);
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
{
|
|
130
|
+
// keep the \n\tLocation for CI log parsers to detect the file path ;-)
|
|
131
|
+
logMsg(PRIO_WARNING, "The file has wrong formatting, Location:\n\t" + path);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Dry-run must fail when any file would be reformatted.
|
|
137
|
+
if (!applyChanges && n > 0)
|
|
138
|
+
{
|
|
139
|
+
rc = 1;
|
|
140
|
+
logMsg(PRIO_WARNING,
|
|
141
|
+
"astyle found unformatted files: " + (string)n +
|
|
142
|
+
"; return code set to " + (string)rc);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (stdErr != "")
|
|
147
|
+
logMsg(PRIO_WARNING, "astyle stderr:\n" + stdErr);
|
|
148
|
+
|
|
149
|
+
if (rc != 0)
|
|
150
|
+
{
|
|
151
|
+
logMsg(PRIO_SEVERE, "astyle failed with return code " + (string)rc);
|
|
152
|
+
exit(rc);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
logMsg(PRIO_INFO, "astyle completed successfully");
|
|
156
|
+
exit(0);
|
|
142
157
|
}
|