Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-native-version-setter

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-version-setter - npm Package Compare versions

Comparing version
3.0.2
to
3.0.3
+1
-1
package.json
{
"name": "react-native-version-setter",
"version": "3.0.2",
"version": "3.0.3",
"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("./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
* @param config
* @returns Array
*/
var createLocations = function createLocations(version, packageJson) {
var platform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var config = arguments.length > 3 ? arguments[3] : undefined;
var iosProjectName = config.iosProjectName || packageJson.name;
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.code), "versionName \"".concat(version.raw, "\"")],
platform: _constants.constants.platform.android
}, {
files: "./ios/".concat(iosProjectName, ".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");
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) {
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(''); // 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;
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;
}
"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 && _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.readConfig = void 0;
var _process = require("./process");
var fs = require('fs');
var readConfig = function readConfig(commandLineFlags) {
var config;
try {
config = String(fs.readFileSync('.rnvs.json'));
} catch (e) {
return {};
}
try {
config = JSON.parse(config);
commandLineFlags.debugLog.set && (0, _process.out)("Using config file.");
return config;
} catch (e) {
(0, _process.die)('Error reading .rnvs.json file.');
}
};
exports.readConfig = readConfig;
"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");
var _readConfig = require("./readConfig");
// 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)(); // Read config file
var config = (0, _readConfig.readConfig)(commandLineFlags); // 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, config); // 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);