mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
implement getAppInfo and uploadApp methods
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
const Unzip = require('isomorphic-unzip')
|
||||
const { isBrowser, decodeNullUnicode } = require('./utils')
|
||||
const Unzip = require('isomorphic-unzip');
|
||||
const { isBrowser, decodeNullUnicode } = require('./utils');
|
||||
import { enumZipEntries, readEntire } from '../../bundle';
|
||||
|
||||
class Zip {
|
||||
constructor (file) {
|
||||
constructor(file) {
|
||||
if (isBrowser()) {
|
||||
if (!(file instanceof window.Blob || typeof file.size !== 'undefined')) {
|
||||
throw new Error('Param error: [file] must be an instance of Blob or File in browser.')
|
||||
throw new Error(
|
||||
'Param error: [file] must be an instance of Blob or File in browser.',
|
||||
);
|
||||
}
|
||||
this.file = file
|
||||
this.file = file;
|
||||
} else {
|
||||
if (typeof file !== 'string') {
|
||||
throw new Error('Param error: [file] must be file path in Node.')
|
||||
throw new Error('Param error: [file] must be file path in Node.');
|
||||
}
|
||||
this.file = require('path').resolve(file)
|
||||
this.file = require('path').resolve(file);
|
||||
}
|
||||
this.unzip = new Unzip(this.file)
|
||||
this.unzip = new Unzip(this.file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,27 +25,42 @@ class Zip {
|
||||
* @param {Array} regexps // regexps for matching files
|
||||
* @param {String} type // return type, can be buffer or blob, default buffer
|
||||
*/
|
||||
getEntries (regexps, type = 'buffer') {
|
||||
regexps = regexps.map(regex => decodeNullUnicode(regex))
|
||||
getEntries(regexps, type = 'buffer') {
|
||||
regexps = regexps.map((regex) => decodeNullUnicode(regex));
|
||||
return new Promise((resolve, reject) => {
|
||||
this.unzip.getBuffer(regexps, { type }, (err, buffers) => {
|
||||
err ? reject(err) : resolve(buffers)
|
||||
})
|
||||
})
|
||||
err ? reject(err) : resolve(buffers);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* get entry by regex, return an instance of Buffer or Blob
|
||||
* @param {Regex} regex // regex for matching file
|
||||
* @param {String} type // return type, can be buffer or blob, default buffer
|
||||
*/
|
||||
getEntry (regex, type = 'buffer') {
|
||||
regex = decodeNullUnicode(regex)
|
||||
getEntry(regex, type = 'buffer') {
|
||||
regex = decodeNullUnicode(regex);
|
||||
return new Promise((resolve, reject) => {
|
||||
this.unzip.getBuffer([regex], { type }, (err, buffers) => {
|
||||
err ? reject(err) : resolve(buffers[regex])
|
||||
})
|
||||
})
|
||||
console.log(buffers);
|
||||
err ? reject(err) : resolve(buffers[regex]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async getEntryFromHarmonyApp(regex) {
|
||||
try {
|
||||
let originSource;
|
||||
await enumZipEntries(this.file, (entry, zipFile) => {
|
||||
if (regex.test(entry.fileName)) {
|
||||
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||
}
|
||||
});
|
||||
return originSource;
|
||||
} catch (error) {
|
||||
console.error('Error in getEntryFromHarmonyApp:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Zip
|
||||
module.exports = Zip;
|
||||
|
Reference in New Issue
Block a user