diff --git a/cli/7zip.js b/cli/7zip.js index 6ca9e0b..b7e0873 100644 --- a/cli/7zip.js +++ b/cli/7zip.js @@ -8,7 +8,7 @@ * Dependencies. */ import minimist from 'minimist'; -import platformBinary from '../util/binary.mjs'; +import { Binary } from '../lib/utility.js'; import { createRequire } from 'module'; @@ -16,7 +16,7 @@ import { const require = createRequire( import.meta.url); const pack = require('../package.json'), - sevenBinary = platformBinary(); + sevenBinary = Binary(); /* * Arguments. diff --git a/cli/create.js b/cli/create.js index fbeae30..e0e4d66 100644 --- a/cli/create.js +++ b/cli/create.js @@ -9,7 +9,7 @@ */ import { createArchive -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/delete.js b/cli/delete.js index a48ab9d..67a7eaf 100644 --- a/cli/delete.js +++ b/cli/delete.js @@ -9,7 +9,7 @@ */ import { deleteArchive, -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/extract.js b/cli/extract.js index c520f83..6a8774d 100644 --- a/cli/extract.js +++ b/cli/extract.js @@ -9,7 +9,7 @@ */ import { extractArchive -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/full.js b/cli/full.js index 6bf07c1..41cdda2 100644 --- a/cli/full.js +++ b/cli/full.js @@ -9,7 +9,7 @@ */ import { fullArchive, -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/list.js b/cli/list.js index 0f52a81..30ff949 100644 --- a/cli/list.js +++ b/cli/list.js @@ -9,7 +9,7 @@ */ import { listArchive, -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/only.js b/cli/only.js index 72b06bb..15d8731 100644 --- a/cli/only.js +++ b/cli/only.js @@ -9,7 +9,7 @@ */ import { onlyArchive -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/rename.js b/cli/rename.js index 4b40cda..14e1ed5 100644 --- a/cli/rename.js +++ b/cli/rename.js @@ -9,7 +9,7 @@ */ import { renameArchive -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/sfx.js b/cli/sfx.js index 9c344c0..87a3b94 100644 --- a/cli/sfx.js +++ b/cli/sfx.js @@ -11,7 +11,7 @@ import { createSfxMac, createSfxLinux, createSfxWindows -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { join diff --git a/cli/test.js b/cli/test.js index 4398054..5a507b6 100644 --- a/cli/test.js +++ b/cli/test.js @@ -9,7 +9,7 @@ */ import { testArchive, -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/cli/update.js b/cli/update.js index 96a3416..b833119 100644 --- a/cli/update.js +++ b/cli/update.js @@ -9,7 +9,7 @@ */ import { updateArchive -} from '../lib/index.mjs'; +} from '../lib/index.js'; import minimist from 'minimist'; import { createRequire diff --git a/lib/createArchive.mjs b/lib/createArchive.mjs deleted file mode 100644 index 3756b26..0000000 --- a/lib/createArchive.mjs +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -import when from 'when'; -import { Files, ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, files, options, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === '+') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Convert array of files into a string if needed. - files = Files(files); - - // Create a string that can be parsed by `run`. - let command = 'a "' + filepath + '" ' + files; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - // When all is done resolve the Promise. - .then(function (args) { - return resolve(args); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('CreateArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/createSfx.mjs b/lib/createSfx.js similarity index 98% rename from lib/createSfx.mjs rename to lib/createSfx.js index f4fe6aa..c19b1f2 100644 --- a/lib/createSfx.mjs +++ b/lib/createSfx.js @@ -1,6 +1,6 @@ 'use strict'; -import createArchive from './createArchive.mjs'; +import { createArchive } from './index.js'; import when from 'when'; import { fileURLToPath @@ -11,7 +11,7 @@ import { join } from 'path'; import fs from 'fs-extra'; -import { Binary } from './utility.mjs'; +import { Binary } from './utility.js'; const platformTitle = { win32: 'Windows OS', @@ -116,7 +116,7 @@ archive.pipe(SfxDirectory, { * * @returns {Promise} Promise */ -export default function ( +export const createSfx = function ( name, files, destination = '', diff --git a/lib/deleteArchive.mjs b/lib/deleteArchive.mjs deleted file mode 100644 index ae58fb5..0000000 --- a/lib/deleteArchive.mjs +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -import { Files, Run } from './utility.mjs'; - -export default function (filepath, files, options, override = false) { - return new Promise(function (resolve, reject) { - - // Convert array of files into a string if needed. - files = Files(files); - - // Create a string that can be parsed by `run`. - let command = 'd "' + filepath + '" ' + files; - - // Start the command - Run('7z', command, options, override) - - // When all is done resolve the Promise. - .then(function (args) { - return resolve(args); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('DeleteArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/extractArchive.mjs b/lib/extractArchive.mjs deleted file mode 100644 index f4edaf4..0000000 --- a/lib/extractArchive.mjs +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -import when from 'when'; -import { ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, dest = '*', options = {}, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === '-') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Create a string that can be parsed by `run`. - let command = 'e "' + filepath + '" -o"' + dest + '" '; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - // When all is done resolve the Promise. - .then(function (args) { - return resolve(args); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('ExtractArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/fullArchive.mjs b/lib/fullArchive.mjs deleted file mode 100644 index 4cbcdeb..0000000 --- a/lib/fullArchive.mjs +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -import when from 'when'; -import { ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, dest = '*', options = {}, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === '-') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Create a string that can be parsed by `run`. - let command = 'x "' + filepath + '" -o"' + dest + '" '; - - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function () { - console.error('FullArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..1bbab20 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,677 @@ +'use strict'; + +import when from 'when'; +import { Files, ReplaceNativeSeparator, Run } from './utility.js'; + +import { createSfx } from './createSfx.js'; + +/** + * Create/add content to an archive. + * + * @param filepath {string} Path to the archive. + * @param files {string|array} Files to add. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const createArchive = SevenZip.createArchive = function (filepath, files, options, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === '+') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Convert array of files into a string if needed. + files = Files(files); + + // Create a string that can be parsed by `run`. + let command = 'a "' + filepath + '" ' + files; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + // When all is done resolve the Promise. + .then(function (args) { + return resolve(args); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('CreateArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + + +/** + * Delete content from an archive. + * + * @param filepath {string} Path to the archive. + * @param files {string|array} Files to remove. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const deleteArchive = SevenZip.deleteArchive = function (filepath, files, options, override = false) { + return new Promise(function (resolve, reject) { + + // Convert array of files into a string if needed. + files = Files(files); + + // Create a string that can be parsed by `run`. + let command = 'd "' + filepath + '" ' + files; + + // Start the command + Run('7z', command, options, override) + + // When all is done resolve the Promise. + .then(function (args) { + return resolve(args); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('DeleteArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + +/** + * Extract an archive. + * + * @param {string} archive Path to the archive. + * @param {string} dest Destination. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Extracted files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const extractArchive = SevenZip.extractArchive = function (filepath, dest = '*', options = {}, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === '-') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Create a string that can be parsed by `run`. + let command = 'e "' + filepath + '" -o"' + dest + '" '; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + // When all is done resolve the Promise. + .then(function (args) { + return resolve(args); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('ExtractArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + +/** + * Extract an archive with full paths. + * + * @param filepath {string} Path to the archive. + * @param dest {string} Destination. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Extracted files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const fullArchive = SevenZip.fullArchive = function (filepath, dest = '*', options = {}, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === '-') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Create a string that can be parsed by `run`. + let command = 'x "' + filepath + '" -o"' + dest + '" '; + + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function () { + console.error('FullArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + +/** + * List contents of archive. + * + * @param filepath {string} Path to the archive. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @progress {array} Listed files and directories. + * @resolve {Object} Tech spec about the archive. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const listArchive = SevenZip.listArchive = function (filepath, options, override = false) { + return when.promise(function (resolve, reject, progress) { + let spec = {}; + /* jshint maxlen: 130 */ + let regex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([\.D][\.R][\.H][\.S][\.A]) +(\d+) +(\d+)? +(.+)/; + /* jshint maxlen: 80 */ + + let buffer = ""; //Store incomplete line of a progress data. + + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + if (buffer.length > 0) { + data = buffer + data; + buffer = ""; + } + + data.split('\n').forEach(function (line) { + // Populate the tech specs of the archive that are passed to the + // resolve handler. + if (line.substr(0, 7) === 'Path = ') { + spec.path = line.substr(7, line.length); + } else if (line.substr(0, 7) === 'Type = ') { + spec.type = line.substr(7, line.length); + } else if (line.substr(0, 9) === 'Method = ') { + spec.method = line.substr(9, line.length); + } else if (line.substr(0, 16) === 'Physical Size = ') { + spec.physicalSize = parseInt(line.substr(16, line.length), 10); + } else if (line.substr(0, 15) === 'Headers Size = ') { + spec.headersSize = parseInt(line.substr(15, line.length), 10); + } else { + // Parse the stdout to find entries + let res = regex.exec(line); + if (res) { + let e = { + date: new Date(res[1]), + attr: res[2], + size: parseInt(res[3], 10), + name: ReplaceNativeSeparator(res[5]) + }; + entries.push(e); + } + // Line may be incomplete, Save it to the buffer. + else buffer = line; + } + }); + return entries; + } + + // Create a string that can be parsed by `run`. + let command = 'l "' + filepath + '" '; + Run((process.platform == 'win32' ? '7z' : '7za'), command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function () { + return resolve(spec); + }) + .catch(function (err) { + if (process.platform == 'win32') { + console.error('ListArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + } else { + return reject(err); + } + }); + }); +}; + +/** + * Extract only selected files from archive. + * + * @param {string} filepath Path to the archive. + * @param {string} dest Destination. + * @param {string|array} files Files in archive to extract. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Extracted files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const onlyArchive = SevenZip.onlyArchive = function (filepath, dest, files, options = {}, override = false) { + return when.promise(function (resolve, reject, progress) { + options = Object.assign(options, { files: files }); + + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === '-') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Create a string that can be parsed by `run`. + let command = 'e "' + filepath + '" -o"' + dest + '"'; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + // When all is done resolve the Promise. + .then(function (args) { + return resolve(args); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('OnlyArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + +/** + * Renames files in archive. + * + * @param filepath {string} Path to the archive. + * @param files {string} Files pairs to rename in archive. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const renameArchive = SevenZip.renameArchive = function (filepath, files, options, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === 'U') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Convert array of files into a string if needed. + files = Files(files); + + // Create a string that can be parsed by `run`. + let command = 'rn "' + filepath + '" ' + files; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function () { + return resolve(); + }) + .catch(function () { + console.error('RenameArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + }); +}; + +/** + * Test integrity of archive. + * + * @param filepath {string} Path to the archive. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Extracted files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const testArchive = SevenZip.testArchive = function (filepath, options, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === 'T') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Create a string that can be parsed by `run`. + let command = 't "' + filepath + '"'; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + // When all is done resolve the Promise. + .then(function (args) { + return resolve(args); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('TestArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + + }); +}; + +/** + * Update content to an archive. + * + * @param filepath {string} Path to the archive. + * @param files {string} Files to update. + * @param options {Object} An object of acceptable 7-zip switch options. + * @param override {boolean} should binary directory change? + * + * @resolve {array} Arguments passed to the child-process. + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const updateArchive = SevenZip.updateArchive = function (filepath, files, options, override = false) { + return when.promise(function (resolve, reject, progress) { + /** + * When a stdout is emitted, parse each line and search for a pattern.When + * the pattern is found, extract the file (or directory) name from it and + * pass it to an array. Finally returns this array. + */ + function onprogress(data) { + let entries = []; + data.split('\n').forEach(function (line) { + if (line.substr(0, 1) === 'U') { + entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); + } + }); + return entries; + } + + // Convert array of files into a string if needed. + files = Files(files); + + // Create a string that can be parsed by `run`. + let command = 'u "' + filepath + '" ' + files; + + // Start the command + Run('7z', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + + // When all is done resolve the Promise. + .then(function () { + return resolve(); + }) + + // Catch the error and pass it to the reject function of the Promise. + .catch(function () { + console.error('UpdateArchive failed using `7z`, retying with `7za`.'); + Run('7za', command, options, override) + .progress(function (data) { + return progress(onprogress(data)); + }) + .then(function (args) { + return resolve(args); + }) + .catch(function (err) { + return reject(err); + }); + }); + + }); +}; + +/** + * Creates Windows self extracting archive, an Installation Package. + * + * @param {String} name Application name. + * @param {Array} files Files to add. + * @param {String} destination Application root for the `SfxPackages` directory, will default to package root. + * - All Sfx package archives are stored in the **created** `SfxPackages` directory. + * - The `destination` directory must already exists. + * @param {Object} options Object for Installer config and 7-zip switch options. + * + * `{` + * + * `title:` - Window title message, Default "`name` installation package created on `Current running platform OS`" + * + * `beginPrompt:` - Begin Prompt message, Default "Do you want to install `name`?"" + * + * `progress:` - Value can be "yes" or "no". Default value is "yes". + * + * `runProgram:` - Command for executing. Default value is "setup.exe". + * Substring `% % T` will be replaced with path to temporary folder, + * where files were extracted + * + * `directory:` - Directory prefix for `RunProgram`. Default value is `.\` + * + * `executeFile:` Name of file for executing + * + * `executeParameters:` Parameters for `ExecuteFile` + * + * `}` + * + * `NOTE:` There are two ways to run program: `RunProgram` and `ExecuteFile`. + * - Use `RunProgram`, if you want to run some program from .7z archive. + * - Use `ExecuteFile`, if you want to open some document from .7z archive or + * if you want to execute some command from Windows. + * @param {String} type Application type `gui` or `console`. Default `gui`. Only `console` possible on **Linux** and **Mac** OS. + * + * @resolve {string} full filepath + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const createSfxWindows = SevenZip.windowsSfx = function (name, files, destination, options, type) { + return createSfx(name, files, destination, options, type, 'win32', '.exe'); +}; + +/** + * Creates Linux self extracting archive. + * + * @param {String} name Application name. + * @param {Array} files Files to add. + * @param {String} destination Application root for the `SfxPackages` directory, will default to package root. + * - All Sfx package archives are stored in the **created** `SfxPackages` directory. + * - The `destination` directory must already exists. + * @param {Object} options Object for 7-zip switch options. + * + * @resolve {string} full filepath + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const createSfxLinux = SevenZip.linuxSfx = function (name, files, destination, options) { + return createSfx(name, files, destination, options, 'console', 'linux', '.elf'); +}; + +/** + * Creates Apple macOS self extracting archive. + * + * @param {String} name Application name. + * @param {Array} files Files to add. + * @param {String} destination Application root for the `SfxPackages` directory, will default to package root. + * - All Sfx package archives are stored in the **created** `SfxPackages` directory. + * - The `destination` directory must already exists. + * @param {Object} options Object for 7-zip switch options. + * + * @resolve {string} full filepath + * @progress {array} Listed files and directories. + * @reject {Error} The error as issued by 7-Zip. + * + * @returns {Promise} Promise + */ +export const createSfxMac = SevenZip.macSfx = function (name, files, destination, options) { + return createSfx(name, files, destination, options, 'console', 'darwin', '.pkg'); +}; + +function SevenZip() { }; + +export default SevenZip; + +export const Zip = SevenZip; diff --git a/lib/index.mjs b/lib/index.mjs deleted file mode 100644 index fd4acf5..0000000 --- a/lib/index.mjs +++ /dev/null @@ -1,172 +0,0 @@ -'use strict'; - -import _createArchive from './createArchive.mjs'; -import _deleteArchive from './deleteArchive.mjs'; -import _extractArchive from './extractArchive.mjs'; -import _fullArchive from './fullArchive.mjs'; -import _listArchive from './listArchive.mjs'; -import _onlyArchive from './onlyArchive.mjs'; -import _renameArchive from './renameArchive.mjs'; -import _testArchive from './testArchive.mjs'; -import _updateArchive from './updateArchive.mjs'; -import createSfx from './createSfx.mjs'; - -function SevenZip() { }; - -/** - * Create/add content to an archive. - * - * @param filepath {string} Path to the archive. - * @param files {string|array} Files to add. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Listed files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const createArchive = SevenZip.createArchive = _createArchive; - -/** - * Delete content from an archive. - * - * @param filepath {string} Path to the archive. - * @param files {string|array} Files to remove. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const deleteArchive = SevenZip.deleteArchive = _deleteArchive; - -/** - * Extract an archive. - * - * @param {string} archive Path to the archive. - * @param {string} dest Destination. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Extracted files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const extractArchive = SevenZip.extractArchive = _extractArchive; - -/** - * Extract an archive with full paths. - * - * @param filepath {string} Path to the archive. - * @param dest {string} Destination. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Extracted files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const fullArchive = SevenZip.fullArchive = _fullArchive; - -/** - * List contents of archive. - * - * @param filepath {string} Path to the archive. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @progress {array} Listed files and directories. - * @resolve {Object} Tech spec about the archive. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const listArchive = SevenZip.listArchive = _listArchive; - -/** - * Extract only selected files from archive. - * - * @param {string} filepath Path to the archive. - * @param {string} dest Destination. - * @param {string|array} files Files in archive to extract. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Extracted files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const onlyArchive = SevenZip.onlyArchive = _onlyArchive; - -/** - * Renames files in archive. - * - * @param filepath {string} Path to the archive. - * @param files {string} Files pairs to rename in archive. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Listed files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const renameArchive = SevenZip.renameArchive = _renameArchive; - -/** - * Test integrity of archive. - * - * @param filepath {string} Path to the archive. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Extracted files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const testArchive = SevenZip.testArchive = _testArchive; - -/** - * Update content to an archive. - * - * @param filepath {string} Path to the archive. - * @param files {string} Files to update. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Listed files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export const updateArchive = SevenZip.updateArchive = _updateArchive; - -export const createSfxWindows = SevenZip.windowsSfx = function (name, files, destination, options, type) { - return createSfx(name, files, destination, options, type, 'win32', '.exe'); -}; - -export const createSfxLinux = SevenZip.linuxSfx = function (name, files, destination, options) { - return createSfx(name, files, destination, options, 'console', 'linux', '.elf'); -}; - -export const createSfxMac = SevenZip.macSfx = function (name, files, destination, options) { - return createSfx(name, files, destination, options, 'console', 'darwin', '.pkg'); -}; - -export default SevenZip; - -export const Zip = SevenZip; diff --git a/lib/listArchive.mjs b/lib/listArchive.mjs deleted file mode 100644 index fedb8bc..0000000 --- a/lib/listArchive.mjs +++ /dev/null @@ -1,86 +0,0 @@ -'use strict'; - -import when from 'when'; -import { ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, options, override = false) { - return when.promise(function (resolve, reject, progress) { - let spec = {}; - /* jshint maxlen: 130 */ - let regex = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([\.D][\.R][\.H][\.S][\.A]) +(\d+) +(\d+)? +(.+)/; - /* jshint maxlen: 80 */ - - let buffer = ""; //Store incomplete line of a progress data. - - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - if (buffer.length > 0) { - data = buffer + data; - buffer = ""; - } - - data.split('\n').forEach(function (line) { - // Populate the tech specs of the archive that are passed to the - // resolve handler. - if (line.substr(0, 7) === 'Path = ') { - spec.path = line.substr(7, line.length); - } else if (line.substr(0, 7) === 'Type = ') { - spec.type = line.substr(7, line.length); - } else if (line.substr(0, 9) === 'Method = ') { - spec.method = line.substr(9, line.length); - } else if (line.substr(0, 16) === 'Physical Size = ') { - spec.physicalSize = parseInt(line.substr(16, line.length), 10); - } else if (line.substr(0, 15) === 'Headers Size = ') { - spec.headersSize = parseInt(line.substr(15, line.length), 10); - } else { - // Parse the stdout to find entries - let res = regex.exec(line); - if (res) { - let e = { - date: new Date(res[1]), - attr: res[2], - size: parseInt(res[3], 10), - name: ReplaceNativeSeparator(res[5]) - }; - entries.push(e); - } - // Line may be incomplete, Save it to the buffer. - else buffer = line; - } - }); - return entries; - } - - // Create a string that can be parsed by `run`. - let command = 'l "' + filepath + '" '; - Run((process.platform == 'win32' ? '7z' : '7za'), command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function () { - return resolve(spec); - }) - .catch(function (err) { - if (process.platform == 'win32') { - console.error('ListArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - } else { - return reject(err); - } - }); - }); -}; diff --git a/lib/onlyArchive.mjs b/lib/onlyArchive.mjs deleted file mode 100644 index 81bee8e..0000000 --- a/lib/onlyArchive.mjs +++ /dev/null @@ -1,69 +0,0 @@ -'use strict'; - -import when from 'when'; -import { ReplaceNativeSeparator, Run } from './utility.mjs'; - -/** - * Extract only selected files from archive. - * - * @param {string} filepath Path to the archive. - * @param {string} dest Destination. - * @param {string|array} files Files in archive to extract. - * @param options {Object} An object of acceptable 7-zip switch options. - * @param override {boolean} should binary directory change? - * - * @resolve {array} Arguments passed to the child-process. - * @progress {array} Extracted files and directories. - * @reject {Error} The error as issued by 7-Zip. - * - * @returns {Promise} Promise - */ -export default function (filepath, dest, files, options = {}, override = false) { - return when.promise(function (resolve, reject, progress) { - options = Object.assign(options, { files: files }); - - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === '-') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Create a string that can be parsed by `run`. - let command = 'e "' + filepath + '" -o"' + dest + '"'; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - // When all is done resolve the Promise. - .then(function (args) { - return resolve(args); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('OnlyArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/renameArchive.mjs b/lib/renameArchive.mjs deleted file mode 100644 index 70d2b57..0000000 --- a/lib/renameArchive.mjs +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -import when from 'when'; -import { Files, ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, files, options, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === 'U') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Convert array of files into a string if needed. - files = Files(files); - - // Create a string that can be parsed by `run`. - let command = 'rn "' + filepath + '" ' + files; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function () { - return resolve(); - }) - .catch(function () { - console.error('RenameArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - }); -}; diff --git a/lib/testArchive.mjs b/lib/testArchive.mjs deleted file mode 100644 index c0f8642..0000000 --- a/lib/testArchive.mjs +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -import when from 'when'; -import { ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, options, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === 'T') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Create a string that can be parsed by `run`. - let command = 't "' + filepath + '"'; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - // When all is done resolve the Promise. - .then(function (args) { - return resolve(args); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('TestArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - - }); -}; diff --git a/lib/updateArchive.mjs b/lib/updateArchive.mjs deleted file mode 100644 index 7ad0577..0000000 --- a/lib/updateArchive.mjs +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -import when from 'when'; -import { Files, ReplaceNativeSeparator, Run } from './utility.mjs'; - -export default function (filepath, files, options, override = false) { - return when.promise(function (resolve, reject, progress) { - /** - * When a stdout is emitted, parse each line and search for a pattern.When - * the pattern is found, extract the file (or directory) name from it and - * pass it to an array. Finally returns this array. - */ - function onprogress(data) { - let entries = []; - data.split('\n').forEach(function (line) { - if (line.substr(0, 1) === 'U') { - entries.push(ReplaceNativeSeparator(line.substr(2, line.length))); - } - }); - return entries; - } - - // Convert array of files into a string if needed. - files = Files(files); - - // Create a string that can be parsed by `run`. - let command = 'u "' + filepath + '" ' + files; - - // Start the command - Run('7z', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - - // When all is done resolve the Promise. - .then(function () { - return resolve(); - }) - - // Catch the error and pass it to the reject function of the Promise. - .catch(function () { - console.error('UpdateArchive failed using `7z`, retying with `7za`.'); - Run('7za', command, options, override) - .progress(function (data) { - return progress(onprogress(data)); - }) - .then(function (args) { - return resolve(args); - }) - .catch(function (err) { - return reject(err); - }); - }); - - }); -}; diff --git a/lib/utility.mjs b/lib/utility.js similarity index 100% rename from lib/utility.mjs rename to lib/utility.js diff --git a/package.json b/package.json index eac0a47..dfc711c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.1", "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.mjs", + "main": "lib/index.js", "scripts": { "test": "mocha --recursive test/ --timeout=0", "report": "npx c8 npm test", diff --git a/test/lib/SevenZip.test.js b/test/lib/SevenZip.test.js index a08217b..bd11cc5 100644 --- a/test/lib/SevenZip.test.js +++ b/test/lib/SevenZip.test.js @@ -1,7 +1,7 @@ /*global describe, it */ 'use strict'; import chai from 'chai'; -import SevenZip from '../../lib/index.mjs'; +import SevenZip from '../../lib/index.js'; const expect = chai.expect; describe('Class: `SevenZip`', function () { diff --git a/test/lib/createArchive.test.js b/test/lib/createArchive.test.js index c6f40a1..5f3f2d9 100644 --- a/test/lib/createArchive.test.js +++ b/test/lib/createArchive.test.js @@ -3,15 +3,15 @@ import chai from 'chai'; import { createArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `createArchive`', function () { it('should return an error on 7z error', function (done) { createArchive('.tmp/test/addnot.7z', '.tmp/test/nothere', { - '???': true - }) + '???': true + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); diff --git a/test/lib/createSfx.test.js b/test/lib/createSfx.test.js index ef985fa..707adc5 100644 --- a/test/lib/createSfx.test.js +++ b/test/lib/createSfx.test.js @@ -2,7 +2,7 @@ 'use strict'; import chai from 'chai'; import fs from 'fs-extra'; -import createSfx from '../../lib/createSfx.mjs'; +import { createSfx } from '../../lib/createSfx.js'; const expect = chai.expect; describe('Method: `createSfx`', function () { @@ -21,9 +21,9 @@ describe('Method: `createSfx`', function () { it('should return an error on 7z error', function (done) { createSfx('test.exe', '.tmp/test/nothere', - '.tmp/test/', { - '???': true - }) + '.tmp/test/', { + '???': true + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); diff --git a/test/lib/createSfxLinux.test.js b/test/lib/createSfxLinux.test.js index 7c27fde..2ec5657 100644 --- a/test/lib/createSfxLinux.test.js +++ b/test/lib/createSfxLinux.test.js @@ -3,7 +3,7 @@ import chai from 'chai'; import { createSfxLinux -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; import fs from 'fs-extra'; const expect = chai.expect; diff --git a/test/lib/createSfxMac.test.js b/test/lib/createSfxMac.test.js index f037e2d..16be5e9 100644 --- a/test/lib/createSfxMac.test.js +++ b/test/lib/createSfxMac.test.js @@ -3,7 +3,7 @@ import chai from 'chai'; import { createSfxMac -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; import fs from 'fs-extra'; const expect = chai.expect; diff --git a/test/lib/createSfxWindows.test.js b/test/lib/createSfxWindows.test.js index 9d86119..8488104 100644 --- a/test/lib/createSfxWindows.test.js +++ b/test/lib/createSfxWindows.test.js @@ -3,7 +3,7 @@ import chai from 'chai'; import { createSfxWindows -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; import fs from 'fs-extra'; const expect = chai.expect; diff --git a/test/lib/deleteArchive.test.js b/test/lib/deleteArchive.test.js index bb074b6..fa6df70 100644 --- a/test/lib/deleteArchive.test.js +++ b/test/lib/deleteArchive.test.js @@ -5,15 +5,15 @@ import fs from 'fs-extra'; import { deleteArchive, fullArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `deleteArchive`', function () { it('should return an error on 7z error', function (done) { deleteArchive('.tmp/test/addnot.7z', '.tmp/test/nothere', { - '???': true - }) + '???': true + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); @@ -31,9 +31,9 @@ describe('Method: `deleteArchive`', function () { it('should accept array as source', function (done) { fs.copySync('test/zip.7z', '.tmp/d.7z'); deleteArchive('.tmp/d.7z', [ - 'zip/file0.txt', - 'zip/file1.txt', - ]) + 'zip/file0.txt', + 'zip/file1.txt', + ]) .then(function () { fullArchive('.tmp/d.7z', '.tmp/d').then(function () { let files = fs.readdirSync('.tmp/d/zip'); diff --git a/test/lib/extractArchive.test.js b/test/lib/extractArchive.test.js index d6fdba7..75b7a4a 100644 --- a/test/lib/extractArchive.test.js +++ b/test/lib/extractArchive.test.js @@ -4,7 +4,7 @@ import chai from 'chai'; import fs from 'fs-extra'; import { extractArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `extractArchive`', function () { @@ -19,8 +19,8 @@ describe('Method: `extractArchive`', function () { it('should return an error on output duplicate', function (done) { extractArchive('test/zip.7z', '.tmp/test', { - o: '.tmp/test/duplicate' - }) + o: '.tmp/test/duplicate' + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); diff --git a/test/lib/fullArchive.test.js b/test/lib/fullArchive.test.js index 48a7c9e..3b55da8 100644 --- a/test/lib/fullArchive.test.js +++ b/test/lib/fullArchive.test.js @@ -4,7 +4,7 @@ import chai from 'chai'; import fs from 'fs-extra'; import { fullArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `fullArchive`', function () { @@ -19,8 +19,8 @@ describe('Method: `fullArchive`', function () { it('should return an error on output duplicate', function (done) { fullArchive('test/zip.7z', '.tmp/test', { - o: '.tmp/test/duplicate' - }) + o: '.tmp/test/duplicate' + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); @@ -45,9 +45,9 @@ describe('Method: `fullArchive`', function () { it('should extract only given wildcards', function (done) { fullArchive('test/wildcards.zip', '.tmp/test/', { - wildcards: ['*.txt'], - r: true - }) + wildcards: ['*.txt'], + r: true + }) .progress(function (files) { files.forEach(function (f) { expect(f).to.include('.txt'); diff --git a/test/lib/listArchive.test.js b/test/lib/listArchive.test.js index b8132ac..c09b523 100644 --- a/test/lib/listArchive.test.js +++ b/test/lib/listArchive.test.js @@ -3,7 +3,7 @@ import chai from 'chai'; import { listArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; @@ -41,8 +41,8 @@ describe('Method: `listArchive`', function () { it('should return an tech spec on fulfill', function (done) { listArchive('test/zip.7z', { - r: true - }) + r: true + }) .then(function (spec) { expect(spec).to.have.property('path'); expect(spec).to.have.property('type'); diff --git a/test/lib/onlyArchive.test.js b/test/lib/onlyArchive.test.js index 101b188..0ede681 100644 --- a/test/lib/onlyArchive.test.js +++ b/test/lib/onlyArchive.test.js @@ -4,7 +4,7 @@ import chai from 'chai'; import fs from 'fs-extra'; import { onlyArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `onlyArchive`', function () { diff --git a/test/lib/renameArchive.test.js b/test/lib/renameArchive.test.js index 0a3e05b..cc77c3b 100644 --- a/test/lib/renameArchive.test.js +++ b/test/lib/renameArchive.test.js @@ -4,15 +4,15 @@ import chai from 'chai'; import fs from 'fs-extra'; import { renameArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `renameArchive`', function () { it('should return an error on 7z error', function (done) { renameArchive('.tmp/test/addnot.7z', '.tmp/test/nothere', { - '???': true - }) + '???': true + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); @@ -22,8 +22,8 @@ describe('Method: `renameArchive`', function () { it('should return entries on progress', function (done) { fs.copySync('test/zip.zip', '.tmp/test/update.zip'); renameArchive('.tmp/test/update.zip', ['CHANGELOG.md', 'TODO.doc'], { - w: 'test' - }) + w: 'test' + }) .progress(function (entries) { expect(entries.length).to.be.at.least(1); done(); diff --git a/test/lib/testArchive.test.js b/test/lib/testArchive.test.js index fd332d6..04ea096 100644 --- a/test/lib/testArchive.test.js +++ b/test/lib/testArchive.test.js @@ -3,7 +3,7 @@ import chai from 'chai'; import { testArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `testArchive`', function () { @@ -18,8 +18,8 @@ describe('Method: `testArchive`', function () { it('should return entries on progress', function (done) { testArchive('test/zip.7z', { - r: true - }) + r: true + }) .progress(function (entries) { expect(entries.length).to.be.at.least(1); }) diff --git a/test/lib/updateArchive.test.js b/test/lib/updateArchive.test.js index 9bf1959..8be6f0e 100644 --- a/test/lib/updateArchive.test.js +++ b/test/lib/updateArchive.test.js @@ -4,15 +4,15 @@ import chai from 'chai'; import fs from 'fs-extra'; import { updateArchive -} from '../../lib/index.mjs'; +} from '../../lib/index.js'; const expect = chai.expect; describe('Method: `updateArchive`', function () { it('should return an error on 7z error', function (done) { updateArchive('.tmp/test/addnot.7z', '.tmp/test/nothere', { - '???': true - }) + '???': true + }) .catch(function (err) { expect(err).to.be.an.instanceof(Error); done(); @@ -22,8 +22,8 @@ describe('Method: `updateArchive`', function () { it('should return entries on progress', function (done) { fs.copySync('test/zip.7z', '.tmp/test/update.7z'); updateArchive('.tmp/test/update.7z', '*.md', { - w: 'test' - }) + w: 'test' + }) .progress(function (entries) { expect(entries.length).to.be.at.least(1); done(); diff --git a/test/lib/utility.test.js b/test/lib/utility.test.js index 7bb1164..80e7724 100644 --- a/test/lib/utility.test.js +++ b/test/lib/utility.test.js @@ -2,7 +2,7 @@ 'use strict'; import chai from 'chai'; -import { Binary, Files, ReplaceNativeSeparator, Run, Switches } from '../../lib/utility.mjs'; +import { Binary, Files, ReplaceNativeSeparator, Run, Switches } from '../../lib/utility.js'; import { sep } from 'path'; const expect = chai.expect;