doc-detective 3.4.1 → 3.5.0-dev.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/.github/FUNDING.yml +14 -14
- package/.github/dependabot.yml +11 -11
- package/.github/workflows/auto-dev-release.yml +173 -173
- package/.github/workflows/npm-test.yaml +96 -96
- package/.github/workflows/update-core.yaml +131 -131
- package/CONTRIBUTIONS.md +27 -27
- package/LICENSE +661 -661
- package/README.md +110 -110
- package/dev/dev.config.json +8 -8
- package/dev/dev.spec.json +30 -30
- package/dev/index.js +5 -5
- package/package.json +47 -47
- package/samples/.doc-detective.json +94 -94
- package/samples/doc-content-detect.md +10 -10
- package/samples/doc-content-inline-tests.md +23 -23
- package/samples/docker-hello.spec.json +15 -15
- package/samples/env +2 -2
- package/samples/http.spec.yaml +37 -37
- package/samples/kitten-search-detect.md +7 -7
- package/samples/kitten-search-inline.md +15 -15
- package/samples/kitten-search.spec.json +28 -28
- package/samples/local-gui.md +5 -5
- package/samples/tests.spec.json +70 -70
- package/samples/variables.env +4 -4
- package/scripts/bump-sync-version-core.js +110 -108
- package/src/checkDependencies.js +84 -84
- package/src/index.js +72 -72
- package/src/utils.js +1023 -1023
- package/test/artifacts/cleanup.spec.json +18 -18
- package/test/artifacts/config.json +6 -6
- package/test/artifacts/doc-content.md +23 -23
- package/test/artifacts/env +2 -2
- package/test/artifacts/httpRequest.spec.yaml +37 -37
- package/test/artifacts/runShell.spec.json +29 -29
- package/test/artifacts/setup.spec.json +18 -18
- package/test/artifacts/test.spec.json +46 -46
- package/test/resolvedTests.test.js +193 -193
- package/test/runTests.test.js +53 -53
- package/test/server/index.js +185 -185
- package/test/server/public/index.html +174 -174
- package/test/test-config.json +12 -12
- package/test/test-results.json +124 -124
- package/test/utils.test.js +298 -298
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# Doc Detective documentation overview
|
|
2
|
-
|
|
3
|
-
<!-- test
|
|
4
|
-
testId: doc-detective-docs
|
|
5
|
-
detectSteps: false
|
|
6
|
-
-->
|
|
7
|
-
|
|
8
|
-
[Doc Detective documentation](https://doc-detective.com) is split into a few key sections:
|
|
9
|
-
|
|
10
|
-
<!-- step checkLink: "https://doc-detective.com" -->
|
|
11
|
-
|
|
12
|
-
- The landing page discusses what Doc Detective is, what it does, and who might find it useful.
|
|
13
|
-
- [Get started](https://doc-detective.com/docs/get-started/intro) covers how to quickly get up and running with Doc Detective.
|
|
14
|
-
|
|
15
|
-
<!-- step checkLink: "https://doc-detective.com/docs/get-started/intro" -->
|
|
16
|
-
|
|
17
|
-
Some pages also have unique headings. If you open [type](https://doc-detective.com/docs/get-started/actions/type) it has **Special keys**.
|
|
18
|
-
|
|
19
|
-
<!-- step goTo: "https://doc-detective.com/docs/get-started/actions/type" -->
|
|
20
|
-
<!-- step find: Special keys -->
|
|
21
|
-
|
|
22
|
-
{ .screenshot }
|
|
23
|
-
<!-- step screenshot: reference.png -->
|
|
1
|
+
# Doc Detective documentation overview
|
|
2
|
+
|
|
3
|
+
<!-- test
|
|
4
|
+
testId: doc-detective-docs
|
|
5
|
+
detectSteps: false
|
|
6
|
+
-->
|
|
7
|
+
|
|
8
|
+
[Doc Detective documentation](https://doc-detective.com) is split into a few key sections:
|
|
9
|
+
|
|
10
|
+
<!-- step checkLink: "https://doc-detective.com" -->
|
|
11
|
+
|
|
12
|
+
- The landing page discusses what Doc Detective is, what it does, and who might find it useful.
|
|
13
|
+
- [Get started](https://doc-detective.com/docs/get-started/intro) covers how to quickly get up and running with Doc Detective.
|
|
14
|
+
|
|
15
|
+
<!-- step checkLink: "https://doc-detective.com/docs/get-started/intro" -->
|
|
16
|
+
|
|
17
|
+
Some pages also have unique headings. If you open [type](https://doc-detective.com/docs/get-started/actions/type) it has **Special keys**.
|
|
18
|
+
|
|
19
|
+
<!-- step goTo: "https://doc-detective.com/docs/get-started/actions/type" -->
|
|
20
|
+
<!-- step find: Special keys -->
|
|
21
|
+
|
|
22
|
+
{ .screenshot }
|
|
23
|
+
<!-- step screenshot: reference.png -->
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tests": [
|
|
3
|
-
{
|
|
4
|
-
"steps": [
|
|
5
|
-
{
|
|
6
|
-
"description": "Run a Docker container and check the output.",
|
|
7
|
-
"runShell": {
|
|
8
|
-
"command": "docker run hello-world",
|
|
9
|
-
"stdio": "Hello from Docker!"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"tests": [
|
|
3
|
+
{
|
|
4
|
+
"steps": [
|
|
5
|
+
{
|
|
6
|
+
"description": "Run a Docker container and check the output.",
|
|
7
|
+
"runShell": {
|
|
8
|
+
"command": "docker run hello-world",
|
|
9
|
+
"stdio": "Hello from Docker!"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
package/samples/env
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
USER="John Doe"
|
|
2
|
-
JOB="Software Engineer"
|
|
1
|
+
USER="John Doe"
|
|
2
|
+
JOB="Software Engineer"
|
|
3
3
|
SECRET="YOUR_SECRET_KEY"
|
package/samples/http.spec.yaml
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
tests:
|
|
2
|
-
- steps:
|
|
3
|
-
- loadVariables: env
|
|
4
|
-
- httpRequest:
|
|
5
|
-
url: http://localhost:8092/api/users
|
|
6
|
-
method: post
|
|
7
|
-
request:
|
|
8
|
-
body:
|
|
9
|
-
name: $USER
|
|
10
|
-
job: $JOB
|
|
11
|
-
response:
|
|
12
|
-
body:
|
|
13
|
-
name: John Doe
|
|
14
|
-
job: Software Engineer
|
|
15
|
-
- httpRequest:
|
|
16
|
-
url: http://localhost:8092/api/users
|
|
17
|
-
method: post
|
|
18
|
-
request:
|
|
19
|
-
body:
|
|
20
|
-
data:
|
|
21
|
-
- first_name: George
|
|
22
|
-
last_name: Bluth
|
|
23
|
-
id: 1
|
|
24
|
-
response:
|
|
25
|
-
body:
|
|
26
|
-
data:
|
|
27
|
-
- first_name: George
|
|
28
|
-
last_name: Bluth
|
|
29
|
-
variables:
|
|
30
|
-
ID: $$response.body.data[0].id
|
|
31
|
-
- httpRequest:
|
|
32
|
-
url: http://localhost:8092/api/$ID
|
|
33
|
-
method: get
|
|
34
|
-
timeout: 1000
|
|
35
|
-
savePath: response.json
|
|
36
|
-
maxVariation: 0
|
|
37
|
-
overwrite: aboveVariation
|
|
1
|
+
tests:
|
|
2
|
+
- steps:
|
|
3
|
+
- loadVariables: env
|
|
4
|
+
- httpRequest:
|
|
5
|
+
url: http://localhost:8092/api/users
|
|
6
|
+
method: post
|
|
7
|
+
request:
|
|
8
|
+
body:
|
|
9
|
+
name: $USER
|
|
10
|
+
job: $JOB
|
|
11
|
+
response:
|
|
12
|
+
body:
|
|
13
|
+
name: John Doe
|
|
14
|
+
job: Software Engineer
|
|
15
|
+
- httpRequest:
|
|
16
|
+
url: http://localhost:8092/api/users
|
|
17
|
+
method: post
|
|
18
|
+
request:
|
|
19
|
+
body:
|
|
20
|
+
data:
|
|
21
|
+
- first_name: George
|
|
22
|
+
last_name: Bluth
|
|
23
|
+
id: 1
|
|
24
|
+
response:
|
|
25
|
+
body:
|
|
26
|
+
data:
|
|
27
|
+
- first_name: George
|
|
28
|
+
last_name: Bluth
|
|
29
|
+
variables:
|
|
30
|
+
ID: $$response.body.data[0].id
|
|
31
|
+
- httpRequest:
|
|
32
|
+
url: http://localhost:8092/api/$ID
|
|
33
|
+
method: get
|
|
34
|
+
timeout: 1000
|
|
35
|
+
savePath: response.json
|
|
36
|
+
maxVariation: 0
|
|
37
|
+
overwrite: aboveVariation
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
To search for American Shorthair kittens,
|
|
2
|
-
|
|
3
|
-
1. Go to [DuckDuckGo](https://www.duckduckgo.com).
|
|
4
|
-
2. In the search bar, enter "American Shorthair kittens", then press Enter.
|
|
5
|
-
|
|
6
|
-
<!-- step wait: 10000 -->
|
|
7
|
-
|
|
1
|
+
To search for American Shorthair kittens,
|
|
2
|
+
|
|
3
|
+
1. Go to [DuckDuckGo](https://www.duckduckgo.com).
|
|
4
|
+
2. In the search bar, enter "American Shorthair kittens", then press Enter.
|
|
5
|
+
|
|
6
|
+
<!-- step wait: 10000 -->
|
|
7
|
+
|
|
8
8
|
{ .screenshot }
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
To search for American Shorthair kittens,
|
|
2
|
-
|
|
3
|
-
1. Go to [DuckDuckGo](https://www.duckduckgo.com).
|
|
4
|
-
|
|
5
|
-
[comment]: # (step { "action": "goTo", "url": "https://www.duckduckgo.com"})
|
|
6
|
-
[comment]: # (step { "action": "startRecording", "path": "search-results.gif"})
|
|
7
|
-
|
|
8
|
-
2. In the search bar, enter "American Shorthair kittens", then press Enter.
|
|
9
|
-
|
|
10
|
-
[comment]: # (step { "action": "find", "selector": "#searchbox_input", "click": true })
|
|
11
|
-
[comment]: # (step { "action": "typeKeys", "keys": ["American Shorthair kittens", "$ENTER$"] })
|
|
12
|
-
[comment]: # (step { "action": "find", "selector": "[data-testid='web-vertical']" })
|
|
13
|
-
[comment]: # (step { "action": "stopRecording" })
|
|
14
|
-
|
|
15
|
-

|
|
1
|
+
To search for American Shorthair kittens,
|
|
2
|
+
|
|
3
|
+
1. Go to [DuckDuckGo](https://www.duckduckgo.com).
|
|
4
|
+
|
|
5
|
+
[comment]: # (step { "action": "goTo", "url": "https://www.duckduckgo.com"})
|
|
6
|
+
[comment]: # (step { "action": "startRecording", "path": "search-results.gif"})
|
|
7
|
+
|
|
8
|
+
2. In the search bar, enter "American Shorthair kittens", then press Enter.
|
|
9
|
+
|
|
10
|
+
[comment]: # (step { "action": "find", "selector": "#searchbox_input", "click": true })
|
|
11
|
+
[comment]: # (step { "action": "typeKeys", "keys": ["American Shorthair kittens", "$ENTER$"] })
|
|
12
|
+
[comment]: # (step { "action": "find", "selector": "[data-testid='web-vertical']" })
|
|
13
|
+
[comment]: # (step { "action": "stopRecording" })
|
|
14
|
+
|
|
15
|
+

|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tests": [
|
|
3
|
-
{
|
|
4
|
-
"steps": [
|
|
5
|
-
{
|
|
6
|
-
"action": "goTo",
|
|
7
|
-
"url": "https://www.duckduckgo.com"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"action": "find",
|
|
11
|
-
"selector": "#searchbox_input",
|
|
12
|
-
"click": true,
|
|
13
|
-
"typeKeys": {
|
|
14
|
-
"keys": ["American Shorthair kittens", "$ENTER$"]
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"action": "find",
|
|
19
|
-
"selector": "[data-testid='web-vertical']"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"action": "saveScreenshot",
|
|
23
|
-
"path": "search-results.png"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"tests": [
|
|
3
|
+
{
|
|
4
|
+
"steps": [
|
|
5
|
+
{
|
|
6
|
+
"action": "goTo",
|
|
7
|
+
"url": "https://www.duckduckgo.com"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"action": "find",
|
|
11
|
+
"selector": "#searchbox_input",
|
|
12
|
+
"click": true,
|
|
13
|
+
"typeKeys": {
|
|
14
|
+
"keys": ["American Shorthair kittens", "$ENTER$"]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"action": "find",
|
|
19
|
+
"selector": "[data-testid='web-vertical']"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"action": "saveScreenshot",
|
|
23
|
+
"path": "search-results.png"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
package/samples/local-gui.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Sample Local GUI
|
|
2
|
-
|
|
3
|
-
1. Open [the GUI](http://localhost:8092).
|
|
4
|
-
2. Find **Selection Elements**, and click **Option 1**.
|
|
5
|
-
|
|
1
|
+
# Sample Local GUI
|
|
2
|
+
|
|
3
|
+
1. Open [the GUI](http://localhost:8092).
|
|
4
|
+
2. Find **Selection Elements**, and click **Option 1**.
|
|
5
|
+
|
|
6
6
|
{ .screenshot }
|
package/samples/tests.spec.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "Do all the things! - Spec",
|
|
3
|
-
"contexts": [
|
|
4
|
-
{
|
|
5
|
-
"app": {
|
|
6
|
-
"name": "firefox"
|
|
7
|
-
},
|
|
8
|
-
"platforms": ["windows", "mac", "linux"]
|
|
9
|
-
}
|
|
10
|
-
],
|
|
11
|
-
"tests": [
|
|
12
|
-
{
|
|
13
|
-
"id": "Do all the things! - Test",
|
|
14
|
-
"description": "This test includes nearly every property across all actions.",
|
|
15
|
-
"steps": [
|
|
16
|
-
{
|
|
17
|
-
"action": "setVariables",
|
|
18
|
-
"path": ".env"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"action": "runShell",
|
|
22
|
-
"command": "echo",
|
|
23
|
-
"args": ["$USER"]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"action": "checkLink",
|
|
27
|
-
"url": "https://www.duckduckgo.com"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"action": "httpRequest",
|
|
31
|
-
"url": "https://reqres.in/api/users",
|
|
32
|
-
"method": "post",
|
|
33
|
-
"requestData": {
|
|
34
|
-
"name": "morpheus",
|
|
35
|
-
"job": "leader"
|
|
36
|
-
},
|
|
37
|
-
"responseData": {
|
|
38
|
-
"name": "morpheus",
|
|
39
|
-
"job": "leader"
|
|
40
|
-
},
|
|
41
|
-
"statusCodes": [200, 201]
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"action": "goTo",
|
|
45
|
-
"url": "https://www.google.com"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"action": "find",
|
|
49
|
-
"selector": "[title=Search]",
|
|
50
|
-
"timeout": 10000,
|
|
51
|
-
"moveTo": true,
|
|
52
|
-
"click": true,
|
|
53
|
-
"typeKeys": {
|
|
54
|
-
"keys": ["shorthair cat", "$ENTER$"]
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"action": "wait"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"action": "saveScreenshot",
|
|
62
|
-
"path": "screenshot.png",
|
|
63
|
-
"directory": "samples",
|
|
64
|
-
"maxVariation": 5,
|
|
65
|
-
"overwrite": "byVariation"
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "Do all the things! - Spec",
|
|
3
|
+
"contexts": [
|
|
4
|
+
{
|
|
5
|
+
"app": {
|
|
6
|
+
"name": "firefox"
|
|
7
|
+
},
|
|
8
|
+
"platforms": ["windows", "mac", "linux"]
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"tests": [
|
|
12
|
+
{
|
|
13
|
+
"id": "Do all the things! - Test",
|
|
14
|
+
"description": "This test includes nearly every property across all actions.",
|
|
15
|
+
"steps": [
|
|
16
|
+
{
|
|
17
|
+
"action": "setVariables",
|
|
18
|
+
"path": ".env"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"action": "runShell",
|
|
22
|
+
"command": "echo",
|
|
23
|
+
"args": ["$USER"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"action": "checkLink",
|
|
27
|
+
"url": "https://www.duckduckgo.com"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"action": "httpRequest",
|
|
31
|
+
"url": "https://reqres.in/api/users",
|
|
32
|
+
"method": "post",
|
|
33
|
+
"requestData": {
|
|
34
|
+
"name": "morpheus",
|
|
35
|
+
"job": "leader"
|
|
36
|
+
},
|
|
37
|
+
"responseData": {
|
|
38
|
+
"name": "morpheus",
|
|
39
|
+
"job": "leader"
|
|
40
|
+
},
|
|
41
|
+
"statusCodes": [200, 201]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"action": "goTo",
|
|
45
|
+
"url": "https://www.google.com"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"action": "find",
|
|
49
|
+
"selector": "[title=Search]",
|
|
50
|
+
"timeout": 10000,
|
|
51
|
+
"moveTo": true,
|
|
52
|
+
"click": true,
|
|
53
|
+
"typeKeys": {
|
|
54
|
+
"keys": ["shorthair cat", "$ENTER$"]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"action": "wait"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"action": "saveScreenshot",
|
|
62
|
+
"path": "screenshot.png",
|
|
63
|
+
"directory": "samples",
|
|
64
|
+
"maxVariation": 5,
|
|
65
|
+
"overwrite": "byVariation"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
package/samples/variables.env
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
USERNAME=foo
|
|
2
|
-
PASSWORD=bar
|
|
3
|
-
SHORTHAIR_CAT_SEARCH=american shorthair cats
|
|
4
|
-
URL=www.google.com
|
|
1
|
+
USERNAME=foo
|
|
2
|
+
PASSWORD=bar
|
|
3
|
+
SHORTHAIR_CAT_SEARCH=american shorthair cats
|
|
4
|
+
URL=www.google.com
|
|
5
5
|
TEXT=I'm Feeling Lucky
|
|
@@ -1,108 +1,110 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { execSync } = require("child_process");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const semver = require("semver");
|
|
7
|
-
|
|
8
|
-
function execCommand(command, options = {}) {
|
|
9
|
-
try {
|
|
10
|
-
return execSync(command, {
|
|
11
|
-
encoding: "utf8",
|
|
12
|
-
stdio: "inherit",
|
|
13
|
-
...options,
|
|
14
|
-
});
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error(`Error executing command: ${command}`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function main() {
|
|
22
|
-
// Clean git state
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Get current project version
|
|
27
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
28
|
-
|
|
29
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
30
|
-
console.error("Error: package.json not found");
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
35
|
-
const projVersion = semver.minVersion(packageJson.version);
|
|
36
|
-
|
|
37
|
-
// Get doc-detective-core version
|
|
38
|
-
const coreVersion = semver.minVersion(
|
|
39
|
-
packageJson.dependencies?.["doc-detective-core"] ||
|
|
40
|
-
packageJson.devDependencies?.["doc-detective-core"] ||
|
|
41
|
-
""
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!coreVersion) {
|
|
45
|
-
console.error("Error: doc-detective-core dependency not found");
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!semver.valid(projVersion)) {
|
|
50
|
-
console.error(`Error: Invalid project version format: ${projVersion}`);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Extract major and minor versions using semver
|
|
55
|
-
const projMajor = semver.major(projVersion);
|
|
56
|
-
const projMinor = semver.minor(projVersion);
|
|
57
|
-
const
|
|
58
|
-
const
|
|
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
|
-
// Commit changes
|
|
89
|
-
execCommand("git add package.json package-lock.json");
|
|
90
|
-
execCommand(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const semver = require("semver");
|
|
7
|
+
|
|
8
|
+
function execCommand(command, options = {}) {
|
|
9
|
+
try {
|
|
10
|
+
return execSync(command, {
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
...options,
|
|
14
|
+
});
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error(`Error executing command: ${command}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function main() {
|
|
22
|
+
// Clean git state
|
|
23
|
+
execCommand("git checkout -- .");
|
|
24
|
+
execCommand("git clean -fd");
|
|
25
|
+
|
|
26
|
+
// Get current project version
|
|
27
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
30
|
+
console.error("Error: package.json not found");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
35
|
+
const projVersion = semver.minVersion(packageJson.version);
|
|
36
|
+
|
|
37
|
+
// Get doc-detective-core version
|
|
38
|
+
const coreVersion = semver.minVersion(
|
|
39
|
+
packageJson.dependencies?.["doc-detective-core"] ||
|
|
40
|
+
packageJson.devDependencies?.["doc-detective-core"] ||
|
|
41
|
+
""
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (!coreVersion) {
|
|
45
|
+
console.error("Error: doc-detective-core dependency not found");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!semver.valid(projVersion)) {
|
|
50
|
+
console.error(`Error: Invalid project version format: ${projVersion}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Extract major and minor versions using semver
|
|
55
|
+
const projMajor = semver.major(projVersion);
|
|
56
|
+
const projMinor = semver.minor(projVersion);
|
|
57
|
+
const coreMajor = semver.major(coreVersion);
|
|
58
|
+
const coreMinor = semver.minor(coreVersion);
|
|
59
|
+
|
|
60
|
+
console.log(`Project version: ${projMajor}.${projMinor}.x`);
|
|
61
|
+
console.log(`core version: ${coreMajor}.${coreMinor}.x`);
|
|
62
|
+
|
|
63
|
+
let newVersion;
|
|
64
|
+
|
|
65
|
+
if (projMajor !== coreMajor || projMinor !== coreMinor) {
|
|
66
|
+
// Major or minor mismatch: set version to match doc-detective-core major.minor.0
|
|
67
|
+
newVersion = `${coreMajor}.${coreMinor}.0`;
|
|
68
|
+
|
|
69
|
+
// Validate the new version before setting it
|
|
70
|
+
if (!semver.valid(newVersion)) {
|
|
71
|
+
console.error(`Error: Generated invalid version: ${newVersion}`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log(`Version mismatch detected. Setting version to: ${newVersion}`);
|
|
76
|
+
execCommand(`npm version --no-git-tag-version ${newVersion}`);
|
|
77
|
+
} else {
|
|
78
|
+
// Project version is already equal or greater than core version, just bump patch
|
|
79
|
+
console.log("Project version is current or ahead. Bumping patch version.");
|
|
80
|
+
execCommand("npm version patch --no-git-tag-version");
|
|
81
|
+
// Get the new version after bumping
|
|
82
|
+
const updatedPackageJson = JSON.parse(
|
|
83
|
+
fs.readFileSync(packageJsonPath, "utf8")
|
|
84
|
+
);
|
|
85
|
+
newVersion = updatedPackageJson.version;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Commit changes
|
|
89
|
+
execCommand("git add package.json package-lock.json");
|
|
90
|
+
execCommand(
|
|
91
|
+
'git commit -m "update doc-detective-core [skip ci]"'
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Create tag
|
|
95
|
+
execCommand(`git tag "v${newVersion}"`);
|
|
96
|
+
|
|
97
|
+
// Push changes and tags
|
|
98
|
+
execCommand("git push");
|
|
99
|
+
execCommand("git push --tags");
|
|
100
|
+
|
|
101
|
+
// Output version (equivalent to echo in bash script)
|
|
102
|
+
console.log(`version=${newVersion}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Run the script
|
|
106
|
+
if (require.main === module) {
|
|
107
|
+
main();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { main };
|