Skip to content

Commit

Permalink
feat: convert to a pure ESM package (#496)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This package is now pure ESM. Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
  • Loading branch information
gligoran authored Feb 8, 2022
1 parent d00fc62 commit 7c5aa59
Show file tree
Hide file tree
Showing 20 changed files with 5,866 additions and 798 deletions.
20 changes: 0 additions & 20 deletions .eslintrc.json

This file was deleted.

8 changes: 3 additions & 5 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
strategy:
matrix:
node-version:
- '12'
- '14'
- '16'
- '14'
- '12'
steps:
- uses: actions/checkout@v2
- name: use node ${{ matrix.node-version }}
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
node-version:
- '14'
- '16'
steps:
- uses: actions/checkout@v2
- name: use node ${{ matrix.node-version }}
Expand All @@ -55,8 +55,6 @@ jobs:
${{ runner.os }}-node-${{ matrix.node-version }}
- name: install dependencies
run: npm ci
- name: build
run: npm run build
- name: release to npm
env:
GITHUB_TOKEN: ${{ secrets.SR_PAT }}
Expand Down
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

5 changes: 3 additions & 2 deletions src/cli.js → cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import meow from 'meow';

import cordovaSetVersion from '.';
import cordovaSetVersion from './index.js';

const help = `
Usage
Expand All @@ -19,6 +19,7 @@ const help = `
`;

const options = {
importMeta: import.meta,
flags: {
version: {
type: 'string',
Expand All @@ -37,6 +38,6 @@ const cli = meow(options);

const configPath = cli.input[0] || null;
const version = cli.flags.version || null;
const buildNumber = +cli.flags.buildNumber || null;
const buildNumber = Number(cli.flags.buildNumber) || null;

cordovaSetVersion({ configPath, version, buildNumber });
20 changes: 10 additions & 10 deletions src/index.js → index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';
import promisify from 'util-promisify';
import xml2js from 'xml2js-es6-promise';
import { Builder } from 'xml2js';
Expand All @@ -10,19 +10,19 @@ const xmlBuilder = new Builder();

function checkTypeErrors(configPath, version, buildNumber) {
if (typeof configPath !== 'string') {
throw TypeError('"configPath" argument must be a string');
throw new TypeError('"configPath" argument must be a string');
}

if (version && typeof version !== 'string') {
throw TypeError('"version" argument must be a string');
throw new TypeError('"version" argument must be a string');
}

if (buildNumber && typeof buildNumber !== 'number') {
throw TypeError('"buildNumber" argument must be an integer');
throw new TypeError('"buildNumber" argument must be an integer');
}

if (buildNumber && buildNumber !== parseInt(buildNumber, 10)) {
throw TypeError('"buildNumber" argument must be an integer');
if (buildNumber && buildNumber !== Number.parseInt(buildNumber, 10)) {
throw new TypeError('"buildNumber" argument must be an integer');
}
}

Expand All @@ -42,13 +42,13 @@ async function getVersionFromPackage() {

function setAttributes(xml, version, buildNumber) {
const newXml = xml;
const el = newXml.plugin ? 'plugin' : 'widget';
const element = newXml.plugin ? 'plugin' : 'widget';

if (version) {
newXml[el].$.version = version;
newXml[element].$.version = version;
}

if (el === 'widget' && buildNumber) {
if (element === 'widget' && buildNumber) {
newXml.widget.$['android-versionCode'] = buildNumber;
newXml.widget.$['ios-CFBundleVersion'] = buildNumber;
newXml.widget.$['osx-CFBundleVersion'] = buildNumber;
Expand All @@ -58,7 +58,7 @@ function setAttributes(xml, version, buildNumber) {
}

/**
* Set Version and/or Build Number of Cordova config.xml.
* set Version and/or Build Number of Cordova config.xml.
* @param {string} [configPath]
* @param {string} [version]
* @param {number} [buildNumber]
Expand Down
Loading

0 comments on commit 7c5aa59

Please sign in to comment.