diff --git a/.github/workflows/genversion-ci.yml b/.github/workflows/genversion-ci.yml new file mode 100644 index 0000000..d5d85da --- /dev/null +++ b/.github/workflows/genversion-ci.yml @@ -0,0 +1,21 @@ +name: Genversion CI +run-name: ${{ github.actor }} is testing genversion + +on: [push] + +jobs: + test-genversion: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x, 16.x, 18.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.npmignore b/.npmignore index f855a00..df1f66e 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ +/.github /doc /test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 96707cc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: node_js -node_js: - - 10 - - 12 - - 14 - - 16 diff --git a/README.md b/README.md index 238099c..861ab2c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Logo](doc/genversion-logo-halo.png?raw=true "Abracadabra...and behold!") -[![Travis build status](https://img.shields.io/travis/com/axelpale/genversion)](https://app.travis-ci.com/github/axelpale/genversion) +[![GitHub Actions workflow status](https://img.shields.io/github/actions/workflow/status/axelpale/genversion/genversion-ci.yml)](https://github.com/axelpale/genversion/actions/workflows/genversion-ci.yml) [![npm version](https://img.shields.io/npm/v/genversion?color=green)](https://www.npmjs.com/package/genversion) [![license](https://img.shields.io/npm/l/genversion)](#license) [![npm downloads](https://img.shields.io/npm/dm/genversion?color=green)](https://www.npmjs.com/package/genversion) diff --git a/lib/stringify.js b/lib/stringify.js index 15b4ded..d9e9214 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -31,15 +31,15 @@ const stringify = (value, options) => { // - unescaped double or single quotes ' if (quote === '\'') { // escape unescaped single quote - const escapedValue = value.replaceAll('\'', '\\\'') + const escapedValue = value.replace(/'/g, '\\\'') return quote + escapedValue + quote } else if (quote === '"') { // escape unescaped double quote - const escapedValue = value.replaceAll('"', '\\"') + const escapedValue = value.replace(/"/g, '\\"') return quote + escapedValue + quote } else if (quote === '`') { // escape unescaped backtick - const escapedValue = value.replaceAll('`', '\\`') + const escapedValue = value.replace(/`/g, '\\`') return quote + escapedValue + quote } // else diff --git a/package.json b/package.json index d0e492e..497a65b 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ }, "devDependencies": { "fs-extra": "^10.0.1", - "mocha": "^10.2.0", + "mocha": "^8.4.0", "should": "^13.1.0", - "standard": "^17.1.0" + "standard": "^16.0.4" }, "engines": { "node": ">=10.0.0" diff --git a/test/cli.test.js b/test/cli.test.js index 9a73354..c048576 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -512,6 +512,66 @@ describe('genversion cli', () => { }) }) + it('should handle single quotes in properties', (done) => { + const clit = new CliTest() + const cmd = GENERATE_COMMAND + ' ' + + '--source ./test/fixture ' + + '--property author ' + P + clit.exec(cmd, (err, response) => { + if (err) { + return done(err) + } + + readTemp().should.equal(SIGNATURE + + 'module.exports = { ' + + 'name: \'Fo\\\'o "Bar" l`Baz\'' + + ' }\n' + ) + + return done() + }) + }) + + it('should handle double quotes in properties', (done) => { + const clit = new CliTest() + const cmd = GENERATE_COMMAND + ' ' + + '--source ./test/fixture ' + + '--property author --double ' + P + clit.exec(cmd, (err, response) => { + if (err) { + return done(err) + } + + readTemp().should.equal(SIGNATURE + + 'module.exports = { ' + + 'name: "Fo\'o \\"Bar\\" l`Baz"' + + ' }\n' + ) + + return done() + }) + }) + + it('should handle backticks in properties', (done) => { + const clit = new CliTest() + const cmd = GENERATE_COMMAND + ' ' + + '--source ./test/fixture ' + + '--property author -b ' + P + clit.exec(cmd, (err, response) => { + if (err) { + return done(err) + } + + readTemp().should.equal(SIGNATURE + + 'module.exports = { ' + + 'name: `Fo\'o "Bar" l\\`Baz`' + + ' }\n' + ) + + return done() + }) + }) + it('should not understand multiple property flags', (done) => { const clit = new CliTest() const cmd = GENERATE_COMMAND + ' --property name ' + diff --git a/test/fixture/package.json b/test/fixture/package.json index b857efd..42314cf 100644 --- a/test/fixture/package.json +++ b/test/fixture/package.json @@ -5,6 +5,9 @@ "keywords": ["foo", "bar"], "main": "index.js", "license": "MIT", + "author": { + "name": "Fo'o \"Bar\" l`Baz" + }, "dependencies": {}, "engines": { "node": ">=10.0.0",