Skip to content

Commit

Permalink
Merge pull request #26 from triniwiz/feat-v4
Browse files Browse the repository at this point in the history
feat(): v4
  • Loading branch information
triniwiz authored Dec 4, 2019
2 parents 629d693 + 3b0091f commit c109fc3
Show file tree
Hide file tree
Showing 50 changed files with 2,423 additions and 647 deletions.
68 changes: 39 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,65 @@ matrix:
- stage: "Lint"
language: node_js
os: linux
node_js: "8"
node_js: "12"
script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint
- stage: "WebPack, Build and Test"
- stage: "WebPack"
os: osx
env:
- WebPack="iOS"
osx_image: xcode9.3
language: node_js
node_js: "8"
osx_image: xcode10.2
language: node_js
node_js: "12"
jdk: oraclejdk8
script: cd demo && npm run build.plugin && npm i && tns build ios --bundle --env.uglify
before_script: pod repo update
script: cd demo && npm run build.plugin && npm i && tns build ios --env.uglify
- language: android
os: linux
env:
- WebPack="Android"
jdk: oraclejdk8
before_install: nvm install 8
script: cd demo && npm run build.plugin && npm i && tns build android --bundle --env.uglify --env.snapshot
before_install: nvm install 12
script: cd demo && npm run build.plugin && npm i && tns build android --env.uglify --env.snapshot
- stage: "Tests"
os: osx
env:
- iOS="UnitTests"
osx_image: xcode10
language: node_js
node_js: "12"
jdk: oraclejdk8
before_script:
- ios-sim start --devicetypeid "iPhone-8-Plus, 12.0"
before_install:
- pip install --upgrade pip
- pip install --user --upgrade matplotlib
- pip install six
script:
- cd src && npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch
- language: android
env:
- BuildAndroid="27"
os: linux
env:
- Android="UnitTests"
jdk: oraclejdk8
before_install: nvm install stable
before_install: nvm install 12
before_script:
- echo no | android create avd --force -n test -t android-21 -b armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
script:
- cd src && npm i && npm run tsc && cd ../demo && tns build android
- os: osx
env:
- BuildiOS="11"
- Xcode="9.3"
osx_image: xcode9.3
language: node_js
node_js: "8"
jdk: oraclejdk8
script:
- cd src && npm i && npm run tsc && cd ../demo && tns build ios
- cd src && npm i && npm run tsc && npm run tslint && cd ../demo && tns build android
- travis_wait travis_retry tns test android --justlaunch

android:
components:
- tools
- platform-tools
- build-tools-27.0.3
- android-27
- android-26
- android-23
- build-tools-28.0.3
- android-28
- extra-android-m2repository
- sys-img-armeabi-v7a-android-21

install:
- echo no | npm install -g nativescript
- tns usage-reporting disable
- tns error-reporting disable
- echo no | npm install -g nativescript
- tns usage-reporting disable
- tns error-reporting disable
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@

### Zip

```ts
```typescript
import { Zip } from "nativescript-zip";
import * as fs from "file-system";
import * as fs from "tns-core-modules/file-system";
let path = fs.path.join(fs.knownFolders.temp().path, "stuff");
let dest = fs.path.join(fs.knownFolders.currentApp().path, "/assets");
Zip.zip(path,dest);
let dest = fs.path.join(fs.knownFolders.documents().path, "/assets");
Zip.zip({
folder: path,
destination: dest
});
```

#### Progress

```ts
```typescript
import { Zip } from "nativescript-zip";
import * as fs from "file-system";
import * as fs from "tns-core-modules/file-system";
let path = fs.path.join(fs.knownFolders.temp().path, "stuff");
let dest = fs.path.join(fs.knownFolders.currentApp().path, "/assets");
Zip.zipWithProgress(path,dest,onZipProgress);
let dest = fs.path.join(fs.knownFolders.documents().path, "/assets");
Zip.zip({
folder: path,
destination: dest,
onProgress: onZipProgress
});

function onZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
Expand All @@ -44,24 +51,31 @@ function onZipProgress(percent: number) {

### Unzip

```ts
```typescript
import { Zip } from "nativescript-zip";
import * as fs from "file-system";
import * as fs from "tns-core-modules/file-system";
let zipPath = fs.path.join(fs.knownFolders.temp().path, "stuff.zip");
let dest = fs.path.join(fs.knownFolders.currentApp().path, "/assets");
Zip.unzip(zipPath,dest);
let dest = fs.path.join(fs.knownFolders.documents().path, "/assets");
Zip.unzip({
archive: zipPath,
destination: dest
});
```

#### Progress

```ts
```typescript
import { Zip } from "nativescript-zip";
import * as fs from "file-system";
import * as fs from "tns-core-modules/file-system";
let zipPath = fs.path.join(fs.knownFolders.temp().path, "stuff.zip");
let dest = fs.path.join(fs.knownFolders.currentApp().path, "/assets");
Zip.unzipWithProgress(zipPath,dest,onZipProgress);

function onZipProgress(percent: number) {
let dest = fs.path.join(fs.knownFolders.documennts().path, "/assets");
Zip.unzip({
archive: zipPath,
destination: dest,
onProgress: onUnZipProgress
});

function onUnZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
}
```
Expand Down
6 changes: 3 additions & 3 deletions demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import "./bundle-config";
import * as application from 'tns-core-modules/application';
application.start({ moduleName: "main-page" });
import * as application from 'tns-core-modules/application';

application.run({moduleName: 'main-page'});
Binary file added demo/app/assets/SampleVideo_1280x720_30mb.mp4
Binary file not shown.
9 changes: 0 additions & 9 deletions demo/app/bundle-config.ts

This file was deleted.

109 changes: 74 additions & 35 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,95 @@ let model: HelloWorldModel;

// Event handler for Page 'loaded' event attached in main-page.xml
export function pageLoaded(args: observable.EventData) {
// Get the event sender
let page = <pages.Page>args.object;
page.bindingContext = model = new HelloWorldModel();
// Get the event sender
let page = <pages.Page>args.object;
page.bindingContext = model = new HelloWorldModel();
}

const dest = fs.Folder.fromPath(
fs.path.join(fs.knownFolders.temp().path, 'books')
fs.path.join(fs.knownFolders.temp().path, 'books')
);
const dir = () => {
return fs.path.join(fs.knownFolders.currentApp().path, 'assets');
};
const out = () => {
return fs.path.join(fs.knownFolders.temp().path, 'zip_files_out.zip');
};

export function create() {
Zip.zip({
directory: dir(),
archive: out(),
onProgress: (progress) => {
console.log('create: progress: ' + progress)
}
}).then(archive => {
console.log('create success: ', archive);
}).catch(error => {
console.log('create error: ', error);
})
}

export function extract() {
Zip.unzip({
archive: out(),
onProgress: (progress) => {
console.log('extract: progress: ' + progress)
}
}).then(path => {
console.log('extract success: ', path)
})
.catch(error => {
console.log('extract error: ', error)
})

}

export function unzip() {
console.log(`begin unzip`);
let appPath = fs.knownFolders.currentApp().path;
let testZipFile = fs.path.join(appPath, 'test_70mb.zip');
// Zip.unzip(testZipFile, appPath);
Zip.unzipWithProgress(testZipFile, dest.path, onZipProgress, true)
.then(() => {
console.log(`unzip succesfully completed`);
console.log(`begin unzip`);
let appPath = fs.knownFolders.currentApp().path;
let testZipFile = fs.path.join(appPath, 'test_70mb.zip');
// Zip.unzip(testZipFile, appPath);
Zip.unzip({
archive: testZipFile,
directory: dest.path,
onProgress: onZipProgress,
})
.catch(err => {
console.log(`unzip error: ${err}`);
});
.then(() => {
console.log(`unzip succesfully completed`);
})
.catch(err => {
console.log(`unzip error: ${err}`);
});
}

export function showFiles() {
traceFolderTree(dest, 2);
traceFolderTree(dest, 2);
}

function onZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
model.progress = percent;
model.notifyPropertyChange('progress', percent);
console.log(`unzip progress: ${percent}`);
model.progress = percent;
model.notifyPropertyChange('progress', percent);
}

function traceFolderTree(
folder: fs.Folder,
maxDepth: number = 3,
depth: number = 0
folder: fs.Folder,
maxDepth: number = 3,
depth: number = 0
) {
try {
let whitespace = new Array(depth + 1).join(' ');
console.log(`${whitespace}${fs.Folder.fromPath(folder.path).name}`);
folder.eachEntity(ent => {
if (fs.Folder.exists(ent.path) && depth < maxDepth) {
traceFolderTree(fs.Folder.fromPath(ent.path), maxDepth, depth + 1);
} else {
console.log(`${whitespace}- ${ent.name}`);
}
return true;
});
} catch (err) {
console.log(`err tracing tree: ${err}`);
}
try {
let whitespace = new Array(depth + 1).join(' ');
console.log(`${whitespace}${fs.Folder.fromPath(folder.path).name}`);
folder.eachEntity(ent => {
if (fs.Folder.exists(ent.path) && depth < maxDepth) {
traceFolderTree(fs.Folder.fromPath(ent.path), maxDepth, depth + 1);
} else {
console.log(`${whitespace}- ${ent.name}`);
}
return true;
});
} catch (err) {
console.log(`err tracing tree: ${err}`);
}
}
12 changes: 6 additions & 6 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page"
xmlns:ui="nativescript-zip">
<StackLayout class="p-20">
<Label text="{{ message }}" class="t-20 text-center c-black" textWrap="true"/>
</StackLayout>
</Page>
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page">
<StackLayout class="p-20">
<Button text="Create Zip file" tap="create"/>
<Button text="Extract Zip File" tap="extract"/>
</StackLayout>
</Page>
3 changes: 2 additions & 1 deletion demo/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"homepage": "https://github.com/NativeScript/template-hello-world-ts",
"android": {
"v8Flags": "--expose_gc"
"v8Flags": "--expose_gc",
"markingMode": "none"
},
"devDependencies": {
"nativescript-dev-typescript": "^0.3.0"
Expand Down
Loading

0 comments on commit c109fc3

Please sign in to comment.