Skip to content

Commit 3401154

Browse files
committed
Merge branch 'release-0.3.0'
2 parents 480aabf + 100f99b commit 3401154

File tree

10 files changed

+238
-52
lines changed

10 files changed

+238
-52
lines changed

.github/workflows/codeql.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: '16 10 * * 5'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'javascript', 'typescript' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
29+
# Initializes the CodeQL tools for scanning.
30+
- name: Initialize CodeQL
31+
uses: github/codeql-action/init@v2
32+
with:
33+
languages: ${{ matrix.language }}
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2

.github/workflows/stale.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2+
#
3+
# You can adjust the behavior by modifying this file.
4+
# For more information, see:
5+
# https://github.com/actions/stale
6+
name: Mark stale issues and pull requests
7+
8+
on:
9+
schedule:
10+
- cron: '18 7 * * *'
11+
12+
jobs:
13+
stale:
14+
15+
runs-on: ubuntu-latest
16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
20+
steps:
21+
- uses: actions/stale@v5
22+
with:
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
24+
stale-issue-message: 'Stale issue message'
25+
stale-pr-message: 'Stale pull request message'
26+
stale-issue-label: 'no-issue-activity'
27+
stale-pr-label: 'no-pr-activity'

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22

33
All changes to the CNC Codes JSON Schema will be documented here.
44

5-
## v0.2. [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.2.2)
5+
## v0.3.0 [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.3.0)
6+
7+
### New Features
8+
9+
- *BREAKING* Added `remove` array property to `variant` (Now an object) for modifying JSON for which it is a variant
10+
11+
### Fixes
12+
13+
- Fixed tests to provide more information if the schema is invalid
14+
15+
### Other
16+
17+
- Updated dependencies
18+
- Updated [README](README.md)
19+
- `variant` is now object with `name` property and `remove` array.
20+
21+
## v0.2.2 [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.2.2)
622

723
### Fixes
824

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
This project is a schema definition for using JSON to store description and usage information about G & M codes. It was developed out of a necessity for [G-Code Reference](https://github.com/appliedengdesign/gcode-reference). It will be updated as the needs arise for the various types of G/M codes and various Machine Tools or 3D Printers.
88

9-
Latest NPM Version: v0.2.2
9+
Latest NPM Version: v0.3.0
1010

1111
Latest Draft Schema Version: 2022-07
1212

@@ -69,10 +69,22 @@ Previous Versions: [2022-06](https://appliedengdesign.github.io/cnccodes-json-sc
6969
},
7070
"variant": {
7171
"description": "Defined if G/M Codes are for specific MTB/3DP Variant. (Must be lower case, 3-8 characters)",
72-
"type": "string",
73-
"minLength": 3,
74-
"maxLength": 8,
75-
"pattern": "[A-Za-z0-9]"
72+
"type": "object",
73+
"properties": {
74+
"name": {
75+
"type": "string",
76+
"minLength": 3,
77+
"maxLength": 8,
78+
"pattern": "[a-z0-9]"
79+
},
80+
"remove": {
81+
"type": "array",
82+
"items": {
83+
"type": "string"
84+
},
85+
"uniqueItems": true
86+
}
87+
}
7688
},
7789
"codes": {
7890
"description": "Individual G/M Codes",

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@appliedengdesign/cnccodes-json-schema",
3-
"version": "0.2.2",
3+
"version": "0.3.0",
44
"description": "JSON Schema for CNC G & M Codes",
55
"author": "Mike Centola",
66
"license": "MIT",
@@ -34,11 +34,14 @@
3434
"access": "public"
3535
},
3636
"scripts": {
37-
"build": "tsc --project tsconfig.build.json",
37+
"build": "npm run test && tsc --project tsconfig.build.json",
3838
"build-ghp": "npx ts-node ./scripts/build-ghpages.ts",
3939
"clean": "shx rm -rf dist/*",
4040
"compile": "tsc",
41+
"lint": "eslint src/**/*.ts --fix",
42+
"refresh": "shx rm -rf ./node_modules ./package-lock.json && npm install",
4143
"prepack": "npm run clean && npm run build",
44+
"pretty": "prettier --config .prettierrc --loglevel warn --write",
4245
"test": "mocha --require ts-node/register test/**/*.ts"
4346
},
4447
"devDependencies": {

src/schema/cnccodes.schema.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,22 @@
5252
},
5353
"variant": {
5454
"description": "Defined if G/M Codes are for specific MTB/3DP Variant. (Must be lower case, 3-8 characters)",
55-
"type": "string",
56-
"minLength": 3,
57-
"maxLength": 8,
58-
"pattern": "[A-Za-z0-9]"
55+
"type": "object",
56+
"properties": {
57+
"name": {
58+
"type": "string",
59+
"minLength": 3,
60+
"maxLength": 8,
61+
"pattern": "[a-z0-9]"
62+
},
63+
"remove": {
64+
"type": "array",
65+
"items": {
66+
"type": "string"
67+
},
68+
"uniqueItems": true
69+
}
70+
}
5971
},
6072
"codes": {
6173
"description": "Individual G/M Codes",

test/sample/g-sample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "gcode",
44
"machineType": "mill",
55
"title": "G Code Milling Reference",
6+
"description": "G-Code Reference for Milling Machine Tools",
67
"codes": {
78
"G00": {
89
"category": "motion",

test/sample/m-sample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "mcode",
44
"machineType": "mill",
55
"title": "M Code Milling Reference",
6+
"description": "M Code Reference for Milling Machine Tools",
67
"codes": {
78
"M00": {
89
"category": "mcode",

test/sample/variant-sample.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "../../src/schema/cnccodes.schema.json",
3+
"type": "gcode",
4+
"machineType": "mill",
5+
"title": "G Code Milling Reference",
6+
"description": "G-Code Reference for Milling Machine Tools",
7+
"variant": {
8+
"name": "snpmaker",
9+
"remove": [
10+
"M07",
11+
"M08"
12+
]
13+
},
14+
"codes": {
15+
"G00": {
16+
"category": "motion",
17+
"shortDesc": "Rapid Motion Positioning",
18+
"desc": "G00 is used to move the machine axes at the maximum speed. This G code is modal.",
19+
"modal": true,
20+
"parameters": {
21+
"X": {
22+
"shortDesc": "X-Axis motion command",
23+
"optional": true
24+
},
25+
"Y": {
26+
"shortDesc": "Y-Axis motion command",
27+
"optional": true
28+
},
29+
"Z": {
30+
"shortDesc": "Z-Axis motion command",
31+
"optional": true
32+
}
33+
}
34+
}
35+
}
36+
}

test/test.ts

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,97 @@ import { cncCodesJSONSchema } from '../src';
99
import Ajv from 'ajv/dist/2020';
1010
import gsample from './sample/g-sample.json';
1111
import msample from './sample/m-sample.json';
12+
import variant from './sample/variant-sample.json';
1213

13-
describe('Schema Definition', () => {
14-
it('Should return correct json-schema.org spec (2020-12)', () => {
15-
const sd = cncCodesJSONSchema.$schema;
16-
expect(sd).to.equal('https://json-schema.org/draft/2020-12/schema');
17-
});
18-
});
14+
const defaultOptions = {
15+
allErrors: true,
16+
verbose: true,
17+
};
1918

20-
describe('Validate Schema', () => {
21-
it('Should return true for valid schema', () => {
22-
const ajv = new Ajv({ allErrors: true, verbose: true });
23-
const validate = ajv.getSchema(cncCodesJSONSchema.$schema);
24-
if (validate) {
25-
expect(validate(cncCodesJSONSchema)).to.be.true;
26-
}
27-
});
28-
});
19+
describe('CNC Codes JSON Testing', () => {
20+
describe('Validate Schema...', () => {
21+
describe('Schema Definition', () => {
22+
it('Should return correct json-schema.org spec (2020-12)', () => {
23+
const sd = cncCodesJSONSchema.$schema;
24+
expect(sd).to.equal('https://json-schema.org/draft/2020-12/schema');
25+
});
26+
});
2927

30-
describe('Test Schema Against Valid JSON', () => {
31-
const ajv = new Ajv({ allErrors: true, verbose: true });
32-
const validate = ajv.compile(cncCodesJSONSchema);
28+
describe('Validate CNC Codes Schema', () => {
29+
it('Should return true for valid schema', () => {
30+
const ajv = new Ajv(defaultOptions);
3331

34-
if (validate) {
35-
const valid = validate(msample);
36-
it('Should return true for valid JSON', () => {
37-
expect(valid).to.be.true;
32+
const validate = ajv.getSchema(cncCodesJSONSchema.$schema);
33+
if (validate) {
34+
expect(validate(cncCodesJSONSchema)).to.be.true;
35+
}
36+
});
3837
});
38+
});
3939

40-
it('Validation Errors should be null', () => {
41-
expect(validate.errors).to.be.null;
42-
});
43-
}
44-
});
40+
describe('Test Schema...', () => {
41+
describe('Test Schema Against Valid JSON', () => {
42+
const ajv = new Ajv(defaultOptions);
43+
try {
44+
const validate = ajv.compile(cncCodesJSONSchema);
4545

46-
describe('Test Schema Against Invalid JSON', () => {
47-
const ajv = new Ajv({ allErrors: true, verbose: true });
48-
const validate = ajv.compile(cncCodesJSONSchema);
46+
if (validate) {
47+
const valid = validate(msample);
48+
it('Should return true for valid JSON', () => {
49+
expect(valid).to.be.true;
50+
});
4951

50-
if (validate) {
51-
const valid = validate(gsample);
52-
it('Should return true for valid JSON', () => {
53-
expect(valid).to.be.false;
52+
it('Validation Errors should be null', () => {
53+
expect(validate.errors).to.be.null;
54+
});
55+
}
56+
} catch (err) {
57+
it('Schema did not validate... skipping');
58+
}
5459
});
5560

56-
it('Validation errors should not be null', () => {
57-
expect(validate.errors).to.not.be.null;
61+
describe('Test Schema Against Invalid JSON', () => {
62+
const ajv = new Ajv(defaultOptions);
63+
64+
try {
65+
const validate = ajv.compile(cncCodesJSONSchema);
66+
67+
if (validate) {
68+
const valid = validate(gsample);
69+
it('Should return true for valid JSON', () => {
70+
expect(valid).to.be.false;
71+
});
72+
73+
it('Validation errors should not be null', () => {
74+
expect(validate.errors).to.not.be.null;
75+
});
76+
77+
it('Validation error should be shortDesc missing', () => {
78+
if (validate.errors) {
79+
expect(validate.errors[0].params.missingProperty).to.be.equal('shortDesc');
80+
}
81+
});
82+
}
83+
} catch (err) {
84+
it('Schema did not validate... skipping');
85+
}
5886
});
5987

60-
it('Validation error should be shortDesc missing', () => {
61-
if (validate.errors) {
62-
expect(validate.errors[0].params.missingProperty).to.be.equal('shortDesc');
88+
describe('Test Schema Against Valid Variant JSON', () => {
89+
const ajv = new Ajv(defaultOptions);
90+
91+
try {
92+
const validate = ajv.compile(cncCodesJSONSchema);
93+
94+
if (validate) {
95+
const valid = validate(variant);
96+
it('Should return true for valid Variant JSON', () => {
97+
expect(valid).to.be.true;
98+
});
99+
}
100+
} catch (err) {
101+
it('Schema did not validate... skipping');
63102
}
64103
});
65-
}
104+
});
66105
});

0 commit comments

Comments
 (0)