Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e95f1db7f | |||
35e5ded808 | |||
f2430d095f | |||
d79a5af51a | |||
318bdd1bd8 | |||
54a0ec6c71 | |||
8853eecbb9 | |||
1bfca4456c | |||
b337e4c779 | |||
53d56d2d8a | |||
e3781cfd4d | |||
eca90bdf64 | |||
b35b3f6c0b | |||
d3509b8834 | |||
246037aaae | |||
3fc91bc0c1 | |||
6c3991f6bc | |||
cfcba1aa01 | |||
b8a7f02b97 | |||
d6a7fd6c8c | |||
6e079e38c3 | |||
38d1aa5477 |
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,3 +1,22 @@
|
||||
node_modules/
|
||||
pages/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@ -3,69 +3,123 @@ image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage --publish gitlab
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
35
README.md
35
README.md
@ -1,29 +1,28 @@
|
||||
# smartbrowser
|
||||
wraps browser-sync
|
||||
# @pushrocks/smartbrowser
|
||||
puppeteer wrapper for easy tasks
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartbrowser)
|
||||
[](https://GitLab.com/pushrocks/smartbrowser)
|
||||
[](https://github.com/pushrocks/smartbrowser)
|
||||
[](https://pushrocks.gitlab.io/smartbrowser/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartbrowser)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartbrowser)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartbrowser)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartbrowser/)
|
||||
|
||||
## Status for master
|
||||
[](https://GitLab.com/pushrocks/smartbrowser/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartbrowser/commits/master)
|
||||
[](https://www.npmjs.com/package/smartbrowser)
|
||||
[](https://david-dm.org/pushrocks/smartbrowser)
|
||||
[](https://www.bithound.io/github/pushrocks/smartbrowser/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartbrowser)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartbrowser)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartbrowser)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
31
dist/index.d.ts
vendored
31
dist/index.d.ts
vendored
@ -1,31 +0,0 @@
|
||||
/// <reference types="browser-sync" />
|
||||
import * as plugins from './smartbrowser.plugins';
|
||||
/**
|
||||
* the options interface of a Smartbrowser instance
|
||||
*/
|
||||
export interface ISmartbrowserOptions {
|
||||
webroot: string;
|
||||
watchFiles: string[];
|
||||
}
|
||||
/**
|
||||
* Type of status that a bsInstance can have
|
||||
*/
|
||||
export declare type bsStatus = 'idle' | 'starting' | 'running';
|
||||
/**
|
||||
* class smartbrowser controls a browser-sync instance for you
|
||||
*/
|
||||
export declare class Smartbrowser {
|
||||
bsInstance: plugins.browserSync.BrowserSyncInstance;
|
||||
bsConfig: plugins.browserSync.Options;
|
||||
bsStatus: bsStatus;
|
||||
bsStarted: Promise<void>;
|
||||
constructor(optionsArg: ISmartbrowserOptions);
|
||||
/**
|
||||
* starts the server and returns the browserSync instance in a resolved Promise
|
||||
*/
|
||||
start(): Promise<plugins.browserSync.BrowserSyncInstance>;
|
||||
/**
|
||||
* stops the smartbrowser instance
|
||||
*/
|
||||
stop(): Promise<void>;
|
||||
}
|
49
dist/index.js
vendored
49
dist/index.js
vendored
@ -1,49 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartbrowser.plugins");
|
||||
/**
|
||||
* class smartbrowser controls a browser-sync instance for you
|
||||
*/
|
||||
class Smartbrowser {
|
||||
constructor(optionsArg) {
|
||||
this.bsInstance = plugins.browserSync.create();
|
||||
this.bsConfig = {
|
||||
server: {}
|
||||
};
|
||||
this.bsStatus = 'idle';
|
||||
this.bsConfig.server.baseDir = optionsArg.webroot;
|
||||
this.bsConfig.files = optionsArg.watchFiles;
|
||||
}
|
||||
/**
|
||||
* starts the server and returns the browserSync instance in a resolved Promise
|
||||
*/
|
||||
start() {
|
||||
let done = plugins.smartq.defer();
|
||||
if (this.bsStatus === 'idle') {
|
||||
this.bsStatus = 'starting';
|
||||
let localDone = plugins.smartq.defer();
|
||||
this.bsStarted = localDone.promise;
|
||||
this.bsInstance.init(this.bsConfig, () => {
|
||||
this.bsStatus = 'running';
|
||||
localDone.resolve();
|
||||
done.resolve(this.bsInstance);
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.bsStarted.then(() => { done.resolve(this.bsInstance); });
|
||||
}
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* stops the smartbrowser instance
|
||||
*/
|
||||
stop() {
|
||||
let done = plugins.smartq.defer();
|
||||
this.bsInstance.exit();
|
||||
this.bsStatus = 'idle';
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
exports.Smartbrowser = Smartbrowser;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGtEQUFpRDtBQWdCakQ7O0dBRUc7QUFDSDtJQU9FLFlBQWEsVUFBZ0M7UUFON0MsZUFBVSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxFQUFFLENBQUE7UUFDekMsY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FBQyxDQUFDLENBQUMsQ0FBQTtRQUM5RCxDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDckIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSTtRQUNGLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDdkMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtRQUN0QixJQUFJLENBQUMsUUFBUSxHQUFHLE1BQU0sQ0FBQTtRQUN0QixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDZCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0NBQ0Y7QUExQ0Qsb0NBMENDIn0=
|
3
dist/smartbrowser.plugins.d.ts
vendored
3
dist/smartbrowser.plugins.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import 'typings-global';
|
||||
export import browserSync = require('browser-sync');
|
||||
export import smartq = require('smartq');
|
6
dist/smartbrowser.plugins.js
vendored
6
dist/smartbrowser.plugins.js
vendored
@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
exports.browserSync = require("browser-sync");
|
||||
exports.smartq = require("smartq");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRicm93c2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGJyb3dzZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw4Q0FBbUQ7QUFDbkQsbUNBQXdDIn0=
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartbrowser",
|
||||
"shortDescription": "puppeteer wrapper for easy tasks",
|
||||
"npmPackagename": "@pushrocks/smartbrowser",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
2557
package-lock.json
generated
Normal file
2557
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "smartbrowser",
|
||||
"version": "1.0.3",
|
||||
"description": "wraps browser-sync",
|
||||
"name": "@pushrocks/smartbrowser",
|
||||
"version": "1.0.14",
|
||||
"description": "simplified puppeteer",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -18,13 +19,27 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
||||
"dependencies": {
|
||||
"@types/browser-sync": "0.0.34",
|
||||
"browser-sync": "^2.18.8",
|
||||
"smartq": "^1.1.1",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartpdf": "^1.0.17",
|
||||
"@pushrocks/smartpuppeteer": "^1.0.5",
|
||||
"@pushrocks/smartunique": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"smartdelay": "^1.0.1",
|
||||
"tapbundle": "^1.0.5"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"tslint": "^5.17.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"private": true,
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
<head>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body>
|
||||
Test
|
||||
</body>
|
33
test/test.js
33
test/test.js
@ -1,33 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const should = require("should");
|
||||
const smartbrowser = require("../dist/index");
|
||||
let testSmartBrowser;
|
||||
describe('smartbrowser', () => {
|
||||
it('should instanstiate a new browser ', function () {
|
||||
testSmartBrowser = new smartbrowser.Smartbrowser({
|
||||
webroot: './test/assets/',
|
||||
watchFiles: ['./test/assets/']
|
||||
});
|
||||
should(testSmartBrowser).be.instanceof(smartbrowser.Smartbrowser);
|
||||
});
|
||||
it('should start the browser ', function (done) {
|
||||
testSmartBrowser.start().then((bsInstance) => {
|
||||
done();
|
||||
}).catch((err) => { console.log(err); });
|
||||
});
|
||||
it('should stop the browser ', function (done) {
|
||||
this.timeout(10000);
|
||||
setTimeout(() => {
|
||||
testSmartBrowser.stop().then(() => {
|
||||
done();
|
||||
}).catch((err) => { console.log(err); });
|
||||
}, 2000);
|
||||
});
|
||||
it('should exit correctly', function () {
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsOENBQTZDO0FBRTdDLElBQUksZ0JBQTJDLENBQUE7QUFFL0MsUUFBUSxDQUFDLGNBQWMsRUFBRTtJQUNyQixFQUFFLENBQU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VCQUF1QixFQUFDO1FBQ3ZCLFVBQVUsQ0FBQztZQUNQLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDbkIsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFBO0lBQ1gsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
44
test/test.ts
44
test/test.ts
@ -1,29 +1,29 @@
|
||||
import { tap, expect } from 'tapbundle'
|
||||
import * as smartdelay from 'smartdelay'
|
||||
|
||||
import * as smartbrowser from '../dist/index'
|
||||
let testSmartBrowser: smartbrowser.Smartbrowser
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartbrowser from '../ts/index';
|
||||
let testSmartBrowser: smartbrowser.SmartBrowser;
|
||||
|
||||
tap.test('should instanstiate a new browser ', async () => {
|
||||
testSmartBrowser = new smartbrowser.Smartbrowser({
|
||||
webroot: './test/assets/',
|
||||
watchFiles: [ './test/assets/' ]
|
||||
})
|
||||
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.Smartbrowser)
|
||||
}).catch(tap.threw)
|
||||
testSmartBrowser = new smartbrowser.SmartBrowser();
|
||||
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
|
||||
});
|
||||
|
||||
tap.test('should start the browser ', async () => {
|
||||
return await expect(testSmartBrowser.start()).to.eventually.be.fulfilled
|
||||
}).catch(tap.threw)
|
||||
await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
|
||||
});
|
||||
|
||||
tap.test('should create a PDF from a page', async tools => {
|
||||
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
||||
expect(result.buffer).to.be.instanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('should produce a valid screenshot', async tools => {
|
||||
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
||||
expect(result.buffer).to.be.instanceOf(Buffer);
|
||||
});
|
||||
|
||||
tap.test('should stop the browser ', async () => {
|
||||
return await smartdelay.delayFor(2000).then(() => {
|
||||
return expect(testSmartBrowser.stop()).to.eventually.be.fulfilled
|
||||
})
|
||||
})
|
||||
tap.test('should exit correctly', async () => {
|
||||
smartdelay.delayFor(2000).then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
await expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
98
ts/index.ts
98
ts/index.ts
@ -1,62 +1,72 @@
|
||||
import * as plugins from './smartbrowser.plugins'
|
||||
import * as plugins from './smartbrowser.plugins';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
/**
|
||||
* the options interface of a Smartbrowser instance
|
||||
* SmartBrowser
|
||||
*/
|
||||
export interface ISmartbrowserOptions {
|
||||
webroot: string
|
||||
watchFiles: string[]
|
||||
export class SmartBrowser {
|
||||
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||
public smartpdf: plugins.smartpdf.SmartPdf;
|
||||
|
||||
/**
|
||||
* start the SmartBrowser instance
|
||||
*/
|
||||
public async start() {
|
||||
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
||||
this.smartpdf = new plugins.smartpdf.SmartPdf();
|
||||
await this.smartpdf.start(this.headlessBrowser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of status that a bsInstance can have
|
||||
* stop the SmartBrowser instance
|
||||
*/
|
||||
export type bsStatus = 'idle' | 'starting' | 'running'
|
||||
|
||||
/**
|
||||
* class smartbrowser controls a browser-sync instance for you
|
||||
*/
|
||||
export class Smartbrowser {
|
||||
bsInstance = plugins.browserSync.create()
|
||||
bsConfig: plugins.browserSync.Options = {
|
||||
server: {}
|
||||
}
|
||||
bsStatus: bsStatus = 'idle'
|
||||
bsStarted: Promise<void>
|
||||
constructor (optionsArg: ISmartbrowserOptions) {
|
||||
this.bsConfig.server.baseDir = optionsArg.webroot
|
||||
this.bsConfig.files = optionsArg.watchFiles
|
||||
public async stop() {
|
||||
await this.headlessBrowser.close();
|
||||
await this.smartpdf.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the server and returns the browserSync instance in a resolved Promise
|
||||
* create a pdf from page
|
||||
* @param urlArg
|
||||
*/
|
||||
start (): Promise<plugins.browserSync.BrowserSyncInstance> {
|
||||
let done = plugins.smartq.defer<plugins.browserSync.BrowserSyncInstance>()
|
||||
if (this.bsStatus === 'idle') {
|
||||
this.bsStatus = 'starting'
|
||||
let localDone = plugins.smartq.defer<void>()
|
||||
this.bsStarted = localDone.promise
|
||||
this.bsInstance.init(this.bsConfig, () => {
|
||||
this.bsStatus = 'running'
|
||||
localDone.resolve()
|
||||
done.resolve(this.bsInstance)
|
||||
})
|
||||
} else {
|
||||
this.bsStarted.then(() => { done.resolve(this.bsInstance) })
|
||||
}
|
||||
return done.promise
|
||||
public pdfFromPage(urlArg: string) {
|
||||
const result = this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the smartbrowser instance
|
||||
* make a screenshot from a page
|
||||
* @param urlArg
|
||||
*/
|
||||
stop (): Promise<void> {
|
||||
let done = plugins.smartq.defer<void>()
|
||||
this.bsInstance.exit()
|
||||
this.bsStatus = 'idle'
|
||||
done.resolve()
|
||||
return done.promise
|
||||
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
|
||||
const pageId = plugins.smartunique.shortId();
|
||||
const page = await this.headlessBrowser.newPage();
|
||||
await page.goto(urlArg, {
|
||||
waitUntil: 'networkidle2'
|
||||
});
|
||||
const screenshotBuffer = await page.screenshot({
|
||||
encoding: 'binary'
|
||||
});
|
||||
await page.close();
|
||||
return {
|
||||
name: pageId,
|
||||
id: `${pageId}.js`,
|
||||
buffer: screenshotBuffer
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* evalutes an expression on a page
|
||||
* @param urlArg
|
||||
* @param funcArg
|
||||
*/
|
||||
public async evaluateOnPage(urlArg: string, funcArg: () => Promise<any>) {
|
||||
const page = await this.headlessBrowser.newPage();
|
||||
await page.goto(urlArg, {
|
||||
waitUntil: 'networkidle2'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './interfaces.screenshotresult';
|
5
ts/interfaces/interfaces.screenshotresult.ts
Normal file
5
ts/interfaces/interfaces.screenshotresult.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface IScreenShotResult {
|
||||
name: string;
|
||||
id: string;
|
||||
buffer: Buffer;
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
import 'typings-global'
|
||||
export import browserSync = require('browser-sync')
|
||||
export import smartq = require('smartq')
|
||||
// pushrocks scope
|
||||
import * as smartpdf from '@pushrocks/smartpdf';
|
||||
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
|
||||
export { smartpdf, smartpuppeteer, smartunique };
|
||||
|
||||
// third party
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Reference in New Issue
Block a user