react-native-version-setter
Advanced tools
| --- | ||
| name: Feature request | ||
| about: Suggest an idea for this project | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
| --- | ||
| **Is your feature request related to a problem? Please describe.** | ||
| A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
| **Describe the solution you'd like** | ||
| A clear and concise description of what you want to happen. | ||
| **Describe alternatives you've considered** | ||
| A clear and concise description of any alternative solutions or features you've considered. | ||
| **Additional context** | ||
| Add any other context or screenshots about the feature request here. |
| # Contributor Covenant Code of Conduct | ||
| ## Our Pledge | ||
| In the interest of fostering an open and welcoming environment, we as | ||
| contributors and maintainers pledge to making participation in our project and | ||
| our community a harassment-free experience for everyone, regardless of age, body | ||
| size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
| level of experience, education, socio-economic status, nationality, personal | ||
| appearance, race, religion, or sexual identity and orientation. | ||
| ## Our Standards | ||
| Examples of behavior that contributes to creating a positive environment | ||
| include: | ||
| * Using welcoming and inclusive language | ||
| * Being respectful of differing viewpoints and experiences | ||
| * Gracefully accepting constructive criticism | ||
| * Focusing on what is best for the community | ||
| * Showing empathy towards other community members | ||
| Examples of unacceptable behavior by participants include: | ||
| * The use of sexualized language or imagery and unwelcome sexual attention or | ||
| advances | ||
| * Trolling, insulting/derogatory comments, and personal or political attacks | ||
| * Public or private harassment | ||
| * Publishing others' private information, such as a physical or electronic | ||
| address, without explicit permission | ||
| * Other conduct which could reasonably be considered inappropriate in a | ||
| professional setting | ||
| ## Our Responsibilities | ||
| Project maintainers are responsible for clarifying the standards of acceptable | ||
| behavior and are expected to take appropriate and fair corrective action in | ||
| response to any instances of unacceptable behavior. | ||
| Project maintainers have the right and responsibility to remove, edit, or | ||
| reject comments, commits, code, wiki edits, issues, and other contributions | ||
| that are not aligned to this Code of Conduct, or to ban temporarily or | ||
| permanently any contributor for other behaviors that they deem inappropriate, | ||
| threatening, offensive, or harmful. | ||
| ## Scope | ||
| This Code of Conduct applies both within project spaces and in public spaces | ||
| when an individual is representing the project or its community. Examples of | ||
| representing a project or community include using an official project e-mail | ||
| address, posting via an official social media account, or acting as an appointed | ||
| representative at an online or offline event. Representation of a project may be | ||
| further defined and clarified by project maintainers. | ||
| ## Enforcement | ||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
| reported by contacting the project team at tom_mcintosh@outlook.com. All | ||
| complaints will be reviewed and investigated and will result in a response that | ||
| is deemed necessary and appropriate to the circumstances. The project team is | ||
| obligated to maintain confidentiality with regard to the reporter of an incident. | ||
| Further details of specific enforcement policies may be posted separately. | ||
| Project maintainers who do not follow or enforce the Code of Conduct in good | ||
| faith may face temporary or permanent repercussions as determined by other | ||
| members of the project's leadership. | ||
| ## Attribution | ||
| This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
| available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
| [homepage]: https://www.contributor-covenant.org | ||
| For answers to common questions about this code of conduct, see | ||
| https://www.contributor-covenant.org/faq |
+21
| MIT License | ||
| Copyright (c) 2020 Tom McIntosh | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -25,3 +25,3 @@ "use strict"; | ||
| from: [new RegExp('versionCode [0-9]+', 'g'), new RegExp('versionName "([0-9, .])+([-+][a-z0-9]+)?"')], | ||
| to: ["versionCode ".concat(version.stripped), "versionName \"".concat(version.raw, "\"")], | ||
| to: ["versionCode ".concat(version.code), "versionName \"".concat(version.raw, "\"")], | ||
| platform: _constants.constants.platform.android | ||
@@ -28,0 +28,0 @@ }, { |
@@ -14,2 +14,14 @@ "use strict"; | ||
| function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
| function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
| function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
| function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
| function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
| function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
| var createVersion = function createVersion(raw) { | ||
@@ -27,6 +39,76 @@ var version = { | ||
| version.stripped = version.core.split('.').join(''); | ||
| version.stripped = version.core.split('.').join(''); // Code is the Android versionCode where we generate an int from the semantic version | ||
| // Inspired by this: https://gist.github.com/dekalo-stanislav/9ad5f76cc2b49828acbf0634f6586b6c | ||
| version.code = versionCode(version.raw); | ||
| return version; | ||
| }; | ||
| /** | ||
| * Here is representation of Version code generation from version name. | ||
| * - Note that 1.23.1-alpha1 and 1.23.1-alpha2 will share the same versionCode. | ||
| * - We do not have room for type-numbers | ||
| * | ||
| * *--------- major version | ||
| * | *------ minor version | ||
| * | | *--- patch version | ||
| * | | |*-- buildType (dev/alpha/beta/rc/release) | ||
| * | | ||| | ||
| * X00X00XXX | ||
| * so | ||
| * 1.13.20-alpha-v19 = 10130201 | ||
| * see details below: | ||
| * *--------- 1 is major version | ||
| * | *------ 13 is minor version | ||
| * | | *--- 20 is patch version | ||
| * | | |*-- type 1 is alpha. | ||
| * | | ||*- flavor 0 (disabled) | ||
| * | | ||| | ||
| * 101302010 | ||
| */ | ||
| exports.createVersion = createVersion; | ||
| exports.createVersion = createVersion; | ||
| function versionCode(rawVersion) { | ||
| var typeDigit = 1; | ||
| var patchDigit = typeDigit * 10; | ||
| var minorDigit = patchDigit * 1000; | ||
| var majorDigit = minorDigit * 1000; | ||
| var _rawVersion$split = rawVersion.split("-"), | ||
| _rawVersion$split2 = _slicedToArray(_rawVersion$split, 2), | ||
| mainPart = _rawVersion$split2[0], | ||
| typeStr = _rawVersion$split2[1]; | ||
| var dotSplit = mainPart.split('.'); | ||
| var major = Number(dotSplit[0]); | ||
| var minor = Number(dotSplit[1]); | ||
| var patch = Number(dotSplit[2]); | ||
| var type = 9; // Defaults to relase if nothing defined | ||
| if (typeStr) { | ||
| if (typeStr.match(/^alpha/i)) { | ||
| type = 1; | ||
| } | ||
| if (typeStr.match(/^beta/i)) { | ||
| type = 2; | ||
| } | ||
| if (typeStr.match(/^rc/i)) { | ||
| type = 3; | ||
| } // Leaves room for other build-types, but release is highest (9) | ||
| } | ||
| console.log("typestr", typeStr); | ||
| console.log(dotSplit); | ||
| var out = major * majorDigit + minor * minorDigit + patch * patchDigit + type * typeDigit; | ||
| if (out > 2100000000) { | ||
| // Reference: https://medium.com/dipien/versioning-android-apps-d6ec171cfd82 | ||
| throw new Error("versionCode is larger than Google Play allows"); | ||
| } | ||
| return out; | ||
| } |
@@ -24,3 +24,3 @@ "use strict"; | ||
| if ((_result$2 = result[0]) === null || _result$2 === void 0 ? void 0 : _result$2.hasChanged) { | ||
| if ((_result$2 = result[0]) !== null && _result$2 !== void 0 && _result$2.hasChanged) { | ||
| changes++; | ||
@@ -27,0 +27,0 @@ commandLineFlags.debugLog.set && (0, _process.out)("Set ".concat(location.files, " to: ").concat(location.to, " ")); |
+1
-1
| { | ||
| "name": "react-native-version-setter", | ||
| "version": "2.2.0", | ||
| "version": "2.2.1", | ||
| "description": "Update your app version with a single command.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://www.github.com/tj-mc/react-native-version-setter", |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.constants = void 0; | ||
| var constants = { | ||
| platform: { | ||
| android: 'android', | ||
| ios: 'ios', | ||
| universal: 'universal' | ||
| }, | ||
| emoji: { | ||
| warning: String.fromCodePoint(0x1F6D1), | ||
| check: String.fromCodePoint(0x2705), | ||
| sparkle: String.fromCodePoint(0x2728) | ||
| } | ||
| }; | ||
| exports.constants = constants; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.coreReplacer = void 0; | ||
| /** | ||
| * Replacer function to strip beta/rc from ios versions. | ||
| * Strips away second match. | ||
| * @param match | ||
| * @param p1 | ||
| * @param p2 | ||
| * @param offset | ||
| * @param string | ||
| * @return {*} | ||
| */ | ||
| var coreReplacer = function coreReplacer(match, p1, p2, offset, string) { | ||
| return p1; | ||
| }; | ||
| exports.coreReplacer = coreReplacer; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.createCliFlags = void 0; | ||
| var _process = require("../lib/process"); | ||
| var flags = [{ | ||
| name: 'debugLog', | ||
| argument: '-d' | ||
| }, { | ||
| name: 'dryRun', | ||
| argument: '-r' | ||
| }, { | ||
| name: 'iosOnly', | ||
| argument: '-ios' | ||
| }, { | ||
| name: 'androidOnly', | ||
| argument: '-android' | ||
| }]; | ||
| var createCliFlags = function createCliFlags() { | ||
| var args = {}; | ||
| flags.forEach(function (flag) { | ||
| args[flag.name] = { | ||
| argument: flag.argument, | ||
| set: (0, _process.cliArgumentExists)(flag.argument) | ||
| }; | ||
| }); | ||
| return args; | ||
| }; | ||
| exports.createCliFlags = createCliFlags; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.createLocations = void 0; | ||
| var _constants = require("./constants.js"); | ||
| /** | ||
| * Create the location objects for find and replace. | ||
| * @param version | ||
| * @param packageJson | ||
| * @param platform | ||
| * @returns Array | ||
| */ | ||
| var createLocations = function createLocations(version, packageJson) { | ||
| var platform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
| var allLocations = [{ | ||
| files: './android/app/build.gradle', | ||
| from: [new RegExp('versionCode [0-9]+', 'g'), new RegExp('versionName "([0-9, .])+([-+][a-z0-9]+)?"')], | ||
| to: ["versionCode ".concat(version.stripped), "versionName \"".concat(version.raw, "\"")], | ||
| platform: _constants.constants.platform.android | ||
| }, { | ||
| files: "./ios/".concat(packageJson.name, ".xcodeproj/project.pbxproj"), | ||
| from: new RegExp('MARKETING_VERSION = [0-9, .]+', 'g'), | ||
| to: "MARKETING_VERSION = ".concat(version.core), | ||
| platform: _constants.constants.platform.ios | ||
| }, { | ||
| files: "./package.json", | ||
| from: new RegExp('"version": ".+"'), | ||
| to: "\"version\": \"".concat(version.raw, "\""), | ||
| platform: _constants.constants.platform.universal | ||
| }]; | ||
| /** | ||
| * If a platform was passed, find the locations for that platform. | ||
| */ | ||
| switch (platform) { | ||
| case _constants.constants.platform.android: | ||
| return allLocations.filter(function (location) { | ||
| return location.platform === _constants.constants.platform.android; | ||
| }); | ||
| case _constants.constants.platform.ios: | ||
| return allLocations.filter(function (location) { | ||
| return location.platform === _constants.constants.platform.ios; | ||
| }); | ||
| case _constants.constants.platform.universal: | ||
| default: | ||
| return allLocations; | ||
| } | ||
| }; | ||
| exports.createLocations = createLocations; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.createVersion = void 0; | ||
| var _process = require("./process"); | ||
| var _constants = require("./constants"); | ||
| var _coreReplacer = require("./coreReplacer"); | ||
| var createVersion = function createVersion(raw) { | ||
| var version = { | ||
| validRegEx: /^([0-9, .]+)([-+][a-z0-9]+)?$/, | ||
| // Semantic Versioning 2.0 | ||
| raw: raw | ||
| }; // Validate version strings | ||
| version.raw || (0, _process.die)("Please provide a version number. ".concat(_constants.constants.emoji.warning)); | ||
| version.validRegEx.test(version.raw) || (0, _process.die)("Usage: setVersion <version> [args] ".concat(_constants.constants.emoji.warning, " ")); // The core string contains no extended semVer symbols. Eg, 1.1.1 format only. | ||
| version.core = version.raw.replace(version.validRegEx, _coreReplacer.coreReplacer); // Stripped is the core string without periods | ||
| version.stripped = version.core.split('.').join(''); | ||
| return version; | ||
| }; | ||
| exports.createVersion = createVersion; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.getPlatformConstant = void 0; | ||
| var _constants = require("./constants"); | ||
| var _process = require("./process"); | ||
| /** | ||
| * Convert CLI arguments to a constant string | ||
| * @param cliArgs | ||
| * @returns {string} | ||
| */ | ||
| var getPlatformConstant = function getPlatformConstant(cliArgs) { | ||
| if (cliArgs.iosOnly.set && cliArgs.androidOnly.set) { | ||
| (0, _process.out)('Adding all version flags at once has no effect.'); | ||
| return _constants.constants.platform.universal; | ||
| } | ||
| if (cliArgs.iosOnly.set) return _constants.constants.platform.ios; | ||
| if (cliArgs.androidOnly.set) return _constants.constants.platform.android; | ||
| }; | ||
| exports.getPlatformConstant = getPlatformConstant; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.mutateFiles = void 0; | ||
| var _process = require("./process"); | ||
| var _constants = require("./constants"); | ||
| var replace = require('replace-in-file'); | ||
| var mutateFiles = function mutateFiles(locations, commandLineFlags, packageJson, version) { | ||
| var changes = 0; | ||
| try { | ||
| locations.forEach(function (location) { | ||
| var _result$, _result$2; | ||
| var result = replace.sync(location); | ||
| ((_result$ = result[0]) === null || _result$ === void 0 ? void 0 : _result$.file) || (0, _process.out)("Could not find file: ".concat(location.files, " ").concat(_constants.constants.emoji.warning, " ")); | ||
| if ((_result$2 = result[0]) === null || _result$2 === void 0 ? void 0 : _result$2.hasChanged) { | ||
| changes++; | ||
| commandLineFlags.debugLog.set && (0, _process.out)("Set ".concat(location.files, " to: ").concat(location.to, " ")); | ||
| } else { | ||
| commandLineFlags.debugLog.set && (0, _process.out)("".concat(location.files, " was not changed.")); | ||
| } | ||
| }); | ||
| if (locations.length > changes && changes !== 0) { | ||
| (0, _process.out)("One or more files were not changed. Run with -d flag for debug log. ".concat(_constants.constants.emoji.warning)); | ||
| } else if (changes === 0) { | ||
| if (packageJson.version === version.raw) { | ||
| (0, _process.out)("Version is already ".concat(version.raw, " ").concat(_constants.constants.emoji.warning, " ")); | ||
| } else { | ||
| (0, _process.out)("No files changed. Run with -d flag for debug log. ".concat(_constants.constants.emoji.warning, " ")); | ||
| } | ||
| } else if (changes === locations.length) { | ||
| (0, _process.out)("".concat(packageJson.name, ": ").concat(packageJson.version, ": ==> ").concat(version.raw, " ").concat(_constants.constants.emoji.check, " ")); | ||
| } | ||
| } catch (e) { | ||
| (0, _process.die)(e); | ||
| } | ||
| }; | ||
| exports.mutateFiles = mutateFiles; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.cliArgumentExists = exports.logDie = exports.die = exports.out = void 0; | ||
| var out = function out(message) { | ||
| console.log("[RNVS] ".concat(message)); | ||
| }; | ||
| exports.out = out; | ||
| var die = function die(message) { | ||
| out(message); | ||
| process.exit(1); | ||
| }; | ||
| exports.die = die; | ||
| var logDie = function logDie(message, dieMessage) { | ||
| console.log(message); | ||
| die(dieMessage); | ||
| }; | ||
| exports.logDie = logDie; | ||
| var cliArgumentExists = function cliArgumentExists(flag) { | ||
| return !!process.argv.find(function (arg) { | ||
| return arg === flag; | ||
| }); | ||
| }; | ||
| exports.cliArgumentExists = cliArgumentExists; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.readPackageJson = void 0; | ||
| var fs = require('fs'); | ||
| var readPackageJson = function readPackageJson() { | ||
| var packageJson; | ||
| try { | ||
| packageJson = JSON.parse(String(fs.readFileSync('package.json'))); | ||
| if (packageJson) { | ||
| return packageJson; | ||
| } else { | ||
| throw new Error(); | ||
| } | ||
| } catch (e) { | ||
| return null; | ||
| } | ||
| }; | ||
| exports.readPackageJson = readPackageJson; |
| #!/usr/bin/env node | ||
| "use strict"; | ||
| var _process = require("./process.js"); | ||
| var _readPackageJson = require("./readPackageJson.js"); | ||
| var _createLocations = require("./createLocations.js"); | ||
| var _getPlatformConstant = require("./getPlatformConstant"); | ||
| var _createVersion = require("./createVersion"); | ||
| var _mutateFiles = require("./mutateFiles"); | ||
| var _createCliFlags = require("./createCliFlags"); | ||
| // Read package.json | ||
| var packageJson = (0, _readPackageJson.readPackageJson)() || (0, _process.die)('Could not read package.json.'); // Create and check for all CLI flags | ||
| var commandLineFlags = (0, _createCliFlags.createCliFlags)(); // Create the version object | ||
| var version = (0, _createVersion.createVersion)(process.argv[2]); // Use CLI args to determine the correct platform constant | ||
| var platform = (0, _getPlatformConstant.getPlatformConstant)(commandLineFlags); // Get locations for specified version, or all if no version is specified | ||
| var locations = (0, _createLocations.createLocations)(version, packageJson, platform); // If dryRun is set, just print versions | ||
| commandLineFlags.dryRun.set && (0, _process.logDie)(version, 'No changes applied.'); // Make the file mutations | ||
| (0, _mutateFiles.mutateFiles)(locations, commandLineFlags, packageJson, version); |
Sorry, the diff of this file is too big to display
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4
-33.33%22393
-83.93%17
-32%341
-34.8%