Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
3559453579 | |||
ea509d4246 | |||
c13a125ac7 | |||
8f6949b1b8 | |||
9b698c6dea | |||
157bcff7c4 | |||
934423f0ad | |||
e6d7fdced6 | |||
2fc4e691ac | |||
7e8035ea61 | |||
1bc3112bb7 | |||
4a177fd166 | |||
c1cf019af2 | |||
9ecf7c81d4 | |||
8fa40087d4 | |||
a5576410cd | |||
dff08ed54b | |||
fe4dd5c1ee | |||
7f146b547f | |||
4ee936035c | |||
2e95f1db7f | |||
35e5ded808 | |||
f2430d095f | |||
d79a5af51a | |||
318bdd1bd8 | |||
54a0ec6c71 | |||
8853eecbb9 | |||
1bfca4456c | |||
b337e4c779 | |||
53d56d2d8a | |||
e3781cfd4d | |||
eca90bdf64 | |||
b35b3f6c0b | |||
d3509b8834 | |||
246037aaae | |||
3fc91bc0c1 | |||
6c3991f6bc | |||
cfcba1aa01 | |||
b8a7f02b97 | |||
d6a7fd6c8c | |||
6e079e38c3 | |||
38d1aa5477 | |||
6f8ce94ae2 | |||
f3a78ba089 | |||
43bc078ace |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
pages/
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
155
.gitlab-ci.yml
155
.gitlab-ci.yml
@ -1,34 +1,141 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone ci_default
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
|
- metadata
|
||||||
|
|
||||||
testLEGACY:
|
before_script:
|
||||||
stage: test
|
- npm install -g @shipzone/npmci
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
# ====================
|
||||||
stage: test
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci git mirror
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
environment: npm_registry
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
20
README.md
20
README.md
@ -1,20 +0,0 @@
|
|||||||
# smartbrowser
|
|
||||||
easy class API for serving stacks during development with `browser-sync`.
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/smartbrowser)
|
|
||||||
[](https://gitlab.com/pushrocks/smartbrowser)
|
|
||||||
[](https://github.com/pushrocks/smartbrowser)
|
|
||||||
[](https://pushrocks.gitlab.io/smartbrowser/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartbrowser/commits/master)
|
|
||||||
[](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://push.rocks)
|
|
File diff suppressed because one or more lines are too long
@ -1,88 +0,0 @@
|
|||||||
TN:
|
|
||||||
SF:/Users/philkunz/gitlab/pushrocks/smartbrowser/dist/index.js
|
|
||||||
FN:3,(anonymous_1)
|
|
||||||
FN:3,defineProperties
|
|
||||||
FN:3,(anonymous_3)
|
|
||||||
FN:5,_classCallCheck
|
|
||||||
FN:12,(anonymous_5)
|
|
||||||
FN:13,Smartbrowser
|
|
||||||
FN:31,start
|
|
||||||
FN:36,(anonymous_8)
|
|
||||||
FN:40,(anonymous_9)
|
|
||||||
FN:47,(anonymous_10)
|
|
||||||
FN:59,stop
|
|
||||||
FNF:11
|
|
||||||
FNH:10
|
|
||||||
FNDA:1,(anonymous_1)
|
|
||||||
FNDA:1,defineProperties
|
|
||||||
FNDA:1,(anonymous_3)
|
|
||||||
FNDA:1,_classCallCheck
|
|
||||||
FNDA:1,(anonymous_5)
|
|
||||||
FNDA:1,Smartbrowser
|
|
||||||
FNDA:1,start
|
|
||||||
FNDA:1,(anonymous_8)
|
|
||||||
FNDA:1,(anonymous_9)
|
|
||||||
FNDA:0,(anonymous_10)
|
|
||||||
FNDA:1,stop
|
|
||||||
DA:3,2
|
|
||||||
DA:5,1
|
|
||||||
DA:7,1
|
|
||||||
DA:12,1
|
|
||||||
DA:13,1
|
|
||||||
DA:14,1
|
|
||||||
DA:16,1
|
|
||||||
DA:17,1
|
|
||||||
DA:20,1
|
|
||||||
DA:21,1
|
|
||||||
DA:22,1
|
|
||||||
DA:29,1
|
|
||||||
DA:32,1
|
|
||||||
DA:34,1
|
|
||||||
DA:35,1
|
|
||||||
DA:36,1
|
|
||||||
DA:37,1
|
|
||||||
DA:38,1
|
|
||||||
DA:39,1
|
|
||||||
DA:40,1
|
|
||||||
DA:41,1
|
|
||||||
DA:42,1
|
|
||||||
DA:43,1
|
|
||||||
DA:47,0
|
|
||||||
DA:48,0
|
|
||||||
DA:51,1
|
|
||||||
DA:60,1
|
|
||||||
DA:61,1
|
|
||||||
DA:62,1
|
|
||||||
DA:63,1
|
|
||||||
DA:64,1
|
|
||||||
DA:68,1
|
|
||||||
DA:71,1
|
|
||||||
LF:33
|
|
||||||
LH:31
|
|
||||||
BRDA:3,1,0,2
|
|
||||||
BRDA:3,1,1,2
|
|
||||||
BRDA:3,2,0,2
|
|
||||||
BRDA:3,2,1,0
|
|
||||||
BRDA:3,3,0,1
|
|
||||||
BRDA:3,3,1,0
|
|
||||||
BRDA:3,4,0,0
|
|
||||||
BRDA:3,4,1,1
|
|
||||||
BRDA:5,5,0,0
|
|
||||||
BRDA:5,5,1,1
|
|
||||||
BRDA:35,6,0,1
|
|
||||||
BRDA:35,6,1,0
|
|
||||||
BRF:12
|
|
||||||
BRH:7
|
|
||||||
end_of_record
|
|
||||||
TN:
|
|
||||||
SF:/Users/philkunz/gitlab/pushrocks/smartbrowser/dist/smartbrowser.plugins.js
|
|
||||||
FNF:0
|
|
||||||
FNH:0
|
|
||||||
DA:3,1
|
|
||||||
DA:4,1
|
|
||||||
DA:5,1
|
|
||||||
LF:3
|
|
||||||
LH:3
|
|
||||||
BRF:0
|
|
||||||
BRH:0
|
|
||||||
end_of_record
|
|
32
dist/index.d.ts
vendored
32
dist/index.d.ts
vendored
@ -1,32 +0,0 @@
|
|||||||
/// <reference types="browser-sync" />
|
|
||||||
/// <reference types="q" />
|
|
||||||
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: plugins.q.Promise<void>;
|
|
||||||
constructor(optionsArg: ISmartbrowserOptions);
|
|
||||||
/**
|
|
||||||
* starts the server and returns the browserSync instance in a resolved Promise
|
|
||||||
*/
|
|
||||||
start(): plugins.q.Promise<plugins.browserSync.BrowserSyncInstance>;
|
|
||||||
/**
|
|
||||||
* stops the smartbrowser instance
|
|
||||||
*/
|
|
||||||
stop(): plugins.q.Promise<void>;
|
|
||||||
}
|
|
48
dist/index.js
vendored
48
dist/index.js
vendored
@ -1,48 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
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.q.defer();
|
|
||||||
if (this.bsStatus === 'idle') {
|
|
||||||
this.bsStatus = 'starting';
|
|
||||||
let localDone = plugins.q.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.q.defer();
|
|
||||||
this.bsInstance.exit();
|
|
||||||
this.bsStatus = 'idle';
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Smartbrowser = Smartbrowser;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsa0RBQWlEO0FBZ0JqRDs7R0FFRztBQUNIO0lBT0ksWUFBWSxVQUFnQztRQU41QyxlQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLEVBQUUsQ0FBQTtRQUN6QyxhQUFRLEdBQWdDO1lBQ3BDLE1BQU0sRUFBRSxFQUFFO1NBQ2IsQ0FBQTtRQUNELGFBQVEsR0FBYSxNQUFNLENBQUE7UUFHdkIsSUFBSSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUE7UUFDakQsSUFBSSxDQUFDLFFBQVEsQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFDLFVBQVUsQ0FBQTtJQUMvQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxLQUFLO1FBQ0QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQTJDLENBQUE7UUFDckUsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFFBQVEsS0FBSyxNQUFNLENBQUMsQ0FBQyxDQUFDO1lBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFBO1lBQzFCLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUE7WUFDdkMsSUFBSSxDQUFDLFNBQVMsR0FBRyxTQUFTLENBQUMsT0FBTyxDQUFBO1lBQ2xDLElBQUksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxRQUFRLEVBQUU7Z0JBQ2hDLElBQUksQ0FBQyxRQUFRLEdBQUcsU0FBUyxDQUFBO2dCQUN6QixTQUFTLENBQUMsT0FBTyxFQUFFLENBQUE7Z0JBQ25CLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxDQUFBO1lBQ2pDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osSUFBSSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUUsUUFBUSxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ2pFLENBQUM7UUFDRCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0EsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQVEsQ0FBQTtRQUNsQyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1FBQ3RCLElBQUksQ0FBQyxRQUFRLEdBQUcsTUFBTSxDQUFBO1FBQ3RCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNkLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQTFDRCxvQ0EwQ0MifQ==
|
|
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 q = require('q');
|
|
5
dist/smartbrowser.plugins.js
vendored
5
dist/smartbrowser.plugins.js
vendored
@ -1,5 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
exports.browserSync = require("browser-sync");
|
|
||||||
exports.q = require("q");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRicm93c2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGJyb3dzZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUFtRDtBQUNuRCx5QkFBOEIifQ==
|
|
16
npmextra.json
Normal file
16
npmextra.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"npmci": {
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartbrowser",
|
||||||
|
"shortDescription": "puppeteer wrapper for easy tasks",
|
||||||
|
"npmPackagename": "@pushrocks/smartbrowser",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18173
package-lock.json
generated
Normal file
18173
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "smartbrowser",
|
"name": "@pushrocks/smartbrowser",
|
||||||
"version": "1.0.1",
|
"version": "2.0.1",
|
||||||
"description": "wraps browser-sync",
|
"description": "simplified puppeteer",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/ --web)",
|
||||||
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -18,16 +20,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/browser-sync": "0.0.32",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@types/q": "0.0.30",
|
"@pushrocks/smartpdf": "^3.0.1",
|
||||||
"browser-sync": "^2.16.0",
|
"@pushrocks/smartpuppeteer": "^2.0.0",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartunique": "^3.0.3"
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.29",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"npmts-g": "^5.2.8",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"should": "^11.1.0",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"typings-test": "^1.0.3"
|
"tslint": "^6.1.3",
|
||||||
}
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"private": false,
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# @pushrocks/smartbrowser
|
||||||
|
puppeteer wrapper for easy tasks
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
@ -1,6 +0,0 @@
|
|||||||
<head>
|
|
||||||
<title>Test</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Test
|
|
||||||
</body>
|
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsOENBQTZDO0FBRTdDLElBQUksZ0JBQTJDLENBQUE7QUFFL0MsUUFBUSxDQUFDLGNBQWMsRUFBRTtJQUNyQixFQUFFLENBQUMsb0NBQW9DLEVBQUU7UUFDckMsZ0JBQWdCLEdBQUcsSUFBSSxZQUFZLENBQUMsWUFBWSxDQUFDO1lBQzdDLE9BQU8sRUFBRSxnQkFBZ0I7WUFDekIsVUFBVSxFQUFFLENBQUMsZ0JBQWdCLENBQUM7U0FDakMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLGdCQUFnQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsMkJBQTJCLEVBQUUsVUFBVSxJQUFJO1FBQzFDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDLFVBQVU7WUFDckMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQzNDLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDBCQUEwQixFQUFFLFVBQVUsSUFBSTtRQUN6QyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFVBQVUsQ0FBQztZQUNQLGdCQUFnQixDQUFDLElBQUksRUFBRSxDQUFDLElBQUksQ0FBQztnQkFDekIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzNDLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQTtJQUNaLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1FBQ3ZCLFVBQVUsQ0FBQztZQUNQLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDbkIsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFBO0lBQ1gsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
|
64
test/test.ts
64
test/test.ts
@ -1,34 +1,36 @@
|
|||||||
import 'typings-test'
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||||
import * as should from 'should'
|
|
||||||
|
|
||||||
import * as smartbrowser from '../dist/index'
|
import * as smartbrowser from '../ts/index.js';
|
||||||
|
let testSmartBrowser: smartbrowser.SmartBrowser;
|
||||||
|
|
||||||
let testSmartBrowser: smartbrowser.Smartbrowser
|
tap.test('should instanstiate a new browser ', async () => {
|
||||||
|
testSmartBrowser = new smartbrowser.SmartBrowser();
|
||||||
|
return expect(testSmartBrowser).toBeInstanceOf(smartbrowser.SmartBrowser);
|
||||||
|
});
|
||||||
|
|
||||||
describe('smartbrowser', () => {
|
tap.test('should start the browser ', async () => {
|
||||||
it('should instanstiate a new browser ', function () {
|
await testSmartBrowser.start();
|
||||||
testSmartBrowser = new smartbrowser.Smartbrowser({
|
});
|
||||||
webroot: './test/assets/',
|
|
||||||
watchFiles: ['./test/assets/']
|
tap.test('should create a PDF from a page', async (tools) => {
|
||||||
})
|
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
||||||
should(testSmartBrowser).be.instanceof(smartbrowser.Smartbrowser)
|
expect(result.buffer).toBeInstanceOf(Buffer);
|
||||||
})
|
});
|
||||||
it('should start the browser ', function (done) {
|
|
||||||
testSmartBrowser.start().then((bsInstance) => {
|
tap.test('should produce a valid screenshot', async (tools) => {
|
||||||
done()
|
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
||||||
}).catch((err) => { console.log(err) })
|
expect(result.buffer).toBeInstanceOf(Buffer);
|
||||||
})
|
});
|
||||||
it('should stop the browser ', function (done) {
|
|
||||||
this.timeout(10000)
|
tap.test('should evalute something in the browser', async () => {
|
||||||
setTimeout(() => {
|
const result = await testSmartBrowser.evaluateOnPage('https://lossless.com', async () => {
|
||||||
testSmartBrowser.stop().then(() => {
|
return window.location.toString();
|
||||||
done()
|
});
|
||||||
}).catch((err) => { console.log(err) })
|
console.log(result);
|
||||||
}, 2000)
|
});
|
||||||
})
|
|
||||||
it('should exit correctly',function(){
|
tap.test('should stop the browser ', async () => {
|
||||||
setTimeout(() => {
|
await testSmartBrowser.stop();
|
||||||
process.exit(0)
|
});
|
||||||
},2000)
|
|
||||||
})
|
tap.start();
|
||||||
})
|
|
||||||
|
99
ts/index.ts
99
ts/index.ts
@ -1,62 +1,73 @@
|
|||||||
import * as plugins from './smartbrowser.plugins'
|
import * as plugins from './smartbrowser.plugins.js';
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the options interface of a Smartbrowser instance
|
* SmartBrowser
|
||||||
*/
|
*/
|
||||||
export interface ISmartbrowserOptions {
|
export class SmartBrowser {
|
||||||
webroot: string
|
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||||
watchFiles: string[]
|
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'
|
public async stop() {
|
||||||
|
await this.headlessBrowser.close();
|
||||||
/**
|
await this.smartpdf.stop();
|
||||||
* 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: plugins.q.Promise<void>
|
|
||||||
constructor(optionsArg: ISmartbrowserOptions) {
|
|
||||||
this.bsConfig.server.baseDir = optionsArg.webroot
|
|
||||||
this.bsConfig.files = optionsArg.watchFiles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts the server and returns the browserSync instance in a resolved Promise
|
* create a pdf from page
|
||||||
|
* @param urlArg
|
||||||
*/
|
*/
|
||||||
start(): plugins.q.Promise<plugins.browserSync.BrowserSyncInstance> {
|
public pdfFromPage(urlArg: string) {
|
||||||
let done = plugins.q.defer<plugins.browserSync.BrowserSyncInstance>()
|
const result = this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
||||||
if (this.bsStatus === 'idle') {
|
return result;
|
||||||
this.bsStatus = 'starting'
|
|
||||||
let localDone = plugins.q.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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stops the smartbrowser instance
|
* make a screenshot from a page
|
||||||
|
* @param urlArg
|
||||||
*/
|
*/
|
||||||
stop(): plugins.q.Promise<void> {
|
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
|
||||||
let done = plugins.q.defer<void>()
|
const pageId = plugins.smartunique.shortId();
|
||||||
this.bsInstance.exit()
|
const page = await this.headlessBrowser.newPage();
|
||||||
this.bsStatus = 'idle'
|
await page.goto(urlArg, {
|
||||||
done.resolve()
|
waitUntil: 'networkidle2',
|
||||||
return done.promise
|
});
|
||||||
|
const screenshotBuffer = await page.screenshot({
|
||||||
|
encoding: 'binary',
|
||||||
|
}) as Buffer;
|
||||||
|
await page.close();
|
||||||
|
return {
|
||||||
|
name: pageId,
|
||||||
|
id: `${pageId}.js`,
|
||||||
|
buffer: screenshotBuffer,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* evalutes an expression on a page
|
||||||
|
* @param urlArg
|
||||||
|
* @param funcArg
|
||||||
|
*/
|
||||||
|
public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) {
|
||||||
|
const page = await this.headlessBrowser.newPage();
|
||||||
|
await page.goto(urlArg, {
|
||||||
|
waitUntil: 'networkidle2',
|
||||||
|
});
|
||||||
|
const result = await page.evaluate(funcArg);
|
||||||
|
await page.close();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './interfaces.screenshotresult.js';
|
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'
|
// pushrocks scope
|
||||||
export import browserSync = require('browser-sync')
|
import * as smartpdf from '@pushrocks/smartpdf';
|
||||||
export import q = require('q')
|
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