Skip to content

Commit

Permalink
update version/dependencies, and refactor routines from them
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Dec 25, 2020
1 parent 7b99e2f commit 2f2b5ef
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
7 changes: 4 additions & 3 deletions installer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { spawnSync } from 'child_process';
import { unpack } from 'node-unar';
import { wget, isString } from 'node-wget-fetch';
import { isWindows } from 'node-sys';

const __filename = fileURLToPath(
import.meta.url);
Expand Down Expand Up @@ -150,7 +151,7 @@ function makeExecutable(binary = [], binaryFolder = '') {

let extractionPromises = [];
let platforms = [linuxPlatform, appleMacPlatform, windowsOtherPlatform];
if (process.platform == 'win32')
if (isWindows())
platforms = [linuxPlatform, appleMacPlatform, windowsPlatform, windowsOtherPlatform];

platforms.forEach((dataFor) => {
Expand Down Expand Up @@ -214,8 +215,8 @@ Promise.all(extractionPromises)
extracted.forEach(function (dataFor) {
if (dataFor.sfxModules && dataFor.platform == process.platform) {
try {
const directory = (process.platform == "win32") ? dataFor.binaryDestinationDir : binaryDestination;
extraUnpack(join(binaryDestination, (process.platform == "win32") ? '7z.exe' : '7z'),
const directory = isWindows() ? dataFor.binaryDestinationDir : binaryDestination;
extraUnpack(join(binaryDestination, (isWindows() ? '7z.exe' : '7z')),
dataFor.extraSourceFile,
directory,
dataFor.sfxModules
Expand Down
5 changes: 3 additions & 2 deletions lib/createSfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'path';
import fs from 'fs-extra';
import { Binary } from './utility.js';
import { isArray, isWindows } from 'node-sys';

const platformTitle = {
win32: 'Windows OS',
Expand Down Expand Up @@ -132,7 +133,7 @@ export const createSfx = function (
let directory = (destination != '' && fs.existsSync(destination)) ? destination : getPath('when');
let SfxDirectory = join(directory, 'SfxPackages');
fs.ensureDirSync(SfxDirectory);
let override = ((process.platform == 'win32') && (platform == 'linux' || platform == 'darwin'));
let override = (isWindows() && (platform == 'linux' || platform == 'darwin'));
let binaryDirectory = Binary(override);
let configFile = join(binaryDirectory.path, 'config.txt');
//let configFile = join(SfxDirectory, 'config.txt');
Expand Down Expand Up @@ -182,7 +183,7 @@ export const createSfx = function (

let sfxModule = (type == 'gui') ? '7zwin32.sfx' : '7zCon' + platform + '.sfx';
let sfx = name.includes(extension) ? name : name + extension;
let list = Array.isArray(files) ? [configFile].concat(files) : configFile + ' ' + files;
let list = isArray(files) ? [configFile].concat(files) : configFile + ' ' + files;
sfx = join(SfxDirectory, sfx);
let params = Object.assign(options, {
sfx: sfxModule
Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import when from 'when';
import { Files, ReplaceNativeSeparator, Run } from './utility.js';

import { createSfx } from './createSfx.js';
import { isWindows } from 'node-sys';

function retry(command, options, override, progress, onprogress, resolve, reject, archive, noRetry = false) {
// Start the command
Expand Down Expand Up @@ -267,15 +268,15 @@ export const listArchive = SevenZip.listArchive = function (filepath, options, o
// Create a string that can be parsed by `run`.
let command = 'l "' + filepath + '" ';

Run((process.platform == 'win32' ? '7z' : '7za'), command, options, override)
Run((isWindows() ? '7z' : '7za'), command, options, override)
.progress(function (data) {
return progress(onprogress(data));
})
.then(function () {
return resolve(spec);
})
.catch(function (err) {
if (process.platform == 'win32') {
if (isWindows()) {
console.error('ListArchive failed using `7z`, retying with `7za`.');
Run('7za', command, options, override)
.progress(function (data) {
Expand Down
10 changes: 5 additions & 5 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import when from 'when';
import { EOL } from 'os';
import { fileURLToPath } from 'url';
import { dirname, join, sep, sep as nativeSeparator, normalize } from 'path';
import { spawning, isUndefined, isArray, isString } from 'node-sys';
import { spawning, isUndefined, isArray, isString, isWindows, isBool } from 'node-sys';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export const Binary = function (override = false, binary = '7z') {
let path = join(__dirname, '..', "binaries", (override == true ? process.platform + sep + 'other32' : process.platform));
let filename = (process.platform == "win32") ? binary + '.exe' : binary;
let path = join(__dirname, '..', "binaries", (override === true ? process.platform + sep + 'other32' : process.platform));
let filename = isWindows() ? binary + '.exe' : binary;
return {
path: path,
filename: filename,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const Run = function (binary = '7z', command = null, switches = {}, overr
// Parse the command variable. If the command is not a string reject the
// Promise. Otherwise transform the command into two variables: the command
// name and the arguments.
if (typeof command !== 'string' || typeof binary !== 'string') {
if (!isString(command) || !isString(binary)) {
return reject(new Error('Command and Binary must be a string'));
}

Expand Down Expand Up @@ -222,7 +222,7 @@ export const Switches = function (switches) {
// Switches with a value. Detect if the value contains a space. If it does
// wrap the value with double quotes. Else just add the switch and its value
// to the string. Doubles quotes are used for parsing with a RegExp later.
if (typeof switches[s] !== 'boolean') {
if (!isBool(switches[s])) {

// Special treatment for wildcards
if (s === 'wildcards') {
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-7z-archive",
"version": "1.0.2",
"version": "1.0.3",
"description": "ESM front-end to 7-Zip, featuring alternative full 7z CLI tools, binaries for Linux, Windows, Mac OSX, seamlessly create 7zip SFX self extracting archives targeting different platforms.",
"type": "module",
"main": "lib/index.js",
Expand Down Expand Up @@ -73,8 +73,8 @@
"node": ">=12.0.0"
},
"dependencies": {
"node-unar": "^1.0.5",
"node-sys": "^1.1.1",
"node-unar": "^1.0.6",
"node-sys": "^1.1.3",
"fs-extra": "^9.0.1",
"node-wget-fetch": "^1.1.0",
"when": "^3.7.8",
Expand Down

0 comments on commit 2f2b5ef

Please sign in to comment.