@adobe/helix-md2jcr 1.0.0 → 1.0.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.0.4](https://github.com/adobe/helix-md2jcr/compare/v1.0.3...v1.0.4) (2025-01-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fix typo and silence eslint warning ([#41](https://github.com/adobe/helix-md2jcr/issues/41)) ([b1f9e51](https://github.com/adobe/helix-md2jcr/commit/b1f9e51dc08caef83ab092a4195d2f6a95a26af3))
7
+
8
+ ## [1.0.3](https://github.com/adobe/helix-md2jcr/compare/v1.0.2...v1.0.3) (2025-01-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove private ([#39](https://github.com/adobe/helix-md2jcr/issues/39)) ([1358e6d](https://github.com/adobe/helix-md2jcr/commit/1358e6dda7950a25d4b8a99bb5e4fbbf87b4c0d5))
14
+
15
+ ## [1.0.2](https://github.com/adobe/helix-md2jcr/compare/v1.0.1...v1.0.2) (2025-01-28)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * update docs for release ([#38](https://github.com/adobe/helix-md2jcr/issues/38)) ([223a94e](https://github.com/adobe/helix-md2jcr/commit/223a94e92b76eaa86d7fce670c4cec6ffed6065a))
21
+
22
+ ## [1.0.1](https://github.com/adobe/helix-md2jcr/compare/v1.0.0...v1.0.1) (2025-01-28)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update readme ([#37](https://github.com/adobe/helix-md2jcr/issues/37)) ([ae4ab74](https://github.com/adobe/helix-md2jcr/commit/ae4ab740a7629ad9a3c99da99ef3520304fe9032))
28
+
1
29
  # 1.0.0 (2025-01-28)
2
30
 
3
31
 
package/README.md CHANGED
@@ -8,20 +8,49 @@
8
8
  [![GitHub issues](https://img.shields.io/github/issues/adobe/helix-md2jcr.svg)](https://github.com/adobe/helix-md2jcr/issues)
9
9
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
10
10
 
11
- ## Installation
11
+ ## Development
12
+ Install all dependencies by running:
13
+
14
+ ```bash
15
+ npm install
16
+ ```
12
17
 
13
18
  ## Usage
19
+ You can install the package via npm:
14
20
 
15
21
  ```bash
16
22
  npm install @adobe/helix-md2jcr
17
23
  ```
18
24
 
19
- ## Converting Markdown to JCR XML document
25
+ ## Converting Markdown to JCR Nodes
26
+ Running the following command will generate an XML file with the JCR structure alongside of the input file.
20
27
 
21
- just run:
28
+ For example generating xml for the simple.md file, run:
29
+ ```bash
30
+ node ./src/cli/convert2jcr.js test/fixtures/simple.md
31
+ ```
32
+ If you wish to see the output in the console, you can run the following command with the verbose flag -v
33
+ ```bash
34
+ node ./src/cli/convert2jcr.js test/fixtures/simple.md -v
35
+ ```
22
36
 
37
+ If you wish to see the decoded output in the console you can run the following command with the verbose and decode flags -v and -d:
23
38
  ```bash
24
- node ./src/cli/convert2jcr.js <file>
39
+ node ./src/cli/convert2jcr.js test/fixtures/simple.md -v -d
25
40
  ```
26
41
 
27
- The converter will produce a `.xml` file with the generated document converted following the JCR XML schema.
42
+ The converter will produce a `.xml` which is the generated document converted
43
+ from markdown. This can be used to check for potential content changes due to conversion.
44
+
45
+ ## Baseline XML Files
46
+ Running the ./baseline-tests.sh script will detect any md file under test/fixtures and execute the convert2jcr node script.
47
+ The script will generate new xml files beside the md files it locates. This is helpful when making changes to the converter
48
+ and you want to see if the changes have any impact on the output. By using git diff, you will see the new changes in the xml files.
49
+ If you are satisfied with the changes, you can commit the new xml files.
50
+
51
+
52
+ ## Running Tests
53
+ Simply execute the following command to run the tests:
54
+ ```bash
55
+ npm test
56
+ ```
package/baseline-tests.sh CHANGED
@@ -1,5 +1,34 @@
1
1
  #!/bin/bash
2
2
 
3
+ # create a function that prints the usage of the script
4
+ usage() {
5
+ echo "Usage: $0 [-v] [-d]"
6
+ echo " -v: Verbose mode"
7
+ echo " -d: Decode output mode"
8
+ exit 1
9
+ }
10
+
11
+ # verify that the command arguments are only -v or -d if any other commands are found exit with an error. If -d is present but -v is not present, exit with an error.
12
+ while getopts ":vd" opt; do
13
+ case ${opt} in
14
+ v )
15
+ VERBOSE="true"
16
+ ;;
17
+ d )
18
+ DECODE="true"
19
+ ;;
20
+ \? )
21
+ echo "Invalid option: $OPTARG" 1>&2
22
+ usage
23
+ ;;
24
+ : )
25
+ echo "Invalid option: $OPTARG requires an argument" 1>&2
26
+ usage
27
+ ;;
28
+ esac
29
+ done
30
+
31
+
3
32
  # Set the root directory to search for .md files
4
33
  MD_DIR="test/fixtures"
5
34
 
@@ -21,19 +50,22 @@ if [ -z "$MD_FILES" ]; then
21
50
  exit 1
22
51
  fi
23
52
 
53
+ ARGS=""
54
+ [ "$VERBOSE" = "true" ] && ARGS="$ARGS -v"
55
+ [ "$DECODE" = "true" ] && ARGS="$ARGS -d"
56
+
24
57
  # Iterate over each .md file
25
58
  for MD_FILE in $MD_FILES; do
59
+ # if VERBOSE is true then echo a new line
60
+ [ "$VERBOSE" = "true" ] && echo
61
+
26
62
  # Execute the Node.js script with the .md file as an argument
27
- echo "*******************************************************************************"
28
63
  echo "Processing $MD_FILE..."
29
- echo "*******************************************************************************"
30
- echo ""
31
64
 
32
- if [ "$1" == "-d" ]; then
33
- NODE_ENV=debug node "$NODE_SCRIPT" "$MD_FILE"
34
- else
35
- node "$NODE_SCRIPT" "$MD_FILE"
36
- fi
65
+ # if VERBOSE is true then echo a new line
66
+ [ "$VERBOSE" = "true" ] && echo
67
+
68
+ node "$NODE_SCRIPT" "$MD_FILE" $ARGS
37
69
 
38
70
  # Check if the Node.js script executed successfully
39
71
  if [ $? -ne 0 ]; then
@@ -42,4 +74,5 @@ for MD_FILE in $MD_FILES; do
42
74
  fi
43
75
  done
44
76
 
77
+
45
78
  echo "All .md files have been processed successfully."
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export default {
13
+ extends: ['@commitlint/config-conventional'],
14
+ rules: {
15
+ 'footer-max-line-length': [0],
16
+ },
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-md2jcr",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Helix Service that converts markdown to JCR content structure",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  "lint": "eslint .",
10
10
  "semantic-release": "semantic-release",
11
11
  "semantic-release-dry": "semantic-release --dry-run --branches $CI_BRANCH",
12
- "prepare": "husky install"
12
+ "prepare": "husky"
13
13
  },
14
14
  "mocha": {
15
15
  "spec": "test/*.test.js",
@@ -56,6 +56,8 @@
56
56
  "devDependencies": {
57
57
  "@adobe/eslint-config-helix": "2.0.8",
58
58
  "@adobe/helix-mediahandler": "2.5.48",
59
+ "@commitlint/cli": "^19.6.1",
60
+ "@commitlint/config-conventional": "^19.6.0",
59
61
  "@semantic-release/changelog": "6.0.3",
60
62
  "@semantic-release/exec": "6.0.3",
61
63
  "@semantic-release/git": "10.0.1",
@@ -65,7 +67,7 @@
65
67
  "eslint-import-resolver-exports": "1.0.0-beta.5",
66
68
  "eslint-plugin-header": "3.1.1",
67
69
  "eslint-plugin-import": "2.31.0",
68
- "husky": "9.1.7",
70
+ "husky": "^9.1.7",
69
71
  "junit-report-builder": "5.1.1",
70
72
  "lint-staged": "15.4.3",
71
73
  "mocha": "10.8.2",
@@ -39,11 +39,12 @@ async function readJsonFile(filePath) {
39
39
  /**
40
40
  * Convert a markdown file to JCR XML.
41
41
  * @param mdFile {string} The path to the markdown file.
42
+ * @param verbose - if true the XML will be printed to the console.
42
43
  * @param decodeXML - if true a file with the decoded XML will be created.
43
44
  * @returns {Promise<void>} A promise that resolves when the conversion is
44
45
  * complete, or rejects if the file is not a markdown file.
45
46
  */
46
- async function convert(mdFile, decodeXML = false) {
47
+ async function convert(mdFile, verbose = false, decodeXML = false) {
47
48
  if (!mdFile.endsWith('.md')) {
48
49
  return Promise.reject(new Error('File must be a markdown file'));
49
50
  }
@@ -51,7 +52,6 @@ async function convert(mdFile, decodeXML = false) {
51
52
  const dir = path.dirname(mdFile);
52
53
  const base = path.basename(mdFile, '.md');
53
54
  const fileJcrXML = path.resolve(dir, `${base}.xml`);
54
- const decodedXML = path.resolve(dir, `${base}-decoded.xml`);
55
55
 
56
56
  let modelJson;
57
57
  let definitionJson;
@@ -96,8 +96,12 @@ async function convert(mdFile, decodeXML = false) {
96
96
 
97
97
  const xml = await md2jcr(md, opts);
98
98
 
99
- if (decodeXML) {
100
- writeFile(decodedXML, decode(xml));
99
+ if (verbose) {
100
+ if (!decodeXML) {
101
+ console.log(xml);
102
+ } else if (decodeXML) {
103
+ console.log(decode(xml));
104
+ }
101
105
  }
102
106
 
103
107
  return writeFile(fileJcrXML, xml);
@@ -115,13 +119,16 @@ async function run(inPath) {
115
119
 
116
120
  const files = [];
117
121
  if ((await stat(dirOrFilePath)).isDirectory()) {
118
- files.push(...await readdir(dirOrFilePath));
122
+ const items = await readdir(dirOrFilePath);
123
+ items
124
+ .filter((item) => item.endsWith('.md'))
125
+ .forEach((item) => files.push(path.resolve(dirOrFilePath, item)));
119
126
  } else {
120
127
  files.push(dirOrFilePath);
121
128
  }
122
129
 
123
130
  for (const file of files) {
124
- await convert(file, process.argv.includes('-d'));
131
+ await convert(file, process.argv.includes('-v'), process.argv.includes('-d'));
125
132
  }
126
133
  }
127
134
 
@@ -29,6 +29,8 @@ import image from './supports/image.js';
29
29
  import FieldGroupFieldResolver from '../../domain/FieldGroupFieldResolver.js';
30
30
  import ModelHelper from '../../domain/ModelHelper.js';
31
31
 
32
+ /* eslint-disable no-console */
33
+
32
34
  /**
33
35
  * @typedef {import('../../index.d.ts').FieldDef} Field
34
36
  * @typedef {import('../../index.d.ts').DefinitionDef} Definition
@@ -250,9 +252,9 @@ function extractProperties(mdast, model, mode, component, fields, properties) {
250
252
  extractKeyValueProperties(row, model, fieldResolver, fieldGroup, properties);
251
253
  } else {
252
254
  // for each cell in the row, process the nodes that exist in the cell
253
- let processsing = false;
255
+ let processing = false;
254
256
  for (const cell of cells) {
255
- if (mode === 'blockItem' && !processsing) {
257
+ if (mode === 'blockItem' && !processing) {
256
258
  fieldGroup = fieldsCloned.shift();
257
259
  }
258
260
 
@@ -260,7 +262,7 @@ function extractProperties(mdast, model, mode, component, fields, properties) {
260
262
  if (nodes.length === 0) {
261
263
  // throw away the field that was associated with the cell
262
264
  fieldGroup.fields.shift();
263
- processsing = true;
265
+ processing = true;
264
266
  // if there are no nodes in the cell, then we need to skip it
265
267
  } else {
266
268
  while (nodes.length > 0) {
@@ -86,9 +86,5 @@ export default async function mdast2jcr(mdast, options = {}) {
86
86
  lineSeparator: '\n',
87
87
  });
88
88
 
89
- if (process.env.NODE_ENV === 'debug') {
90
- console.log(xml);
91
- }
92
-
93
89
  return xml;
94
90
  }