@winccoa-tools-pack/npm-winccoa-ctrl-code-style 0.1.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/dist/cjs/cli.js +204 -0
  4. package/dist/cjs/cli.js.map +1 -0
  5. package/dist/cjs/index.js +29 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/paths.js +50 -0
  8. package/dist/cjs/paths.js.map +1 -0
  9. package/dist/cjs/register.js +154 -0
  10. package/dist/cjs/register.js.map +1 -0
  11. package/dist/cjs/style-check.js +110 -0
  12. package/dist/cjs/style-check.js.map +1 -0
  13. package/dist/cjs/types.js +3 -0
  14. package/dist/cjs/types.js.map +1 -0
  15. package/dist/cli.d.ts +15 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/esm/cli.js +204 -0
  18. package/dist/esm/cli.js.map +1 -0
  19. package/dist/esm/index.js +29 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/paths.js +50 -0
  22. package/dist/esm/paths.js.map +1 -0
  23. package/dist/esm/register.js +154 -0
  24. package/dist/esm/register.js.map +1 -0
  25. package/dist/esm/style-check.js +110 -0
  26. package/dist/esm/style-check.js.map +1 -0
  27. package/dist/esm/types.js +3 -0
  28. package/dist/esm/types.js.map +1 -0
  29. package/dist/index.d.ts +13 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/paths.d.ts +16 -0
  32. package/dist/paths.d.ts.map +1 -0
  33. package/dist/register.d.ts +49 -0
  34. package/dist/register.d.ts.map +1 -0
  35. package/dist/style-check.d.ts +31 -0
  36. package/dist/style-check.d.ts.map +1 -0
  37. package/dist/types.d.ts +71 -0
  38. package/dist/types.d.ts.map +1 -0
  39. package/package.json +68 -0
  40. package/scripts/approve-open-pr-workflows.sh +85 -0
  41. package/scripts/check-changelog-version.mjs +37 -0
  42. package/scripts/fix-esm-imports.mjs +115 -0
  43. package/scripts/generate-changelog.mjs +190 -0
  44. package/scripts/register-stylecheck-projects.ps1 +92 -0
  45. package/scripts/register-stylecheck-projects.sh +193 -0
  46. package/scripts/run-node-tests.ts +74 -0
  47. package/scripts/wait-for-winccoa.sh +26 -0
  48. package/winccoa/StyleCheck/scripts/astyle.ctl +142 -0
@@ -0,0 +1,142 @@
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
+ @AIgeneratedHelpContent
10
+ */
11
+
12
+ #uses "fileSystem"
13
+
14
+ //-----------------------------------------------------------------------------
15
+ /**
16
+ @brief Emit a CTRL log line via throwError for CI log parsers.
17
+ @param prio Error priority (PRIO_INFO / PRIO_WARNING / PRIO_SEVERE).
18
+ @param text Message text.
19
+ */
20
+ void logMsg(int prio, const string &text)
21
+ {
22
+ throwError(makeError("", prio, ERR_CONTROL, prio == PRIO_INFO ? 0 : 54, text));
23
+ }
24
+
25
+ //-----------------------------------------------------------------------------
26
+ /**
27
+ Run astyle for all CTL files below the given source path.
28
+
29
+ @param sourcePath Directory to scan recursively for CTL files.
30
+ @param applyChanges If true, format files in place. If false, dry-run only.
31
+ */
32
+ main(string sourcePath, bool applyChanges = FALSE)
33
+ {
34
+ dyn_string args;
35
+ string stdErr;
36
+ string stdOut;
37
+
38
+ if (sourcePath.isEmpty())
39
+ {
40
+ logMsg(PRIO_SEVERE, "sourcePath must not be empty");
41
+ exit(2);
42
+ }
43
+
44
+ dyn_string files = getFileNamesRecursive(sourcePath, "*.ctl");
45
+ dyn_string filesToCheck;
46
+
47
+ for (int i = 1; i <= dynlen(files); i++)
48
+ {
49
+ const string path = makeUnixPath(files[i]);
50
+ dynAppend(filesToCheck, makeNativePath(path));
51
+ }
52
+
53
+ if (dynlen(filesToCheck) == 0)
54
+ {
55
+ logMsg(PRIO_WARNING, "No .ctl files found below " + sourcePath);
56
+ exit(1);
57
+ }
58
+
59
+ string astyleBin = getPath(BIN_REL_PATH, _WIN32 ? "astyle.exe" : "astyle");
60
+ if (astyleBin.isEmpty())
61
+ {
62
+ logMsg(PRIO_SEVERE, "astyle executable not found in WinCC OA bin path");
63
+ exit(2);
64
+ }
65
+
66
+ // Search order: worker project config, StyleCheck sub-project, OA install.
67
+ string optionsFile = getPath(CONFIG_REL_PATH, "astyle.config");
68
+ if (optionsFile.isEmpty())
69
+ {
70
+ logMsg(PRIO_SEVERE, "astyle.config not found via getPath(CONFIG_REL_PATH)");
71
+ exit(2);
72
+ }
73
+
74
+ args[1] = astyleBin;
75
+ args[2] = "--options=" + makeNativePath(optionsFile);
76
+ args[3] = "--suffix=none";
77
+ if (!applyChanges)
78
+ args[4] = "--dry-run";
79
+
80
+ dynAppend(args, "--formatted");
81
+ dynAppend(args, filesToCheck);
82
+
83
+ logMsg(PRIO_INFO,
84
+ "Running astyle on " + dynlen(filesToCheck) +
85
+ " file(s); applyChanges=" + applyChanges +
86
+ "; options=" + optionsFile);
87
+
88
+ int rc = system(args, stdOut, stdErr);
89
+
90
+ strreplace(stdOut, "\r", "");
91
+ strreplace(stdErr, "\r", "");
92
+
93
+ if (stdOut != "")
94
+ {
95
+ dyn_string lines = strsplit(stdOut, "\n");
96
+ int n = 0;
97
+ for (int i = 1; i <= dynlen(lines); i++)
98
+ {
99
+ const string line = lines[i];
100
+ if (!line.isEmpty())
101
+ {
102
+ n++;
103
+ const int firstSpace = strpos(line, " ");
104
+ string path = firstSpace > 0 ? strltrim(strrtrim(substr(line, firstSpace))) : line;
105
+ logMsg(applyChanges ? PRIO_INFO : PRIO_WARNING, "formatted: " + path);
106
+
107
+ if (applyChanges)
108
+ {
109
+ logMsg(PRIO_INFO, "The file has been formatted: " + path);
110
+ }
111
+ else
112
+ {
113
+ // keep the \n\tLocation for CI log parsers to detect the file path ;-)
114
+ logMsg(PRIO_WARNING, "The file has wrong formatting, Location:\n\t" + path);
115
+ }
116
+ }
117
+ }
118
+
119
+
120
+
121
+ // Dry-run must fail when any file would be reformatted.
122
+ if (!applyChanges && n > 0)
123
+ {
124
+ rc = 1;
125
+ logMsg(PRIO_WARNING,
126
+ "astyle found unformatted files: " + n +
127
+ "; return code set to " + rc);
128
+ }
129
+ }
130
+
131
+ if (stdErr != "")
132
+ logMsg(PRIO_WARNING, "astyle stderr:\n" + stdErr);
133
+
134
+ if (rc != 0)
135
+ {
136
+ logMsg(PRIO_SEVERE, "astyle failed with return code " + rc);
137
+ exit(rc);
138
+ }
139
+
140
+ logMsg(PRIO_INFO, "astyle completed successfully");
141
+ exit(0);
142
+ }