diff --git a/Makefile b/Makefile index 3cfca494c..16fe636cf 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ clean-oci-image: test: build-validations ## Test all -build: init-content test-content build-content ## Build all artifacts and copy into dist directory +build: init-content test-content build-content format-content test-dist-content ## Build all artifacts and copy into dist directory build-oci-image: ## Build OCI image docker build \ diff --git a/package-lock.json b/package-lock.json index 60f071366..969b121bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "js-yaml": "^4.1.0", "jsdom": "^25.0.0", "oscal": "2.0.7", + "prettier": "^3.4.2", "ts-node": "^10.9.2", "xml-formatter": "^3.6.3", "xml2js": "^0.6.2" @@ -2905,6 +2906,21 @@ "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", "dev": true }, + "node_modules/prettier": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", diff --git a/package.json b/package.json index c78d588e4..29ae337b6 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "js-yaml": "^4.1.0", "jsdom": "^25.0.0", "oscal": "2.0.7", + "prettier": "^3.4.2", "ts-node": "^10.9.2", "xml-formatter": "^3.6.3", "xml2js": "^0.6.2" diff --git a/src/content/module.mk b/src/content/module.mk index 7abf19f31..27ad366db 100644 --- a/src/content/module.mk +++ b/src/content/module.mk @@ -8,12 +8,18 @@ XML_DIR = $(DIST_DIR)/content/rev5/baselines/xml JSON_DIR = $(DIST_DIR)/content/rev5/baselines/json YAML_DIR = $(DIST_DIR)/content/rev5/baselines/yaml +# Format configuration +XML_FILES := $(shell find $(XML_DIR) -type f -name "*.xml" 2>/dev/null) +JSON_FILES := $(shell find $(JSON_DIR) -type f -name "*.json" 2>/dev/null) +YAML_FILES := $(shell find $(YAML_DIR) -type f -name "*.yaml" -o -name "*.yml" 2>/dev/null) + .PHONY: init-content init-content: @npm install $(OSCAL_CLI) use $(OSCAL_CLI_VERSION) $(OSCAL_CLI) server update $(OSCAL_CLI) server start -bg + # Generate content and perform conversions .PHONY: build-content build-content: @@ -42,13 +48,62 @@ build-content: @echo "Converting Profiles to YAML..." $(OSCAL_CLI) convert -f $(XML_DIR) -o $(YAML_DIR) -t YAML -s +# Format files +.PHONY: format-xml +format-xml: + @echo "Formatting XML files..." + @for file in $(XML_FILES); do \ + echo "Formatting $$file..."; \ + xmllint --format --output "$$file" "$$file"; \ + done + +.PHONY: format-json +format-json: + @echo "Formatting JSON files..." + @for file in $(JSON_FILES); do \ + echo "Formatting $$file..."; \ + npx prettier --write --parser json "$$file"; \ + done + +.PHONY: format-yaml +format-yaml: + @echo "Formatting YAML files..." + @for file in $(YAML_FILES); do \ + echo "Formatting $$file..."; \ + npx prettier --write --parser yaml "$$file"; \ + done + +# Combined format target +.PHONY: format-content +format-content: format-xml format-json format-yaml + @echo "All formatting complete!" .PHONY: test-content -test-content: +test-content: @echo "Validating Source files" - @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/ -r -s + @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_HIGH-baseline_profile.xml -s + @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_LI-SaaS-baseline_profile.xml -s + @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_LOW-baseline_profile.xml -s + @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_MODERATE-baseline_profile.xml -s + + +.PHONY: test-dist-content +test-dist-content: + @echo "Validating Output files" + @for file in $(YAML_FILES); do \ + echo "Validating $$file..."; \ + $(OSCAL_CLI) validate -f -s "$$file"; \ + done + @for file in $(JSON_FILES); do \ + echo "Validating $$file..."; \ + $(OSCAL_CLI) validate -f -s "$$file"; \ + done + @for file in $(XML_FILES); do \ + echo "Validating $$file..."; \ + $(OSCAL_CLI) validate -f -s "$$file"; \ + done .PHONY: test-legacy-content -test-legacy-content: +test-legacy-content: format @echo "Validating Source files" - @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev4/baselines/ -r -s + @$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev4/baselines/ -r -s \ No newline at end of file