@dbwebb/databas 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kursen webtec
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @dbwebb/databas CLI
2
+
3
+ A cli to work with the course databas, for students and staff.
4
+
5
+
6
+
7
+ ## Install
8
+
9
+ You can install the tool through npm as this.
10
+
11
+ ```bash
12
+ npm i @dbwebb/databas --save-dev
13
+ ```
14
+
15
+
16
+
17
+ ### Update
18
+
19
+ You can update to the latest version like this.
20
+
21
+ ```bash
22
+ npm update @dbwebb/databas@latest
23
+ ```
24
+
25
+
26
+
27
+ ## Execute the `check` command
28
+
29
+ You can execute the command like this and the result is a helptext on how to use the command.
30
+
31
+ ```bash
32
+ npx @dbwebb/databas check <kmom>
33
+ ```
34
+
35
+ The following commands are supported.
36
+
37
+ ```bash
38
+ npx @dbwebb/databas check labbmiljo
39
+ npx @dbwebb/databas check kmom01
40
+ npx @dbwebb/databas check kmom02
41
+ npx @dbwebb/databas check kmom03
42
+ npx @dbwebb/databas check kmom04
43
+ npx @dbwebb/databas check kmom05
44
+ npx @dbwebb/databas check kmom06
45
+ npx @dbwebb/databas check kmom07
46
+ npx @dbwebb/databas check kmom08
47
+ npx @dbwebb/databas check kmom10
48
+ ```
49
+
50
+ When you run kmom01, it will also check labbmiljo.
51
+
52
+ When you run kmom02, it will also check kmom01 and labbmiljo (and so on).
53
+
54
+ You can get a helptext like this.
55
+
56
+ ```bash
57
+ npx @dbwebb/databas check --help
58
+ ```
59
+
60
+
61
+ <!--
62
+ ### Execute subcommand `check lab`
63
+
64
+ This command prints out the summary row from a lab and visualises the points on each lab. This is used to show a summary of the points of several labs.
65
+
66
+ You can use it like this to show the results from one lab.
67
+
68
+ ```
69
+ # Show the result from one lab
70
+ npx @dbwebb/databas check lab lab_01
71
+ ```
72
+
73
+ You can use it like this to show the results from several labs.
74
+
75
+ ```
76
+ # Show the result from one lab
77
+ npx @dbwebb/databas check lab lab_01 lab_02
78
+ ```
79
+ -->
80
+
81
+
82
+
83
+ <!--
84
+ ## To be done
85
+
86
+ These will be supported but are yet not implemented.
87
+
88
+ ```bash
89
+ npx @dbwebb/databas check kmom04
90
+ npx @dbwebb/databas check kmom05
91
+ npx @dbwebb/databas check kmom06
92
+ npx @dbwebb/databas check kmom10
93
+ ```
94
+ -->
95
+
96
+
97
+
98
+ <!--
99
+ ## Developer
100
+
101
+ Use `npm link` to make a local link to the scripts. Then run like this.
102
+
103
+ ```bash
104
+ check-files
105
+ help
106
+ ```
107
+ -->
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ import fs from "fs";
3
+ //import acorn from "acorn";
4
+ import * as acorn from "acorn";
5
+
6
+ // Läs in argument
7
+ const [,, filePath, functionName] = process.argv;
8
+
9
+ if (!filePath || !functionName) {
10
+ console.error("❌ Användning: node checkFunction.js <filväg> <funktionsnamn>");
11
+ process.exit(1);
12
+ }
13
+
14
+ // Läs in filen
15
+ const code = fs.readFileSync(filePath, "utf-8");
16
+
17
+ // Parsa till AST
18
+ const ast = acorn.parse(code, { ecmaVersion: "latest", sourceType: "module" });
19
+
20
+ let found = false;
21
+
22
+ // Enkel rekursiv traversering av AST
23
+ function walk(node) {
24
+ if (!node) return;
25
+
26
+ // Kolla olika typer av deklarationer
27
+ if (node.type === "FunctionDeclaration" && node.id?.name === functionName) {
28
+ found = true;
29
+ }
30
+
31
+ if (node.type === "VariableDeclarator" && node.id.name === functionName) {
32
+ found = true;
33
+ }
34
+
35
+ if (node.type === "Property" && node.key.name === functionName) {
36
+ found = true;
37
+ }
38
+
39
+ if (node.type === "MethodDefinition" && node.key.name === functionName) {
40
+ found = true;
41
+ }
42
+
43
+ // Gå igenom alla undernoder
44
+ for (const key in node) {
45
+ const val = node[key];
46
+ if (Array.isArray(val)) val.forEach(walk);
47
+ else if (val && typeof val === "object") walk(val);
48
+ }
49
+ }
50
+
51
+ walk(ast);
52
+
53
+ if (found) {
54
+ console.log(`✅ Funktionen '${functionName}()' hittad i ${filePath}`);
55
+ process.exit(0);
56
+ } else {
57
+ console.log(`❌ Funktionen '${functionName}()' saknas i ${filePath}`);
58
+ process.exit(1);
59
+ }
@@ -0,0 +1,839 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Check that the repo contains whats expected.
4
+ #
5
+ # Exit values:
6
+ # 0 on success
7
+ # 1 on failure
8
+ #
9
+
10
+
11
+
12
+ # Name of the script
13
+ #SCRIPT=$( basename "$0" )
14
+
15
+ ##
16
+ # Message to display for version.
17
+ #
18
+ version ()
19
+ {
20
+ local txt=(
21
+ "$SCRIPT version $VERSION"
22
+ )
23
+
24
+ printf "%s\\n" "${txt[@]}"
25
+ }
26
+
27
+
28
+
29
+ ##
30
+ # Message to display for usage and help.
31
+ #
32
+ usage ()
33
+ {
34
+ local txt=(
35
+ "Check that your repo contains the essentials for each part of the course."
36
+ "Usage: $SCRIPT check [options] <command> [arguments]"
37
+ ""
38
+ "Command:"
39
+ " eslint Checks executed by eslint."
40
+ " lab <lab_01 lab_02 lab_03 lab_04> Checks and prints the specified labs."
41
+ " labbmiljo Checks related to the labbmiljö."
42
+ " kmom01 Checks related to kmom01."
43
+ " kmom02 Checks related to kmom02."
44
+ " kmom03 Checks related to kmom03."
45
+ " kmom04 Checks related to kmom04."
46
+ " kmom05 Checks related to kmom05."
47
+ " kmom06 Checks related to kmom06."
48
+ " kmom10 Checks related to kmom10."
49
+ ""
50
+ "Options:"
51
+ " --eslint-fix Run eslint fix to see if some validation errors disappear."
52
+ " --only-this Check only the specific kmom, no previous ones."
53
+ " --no-branch Ignore checking branches."
54
+ " --no-color Do not colourize the output."
55
+ " --no-eslint Ignore checking with eslint."
56
+ " --pass-lab Run the lab towards the solution file to pass the check."
57
+ " --help, -h Print help."
58
+ " --version, -h Print version."
59
+ )
60
+
61
+ printf "%s\\n" "${txt[@]}"
62
+ }
63
+
64
+
65
+
66
+ ##
67
+ # Message to display when bad usage.
68
+ #
69
+ badUsage ()
70
+ {
71
+ local message="$1"
72
+ local txt=(
73
+ "For an overview of the command, execute:"
74
+ "$SCRIPT --help"
75
+ )
76
+
77
+ [[ -n $message ]] && printf "%s\\n" "$message"
78
+
79
+ printf "%s\\n" "${txt[@]}" >&2
80
+ exit 1
81
+ }
82
+
83
+
84
+
85
+ ##
86
+ # Error while processing
87
+ #
88
+ # @param string $* error message to display.
89
+ #
90
+ fail ()
91
+ {
92
+ local color
93
+ local normal
94
+
95
+ color=$(tput setaf 1)
96
+ normal=$(tput sgr0)
97
+
98
+ printf "%s $*\\n" "${color}[FAILED]${normal}"
99
+ exit 2
100
+ }
101
+
102
+
103
+
104
+ ##
105
+ # Open an url in the default browser
106
+ #
107
+ # @arg1 the url
108
+ #
109
+ function openUrl {
110
+ local url="$1"
111
+
112
+ #printf "$url\n"
113
+ eval "$WEB_BROWSER \"$url\"" 2>/dev/null &
114
+ sleep 0.5
115
+ }
116
+
117
+
118
+
119
+ ##
120
+ # Check if the git tag is between two versions
121
+ # >=@arg2 and <@arg3
122
+ #
123
+ # @arg1 string the path to the dir to check.
124
+ # @arg2 string the lowest version number to check.
125
+ # @arg3 string the highest version number to check.
126
+ #
127
+ hasGitTagBetween()
128
+ {
129
+ local where="$1"
130
+ local low=
131
+ local high=
132
+ local semTag=
133
+
134
+ low=$( getSemanticVersion "$2" )
135
+ high=$( getSemanticVersion "$3" )
136
+ #echo "Validate that tag exists >=$2 and <$3 ."
137
+
138
+ local success=false
139
+ local highestTag=0
140
+ local highestSemTag=0
141
+
142
+ if [ -d "$where" ]; then
143
+ while read -r tag; do
144
+ semTag=$( getSemanticVersion "$tag" )
145
+ #echo "trying tag $tag = $semTag"
146
+ if [ $semTag -ge $low -a $semTag -lt $high ]; then
147
+ #echo "success with $tag"
148
+ success=
149
+ if [ $semTag -gt $highestSemTag ]; then
150
+ highestTag=$tag
151
+ highestSemTag=$semTag
152
+ fi
153
+ fi
154
+ done < <( cd "$where" && git tag )
155
+ fi
156
+
157
+ if [ "$success" = "false" ]; then
158
+ printf "$MSG_FAILED Failed to validate tag exists >=%s and <%s." "$2" "$3"
159
+ return 1
160
+ fi
161
+
162
+ echo "$highestTag"
163
+ }
164
+
165
+
166
+
167
+ ##
168
+ # Convert version to a comparable string
169
+ # Works for 1.0.0 and v1.0.0
170
+ #
171
+ # @arg1 string the version to check.
172
+ #
173
+ function getSemanticVersion
174
+ {
175
+ #local version=${1:1}
176
+ local version=
177
+
178
+ version=$( echo $1 | sed s/^[vV]// )
179
+ echo "$version" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'
180
+ }
181
+
182
+
183
+
184
+ ##
185
+ # Check if paths (files and dirs) exists.
186
+ #
187
+ # param array of paths
188
+ #
189
+ check_paths ()
190
+ {
191
+ local array_name="$1"
192
+ local verbose="$2"
193
+ local paths=("${!array_name}")
194
+ local success=0
195
+
196
+ for path in "${paths[@]}"; do
197
+ if [[ -e "$path" ]]; then
198
+ [[ -n "$verbose" ]] && echo "✅ $path"
199
+ else
200
+ [[ -n "$verbose" ]] && echo "❌ $path"
201
+ success=1
202
+ fi
203
+ done
204
+
205
+ return $success
206
+ }
207
+
208
+
209
+
210
+ ##
211
+ # Check if a set of branches exists in the repo.
212
+ #
213
+ check_branches ()
214
+ {
215
+ local verbose="$1"
216
+ local branches=(
217
+ "main"
218
+ "bth/submit/kmom03"
219
+ "bth/submit/kmom06"
220
+ "bth/submit/kmom10"
221
+ )
222
+ local success=0
223
+
224
+ (( NO_BRANCH )) && return 0
225
+
226
+ for branch in "${branches[@]}"; do
227
+ if git show-ref --verify --quiet "refs/heads/$branch"; then
228
+ [[ -n "$verbose" ]] && echo "✅ $branch finns lokalt"
229
+ else
230
+ [[ -n "$verbose" ]] && echo "❌ $branch saknas lokalt"
231
+ success=1
232
+ fi
233
+
234
+ # Remote branches
235
+ # if git ls-remote --heads origin "$branch" | grep -q "$branch"; then
236
+ # [[ -n "$verbose" ]] && echo "✅ $branch finns i din remote"
237
+ # else
238
+ # [[ -n "$verbose" ]] && echo "❌ $branch saknas i din remote"
239
+ # success=1
240
+ # fi
241
+ done
242
+
243
+ return $success
244
+ }
245
+
246
+
247
+
248
+ ##
249
+ # Check paths for a kmom
250
+ #
251
+ kmom_check_paths ()
252
+ {
253
+ local silent="$1"
254
+ local pathArray="$2"
255
+ local success=0
256
+
257
+ check_paths "$pathArray" || ([[ ! $silent ]] && check_paths "$pathArray" verbose)
258
+ if (( $? == 0 )); then
259
+ [[ $silent ]] || echo "✅ 😀 $kmom alla kataloger/filer finns på plats."
260
+ else
261
+ [[ $silent ]] || echo "🚫 🔧 $kmom någon katalog/fil saknas eller har fel namn, fixa det."
262
+ success=1
263
+ fi
264
+
265
+ return $success
266
+ }
267
+
268
+
269
+
270
+ ##
271
+ # Check git repo has a tag
272
+ #
273
+ kmom_check_tag ()
274
+ {
275
+ local silent="$1"
276
+ local kmom="$2"
277
+ local tagMin="$3"
278
+ local tagMax="$4"
279
+ local dir="."
280
+ local success=0
281
+ local res=
282
+
283
+ res=$( hasGitTagBetween "$dir" "$tagMin" "$tagMax" )
284
+ if (( $? == 0 )); then
285
+ [[ $silent ]] || echo "✅ 😀 $kmom repot har tagg $res."
286
+ else
287
+ [[ $silent ]] || echo "🚫 🔧 $kmom repot saknar tagg >=$3 and <$4, fixa det."
288
+ success=1
289
+ fi
290
+
291
+ return $success
292
+ }
293
+
294
+
295
+
296
+ ##
297
+ # Check repo passes eslint
298
+ #
299
+ kmom_eslint ()
300
+ {
301
+ local silent="$1"
302
+ local kmom="$2"
303
+ local path="$3"
304
+ local success=0
305
+ local res=
306
+
307
+ (( NO_ESLINT )) && return 0
308
+
309
+ res=$( npx eslint "$path" )
310
+ if (( $? == 0 )); then
311
+ [[ $silent ]] || echo "✅ 😀 $kmom eslint passerar."
312
+ else
313
+ [[ $silent ]] || echo "🚫 🔧 $kmom eslint hittade fel, kör eslint mot $path och fixa det."
314
+ if [[ $ESLINT_FIX ]]; then
315
+ [[ $silent ]] || echo "$res" | tail -1
316
+ [[ $silent ]] || printf "\n🙈 🔧 Försöker laga felen med 'eslint --fix och provar igen...\n"
317
+ res=$( npx eslint "$path" --fix )
318
+ res=$( npx eslint "$path" )
319
+ if (( $? == 0 )); then
320
+ [[ $silent ]] || echo "✅ 😀 $kmom eslint passerar."
321
+ fi
322
+ fi
323
+ [[ $VERBOSE ]] && echo "$res"
324
+ success=1
325
+ fi
326
+
327
+ return $success
328
+ }
329
+
330
+
331
+
332
+ ##
333
+ # Check labs in a kmom
334
+ #
335
+ kmom_check_lab ()
336
+ {
337
+ local silent="$1"
338
+ local kmom="$2"
339
+ local lab="$3"
340
+ local success=0
341
+ local res=
342
+
343
+ [[ -d lab/$lab ]] || return 0
344
+ res=$( cd "lab/$lab" || return 0; node lab "$PASS_LAB" )
345
+ res=$?
346
+ if (( res >= 21 )); then
347
+ [[ $silent ]] || echo "✅ 🙌 $kmom $lab imponerar med ${res}p."
348
+ elif (( res >= 19 )); then
349
+ [[ $silent ]] || echo "✅ 😍 $kmom $lab väl godkänd med ${res}p."
350
+ elif (( res >= 15 )); then
351
+ [[ $silent ]] || echo "✅ 😁 $kmom $lab passerar med ${res}p."
352
+ else
353
+ [[ $silent ]] || echo "🚫 🔧 $kmom $lab med ${res}p passerar inte gränsen för godkänt, fixa det."
354
+ success=1
355
+ fi
356
+
357
+ return $success
358
+ }
359
+
360
+
361
+
362
+ ##
363
+ # Do tests for a kmom.
364
+ #
365
+ kmom_do ()
366
+ {
367
+ local success=0
368
+ local silent="$1"
369
+ local previous_kmom="$2"
370
+ local kmom="$3"
371
+ local pathArray="$4"
372
+ local versionMin="$5"
373
+ local versionMax="$6"
374
+ local lab="$7"
375
+
376
+ if [[ ! $ONLY_THIS ]]; then
377
+ app_"$previous_kmom" silent
378
+ (( $? != 0 )) && success=2
379
+ fi
380
+
381
+ kmom_check_paths "$silent" "$pathArray"
382
+ (( $? != 0 )) && success=1
383
+
384
+ kmom_check_tag "$silent" "$kmom" "$versionMin" "$versionMax"
385
+ (( $? != 0 )) && success=1
386
+
387
+ if [[ $lab ]]; then
388
+ kmom_check_lab "$silent" "$kmom" "$lab"
389
+ (( $? != 0 )) && success=1
390
+ fi
391
+
392
+ if [[ ! $silent ]]; then
393
+ if [[ $kmom != "labbmiljo" ]]; then
394
+ kmom_eslint "$silent" "$kmom" "public/"
395
+ (( $? != 0 )) && success=1
396
+ fi
397
+ fi
398
+
399
+ # Räkna antalet commits
400
+ # npx http-server och testa de routes som skall fungera
401
+
402
+ kmom_summary "$silent" $success "$kmom"
403
+ }
404
+
405
+
406
+
407
+ ##
408
+ # Print the summary for each kmom.
409
+ #
410
+ kmom_summary ()
411
+ {
412
+ local silent="$1"
413
+ local success=$2
414
+ local kmom="$3"
415
+
416
+ if [[ $silent ]]; then
417
+ if (( success == 0)); then
418
+ echo "✅ 😎 $kmom OK."
419
+ else
420
+ echo "🚫 🔧 $kmom något saknas, kör en egen rapport för $kmom och fixa det."
421
+ fi
422
+ fi
423
+ }
424
+
425
+
426
+
427
+ ##
428
+ # Define paths needed for each kmom
429
+ #
430
+ PATHS_LABBMILJO=(
431
+ ".editorconfig"
432
+ ".gitignore"
433
+ "package.json"
434
+ "README.md"
435
+ )
436
+
437
+ PATHS_KMOM01=(
438
+ "lab/"
439
+ "lab/lab_01/"
440
+ "public/"
441
+ "public/css/"
442
+ "public/css/style.css"
443
+ "public/js/"
444
+ "public/js/hello.js"
445
+ "public/about.html"
446
+ "public/me.html"
447
+ "public/report.html"
448
+ )
449
+
450
+ PATHS_KMOM02=(
451
+ "lab/"
452
+ "lab/lab_02/"
453
+ "public/css/responsive-design.css"
454
+ "public/js/responsive-design.js"
455
+ )
456
+
457
+ PATHS_KMOM03=(
458
+ "lab/"
459
+ "lab/lab_03/"
460
+ "public/onepage.html"
461
+ "public/css/onepage.css"
462
+ "public/js/onepage.js"
463
+ )
464
+
465
+ PATHS_KMOM04=(
466
+ "lab/"
467
+ "lab/lab_04/"
468
+ "public/dom.html"
469
+ "public/css/dom.css"
470
+ "public/js/dom.js"
471
+ )
472
+
473
+ PATHS_KMOM05=(
474
+ "public/fetch.html"
475
+ "public/css/fetch.css"
476
+ "public/js/fetch.js"
477
+ )
478
+
479
+ PATHS_KMOM06=(
480
+ "public/duckhunt.html"
481
+ "public/css/duckhunt.css"
482
+ "public/js/duckhunt.js"
483
+ )
484
+
485
+ PATHS_KMOM10=(
486
+ "public/project.html"
487
+ "public/css/project.css"
488
+ "public/js/project.js"
489
+ )
490
+
491
+
492
+
493
+ ##
494
+ # Check using eslint.
495
+ #
496
+ app_eslint ()
497
+ {
498
+ local target="${1:-public}"
499
+
500
+ kmom_eslint "" "" "$target"
501
+ return $?
502
+ }
503
+
504
+
505
+
506
+ ##
507
+ # Check the labs.
508
+ #
509
+ app_lab ()
510
+ {
511
+ local success=0
512
+ local res=
513
+ local ret=
514
+
515
+ for lab in "$@"; do
516
+ if [[ -d lab/$lab ]]; then
517
+ res=$( cd "lab/$lab" || return 0; node lab "$PASS_LAB" )
518
+ ret=$?
519
+ res=$(echo "$res" | tail -3 | head -1)
520
+ res=${res:2}
521
+ else
522
+ res="directory is missing"
523
+ ret=0
524
+ fi
525
+
526
+ [[ $NO_COLOR ]] && res=$( echo "$res" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" )
527
+
528
+ if (( ret >= 21 )); then
529
+ echo "✅ 🙌 $lab $res ${ret}p."
530
+ elif (( ret >= 19 )); then
531
+ echo "✅ 😍 $lab $res ${ret}p."
532
+ elif (( ret >= 15 )); then
533
+ echo "✅ 😁 $lab $res ${ret}p."
534
+ else
535
+ echo "🚫 🔧 $lab $res ${ret}p."
536
+ success=1
537
+ fi
538
+
539
+ done
540
+
541
+ return $success
542
+ }
543
+
544
+
545
+
546
+ ##
547
+ # Check a specific part of the course.
548
+ #
549
+ app_labbmiljo ()
550
+ {
551
+ local silent="$1"
552
+ local kmom="Labbmiljö"
553
+ local success=0
554
+
555
+ kmom_check_paths "$silent" PATHS_LABBMILJO[@]
556
+ success=$?
557
+
558
+ check_branches || ([[ ! $silent ]] && check_branches verbose)
559
+ if (( $? == 0 )); then
560
+ [[ $silent ]] || echo "✅ 😀 $kmom alla branches är på plats."
561
+ else
562
+ [[ $silent ]] || echo "🚫 🔧 $kmom någon branch saknas eller har fel namn, fixa det."
563
+ success=1
564
+ fi
565
+
566
+ # Kolla att repot har rätt namn
567
+ # npx http-server ?
568
+
569
+ kmom_summary "$silent" $success "$kmom"
570
+
571
+ return $success
572
+ }
573
+
574
+
575
+
576
+ ##
577
+ # Check a specific kmom.
578
+ #
579
+ app_kmom01 ()
580
+ {
581
+ local success=0
582
+ local silent="$1"
583
+ local previous_kmom="labbmiljo"
584
+ local kmom="kmom01"
585
+ local pathArray="PATHS_KMOM01[@]"
586
+ local versionMin="v1.0.0"
587
+ local versionMax="v2.0.0"
588
+ local lab="lab_01"
589
+
590
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
591
+ res=$?
592
+ (( res != 0 )) && success=$res
593
+
594
+ return $success
595
+ }
596
+
597
+
598
+
599
+ ##
600
+ # Check a specific kmom.
601
+ #
602
+ app_kmom02 ()
603
+ {
604
+ local silent="$1"
605
+ local success=0
606
+ local previous_kmom="kmom01"
607
+ local kmom="kmom02"
608
+ local pathArray="PATHS_KMOM02[@]"
609
+ local versionMin="v2.0.0"
610
+ local versionMax="v3.0.0"
611
+ local lab="lab_02"
612
+
613
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
614
+ res=$?
615
+ (( res != 0 )) && success=$res
616
+
617
+ return $success
618
+ }
619
+
620
+
621
+
622
+ ##
623
+ # Check a specific kmom.
624
+ #
625
+ app_kmom03 ()
626
+ {
627
+ local silent="$1"
628
+ local success=0
629
+ local previous_kmom="kmom02"
630
+ local kmom="kmom03"
631
+ local pathArray="PATHS_KMOM03[@]"
632
+ local versionMin="v3.0.0"
633
+ local versionMax="v4.0.0"
634
+ local lab="lab_03"
635
+
636
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
637
+ res=$?
638
+ (( res != 0 )) && success=$res
639
+
640
+ # kontrollera att PR är korrekt gjord för kmom03
641
+
642
+ return $success
643
+ }
644
+
645
+
646
+
647
+ ##
648
+ # Check a specific kmom.
649
+ #
650
+ app_kmom04 ()
651
+ {
652
+ local success=0
653
+ local silent="$1"
654
+ local previous_kmom="labbmiljo"
655
+ local kmom="kmom04"
656
+ local pathArray="PATHS_KMOM04[@]"
657
+ local versionMin="v4.0.0"
658
+ local versionMax="v5.0.0"
659
+ local lab="lab_04"
660
+
661
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
662
+ res=$?
663
+ (( res != 0 )) && success=$res
664
+
665
+ return $success
666
+ }
667
+
668
+
669
+
670
+ ##
671
+ # Check a specific kmom.
672
+ #
673
+ app_kmom05 ()
674
+ {
675
+ local success=0
676
+ local silent="$1"
677
+ local previous_kmom="kmom04"
678
+ local kmom="kmom05"
679
+ local pathArray="PATHS_KMOM05[@]"
680
+ local versionMin="v5.0.0"
681
+ local versionMax="v6.0.0"
682
+ local lab="no"
683
+
684
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
685
+ res=$?
686
+ (( res != 0 )) && success=$res
687
+
688
+ return $success
689
+ }
690
+
691
+
692
+
693
+ ##
694
+ # Check a specific kmom.
695
+ #
696
+ app_kmom06 ()
697
+ {
698
+ local success=0
699
+ local silent="$1"
700
+ local previous_kmom="kmom05"
701
+ local kmom="kmom06"
702
+ local pathArray="PATHS_KMOM06[@]"
703
+ local versionMin="v6.0.0"
704
+ local versionMax="v7.0.0"
705
+ local lab=""
706
+
707
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
708
+ res=$?
709
+ (( res != 0 )) && success=$res
710
+
711
+ return $success
712
+ }
713
+
714
+
715
+
716
+ ##
717
+ # Check a specific kmom.
718
+ #
719
+ app_kmom10 ()
720
+ {
721
+ local success=0
722
+ local silent="$1"
723
+ local previous_kmom="no"
724
+ local kmom="kmom10"
725
+ local pathArray="PATHS_KMOM10[@]"
726
+ local versionMin="v7.0.0"
727
+ local versionMax="v11.0.0"
728
+ local lab=""
729
+
730
+ kmom_do "$silent" "$previous_kmom" "$kmom" "$pathArray" "$versionMin" "$versionMax" "$lab"
731
+ res=$?
732
+ (( res != 0 )) && success=$res
733
+
734
+ return $success
735
+ }
736
+
737
+
738
+
739
+ ##
740
+ # Always have a main
741
+ #
742
+ main ()
743
+ {
744
+ local command
745
+ local args
746
+
747
+ while (( $# ))
748
+ do
749
+ case "$1" in
750
+
751
+ --eslint-fix)
752
+ ESLINT_FIX=1
753
+ shift
754
+ ;;
755
+
756
+ --help | -h)
757
+ usage
758
+ exit 0
759
+ ;;
760
+
761
+ --only-this)
762
+ ONLY_THIS=1
763
+ shift
764
+ ;;
765
+
766
+ --no-branch)
767
+ NO_BRANCH=1
768
+ shift
769
+ ;;
770
+
771
+ --no-color)
772
+ NO_COLOR=1
773
+ shift
774
+ ;;
775
+
776
+ --no-eslint)
777
+ NO_ESLINT=1
778
+ shift
779
+ ;;
780
+
781
+ --pass-lab)
782
+ PASS_LAB="-s"
783
+ shift
784
+ ;;
785
+
786
+ --verbose | -v)
787
+ VERBOSE=1
788
+ shift
789
+ ;;
790
+
791
+ --version)
792
+ version
793
+ exit 0
794
+ ;;
795
+
796
+ eslint \
797
+ | lab \
798
+ | labbmiljo \
799
+ | kmom01 \
800
+ | kmom02 \
801
+ | kmom03 \
802
+ | kmom04 \
803
+ | kmom05 \
804
+ | kmom06 \
805
+ | kmom10 \
806
+ )
807
+ if [[ ! $command ]]; then
808
+ command=$1
809
+ else
810
+ args+=("$1")
811
+ fi
812
+ shift
813
+ ;;
814
+
815
+ -*)
816
+ badUsage "Unknown option '$1'."
817
+ ;;
818
+
819
+ *)
820
+ if [[ ! $command ]]; then
821
+ badUsage "Unknown command '$1'."
822
+ else
823
+ args+=("$1")
824
+ shift
825
+ fi
826
+ ;;
827
+
828
+ esac
829
+ done
830
+
831
+ # Execute the command
832
+ if type -t app_"$command" | grep -q function; then
833
+ app_"$command" "${args[@]}"
834
+ else
835
+ badUsage "Missing option or command."
836
+ fi
837
+ }
838
+
839
+ main "$@"
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Name of the script
4
+ #SCRIPT=$( basename "$0" )
5
+ export SCRIPT="@dbwebb/webtec"
6
+
7
+ # Current version
8
+ export VERSION="1.0.0"
9
+
10
+
11
+
12
+ ##
13
+ # Message to display for version.
14
+ #
15
+ version ()
16
+ {
17
+ local txt=(
18
+ "$SCRIPT version $VERSION"
19
+ )
20
+
21
+ printf "%s\\n" "${txt[@]}"
22
+ }
23
+
24
+
25
+
26
+ #SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
27
+ SCRIPT_PATH="$(realpath "$0")"
28
+ SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
29
+
30
+ SUBCOMMAND="$1"
31
+ shift
32
+
33
+ case "$SUBCOMMAND" in
34
+ check)
35
+ "$SCRIPT_DIR/dbw-check.bash" "$@"
36
+ ;;
37
+ help)
38
+ "$SCRIPT_DIR/dbw-help.bash" "$@"
39
+ ;;
40
+ version | --version)
41
+ version
42
+ ;;
43
+ *)
44
+ echo "Usage: npx @dbwebb/webtec {check|help|version}"
45
+ exit 1
46
+ ;;
47
+ esac
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ # @dbwebb/webtec - show help about all scripts
3
+
4
+ echo "📦 Show help text..."
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@dbwebb/databas",
3
+ "version": "1.0.0",
4
+ "description": "CLI to work with the databas source, for staff and student.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "dbwebb",
8
+ "databas",
9
+ "tool",
10
+ "cli",
11
+ "bash"
12
+ ],
13
+ "author": "Mikael Roos",
14
+ "type": "module",
15
+ "scripts": {
16
+ "clean-all": "rm -rf node_modules package-lock.json",
17
+ "test": "echo \"Error: no test specified\" && exit 1"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "README.md",
24
+ "bin"
25
+ ],
26
+ "bin": {
27
+ "databas": "./bin/dbw-databas.bash"
28
+ },
29
+ "dependencies": {
30
+ "acorn": "^8.15.0"
31
+ }
32
+ }