42 Commits

Author SHA1 Message Date
fdfa6a72c8 2.0.3 2022-10-26 23:00:44 +02:00
801416dc1e fix(core): update 2022-10-26 23:00:43 +02:00
84cf226d42 2.0.2 2022-03-25 01:19:21 +01:00
63f56da150 fix(core): update 2022-03-25 01:19:21 +01:00
3559453579 2.0.1 2022-03-24 23:41:51 +01:00
ea509d4246 fix(core): update 2022-03-24 23:41:51 +01:00
c13a125ac7 2.0.0 2022-03-24 14:58:00 +01:00
8f6949b1b8 1.0.23 2022-03-24 14:57:17 +01:00
9b698c6dea fix(core): update 2022-03-24 14:57:16 +01:00
157bcff7c4 1.0.22 2021-11-07 20:42:50 +01:00
934423f0ad fix(core): update 2021-11-07 20:42:49 +01:00
e6d7fdced6 1.0.21 2021-11-07 20:21:04 +01:00
2fc4e691ac fix(core): update 2021-11-07 20:21:03 +01:00
7e8035ea61 1.0.20 2021-04-29 15:26:08 +00:00
1bc3112bb7 fix(core): update 2021-04-29 15:26:08 +00:00
4a177fd166 1.0.19 2021-04-29 14:52:28 +00:00
c1cf019af2 fix(core): update 2021-04-29 14:52:28 +00:00
9ecf7c81d4 1.0.18 2020-08-12 16:31:55 +00:00
8fa40087d4 1.0.17 2020-06-01 20:25:33 +00:00
a5576410cd fix(core): update 2020-06-01 20:25:32 +00:00
dff08ed54b 1.0.16 2020-06-01 20:20:57 +00:00
fe4dd5c1ee fix(core): update 2020-06-01 20:20:57 +00:00
7f146b547f 1.0.15 2020-06-01 20:19:26 +00:00
4ee936035c fix(core): update 2020-06-01 20:19:25 +00:00
2e95f1db7f 1.0.14 2019-06-04 08:29:06 +02:00
35e5ded808 fix(core): update 2019-06-04 08:29:05 +02:00
f2430d095f 1.0.13 2019-06-03 17:17:20 +02:00
d79a5af51a fix(core): update 2019-06-03 17:17:20 +02:00
318bdd1bd8 1.0.12 2019-06-03 17:16:47 +02:00
54a0ec6c71 fix(core): update 2019-06-03 17:16:47 +02:00
8853eecbb9 1.0.11 2019-05-29 14:14:26 +02:00
1bfca4456c fix(core): update 2019-05-29 14:14:26 +02:00
b337e4c779 1.0.10 2019-05-29 08:57:17 +02:00
53d56d2d8a fix(core): update 2019-05-29 08:57:17 +02:00
e3781cfd4d 1.0.9 2019-05-28 23:29:25 +02:00
eca90bdf64 fix(core): update 2019-05-28 23:29:24 +02:00
b35b3f6c0b 1.0.8 2019-05-28 23:28:44 +02:00
d3509b8834 fix(core): update 2019-05-28 23:28:43 +02:00
246037aaae 1.0.7 2019-05-28 23:28:27 +02:00
3fc91bc0c1 fix(core): update 2019-05-28 23:28:26 +02:00
6c3991f6bc 1.0.6 2019-05-28 23:27:56 +02:00
cfcba1aa01 fix(core): update 2019-05-28 23:27:55 +02:00
24 changed files with 4422 additions and 3107 deletions

21
.gitignore vendored
View File

@ -1,3 +1,20 @@
node_modules/
pages/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,38 +1,80 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .yarn/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- test
- release
- trigger
- pages
- security
- test
- release
- metadata
testLEGACY:
stage: test
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
coverage: /\d+.?\d+?\%\s*coverage/
- npmci git mirror
only:
- tags
tags:
- lossless
- 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
testLTS:
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 test lts
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testSTABLE:
testBuild:
stage: test
script:
- npmci test stable
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
@ -40,32 +82,60 @@ testSTABLE:
release:
stage: release
script:
- npmci publish
- 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: trigger
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- 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 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
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -1,29 +0,0 @@
# smartbrowser
wraps browser-sync
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartbrowser)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartbrowser)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartbrowser)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartbrowser/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartbrowser/badges/master/build.svg)](https://GitLab.com/pushrocks/smartbrowser/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartbrowser/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartbrowser/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartbrowser.svg)](https://www.npmjs.com/package/smartbrowser)
[![Dependency Status](https://david-dm.org/pushrocks/smartbrowser.svg)](https://david-dm.org/pushrocks/smartbrowser)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartbrowser/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartbrowser/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartbrowser/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartbrowser)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

32
dist/index.d.ts vendored
View File

@ -1,32 +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>;
reload(): Promise<void>;
}

63
dist/index.js vendored
View File

@ -1,63 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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() {
return __awaiter(this, void 0, void 0, function* () {
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 yield done.promise;
});
}
/**
* stops the smartbrowser instance
*/
stop() {
return __awaiter(this, void 0, void 0, function* () {
this.bsInstance.exit();
this.bsStatus = 'idle';
});
}
reload() {
return __awaiter(this, void 0, void 0, function* () {
this.bsInstance.reload();
});
}
}
exports.Smartbrowser = Smartbrowser;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsa0RBQWlEO0FBZ0JqRDs7R0FFRztBQUNIO0lBT0UsWUFBYSxVQUFnQztRQU43QyxlQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLEVBQUUsQ0FBQTtRQUN6QyxhQUFRLEdBQWdDO1lBQ3RDLE1BQU0sRUFBRSxFQUFFO1NBQ1gsQ0FBQTtRQUNELGFBQVEsR0FBYSxNQUFNLENBQUE7UUFHekIsSUFBSSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUE7UUFDakQsSUFBSSxDQUFDLFFBQVEsQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFDLFVBQVUsQ0FBQTtJQUM3QyxDQUFDO0lBRUQ7O09BRUc7SUFDRyxLQUFLOztZQUNULElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUEyQyxDQUFBO1lBQzFFLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxRQUFRLEtBQUssTUFBTSxDQUFDLENBQUMsQ0FBQztnQkFDN0IsSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUE7Z0JBQzFCLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFRLENBQUE7Z0JBQzVDLElBQUksQ0FBQyxTQUFTLEdBQUcsU0FBUyxDQUFDLE9BQU8sQ0FBQTtnQkFDbEMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFFBQVEsRUFBRTtvQkFDbEMsSUFBSSxDQUFDLFFBQVEsR0FBRyxTQUFTLENBQUE7b0JBQ3pCLFNBQVMsQ0FBQyxPQUFPLEVBQUUsQ0FBQTtvQkFDbkIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUE7Z0JBQy9CLENBQUMsQ0FBQyxDQUFBO1lBQ0osQ0FBQztZQUFDLElBQUksQ0FBQyxDQUFDO2dCQUNOLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtZQUM5RCxDQUFDO1lBQ0QsTUFBTSxDQUFDLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQTtRQUMzQixDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNHLElBQUk7O1lBQ1IsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtZQUN0QixJQUFJLENBQUMsUUFBUSxHQUFHLE1BQU0sQ0FBQTtRQUN4QixDQUFDO0tBQUE7SUFFSyxNQUFNOztZQUNWLElBQUksQ0FBQyxVQUFVLENBQUMsTUFBTSxFQUFFLENBQUE7UUFDMUIsQ0FBQztLQUFBO0NBQ0Y7QUEzQ0Qsb0NBMkNDIn0=

View File

@ -1,3 +0,0 @@
import 'typings-global';
export import browserSync = require('browser-sync');
export import smartq = require('smartq');

View File

@ -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=

View File

@ -1,7 +1,16 @@
{
"npmci": {
"globalNpmTools": [
"npmts"
]
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartbrowser",
"shortDescription": "puppeteer wrapper for easy tasks",
"npmPackagename": "@pushrocks/smartbrowser",
"license": "MIT"
}
}
}

View File

@ -1,11 +1,13 @@
{
"name": "smartbrowser",
"version": "1.0.5",
"description": "wraps browser-sync",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@pushrocks/smartbrowser",
"version": "2.0.3",
"description": "simplified puppeteer",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)"
},
"repository": {
"type": "git",
@ -18,13 +20,31 @@
},
"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.13",
"@pushrocks/smartpdf": "^3.0.2",
"@pushrocks/smartpuppeteer": "^2.0.0",
"@pushrocks/smartunique": "^3.0.3"
},
"devDependencies": {
"smartdelay": "^1.0.1",
"tapbundle": "^1.0.5"
}
"@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.69",
"@pushrocks/tapbundle": "^5.0.3"
},
"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"
]
}

4071
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

39
readme.md Normal file
View 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 | [![pipeline status](https://gitlab.com/pushrocks/smartbrowser/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartbrowser/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartbrowser)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartbrowser)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartbrowser)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartbrowser)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartbrowser)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](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 | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,6 +0,0 @@
<head>
<title>Test</title>
</head>
<body>
Test
</body>

View File

@ -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

View File

@ -1,29 +1,36 @@
import { tap, expect } from 'tapbundle'
import * as smartdelay from 'smartdelay'
import * as smartbrowser from '../dist/index'
let testSmartBrowser: smartbrowser.Smartbrowser
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
import * as smartbrowser from '../ts/index.js';
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).toBeInstanceOf(smartbrowser.SmartBrowser);
});
tap.test('should start the browser ', async () => {
return await expect(testSmartBrowser.start()).to.eventually.be.fulfilled
}).catch(tap.threw)
await testSmartBrowser.start();
});
tap.test('should create a PDF from a page', async (tools) => {
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
expect(result.buffer).toBeInstanceOf(Buffer);
});
tap.test('should produce a valid screenshot', async (tools) => {
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
expect(result.buffer).toBeInstanceOf(Buffer);
});
tap.test('should evalute something in the browser', async () => {
const result = await testSmartBrowser.evaluateOnPage('https://lossless.com', async () => {
return window.location.toString();
});
console.log(result);
});
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 testSmartBrowser.stop();
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartbrowser',
version: '2.0.3',
description: 'simplified puppeteer'
}

View File

@ -1,63 +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 {
webroot: string
watchFiles: string[]
export class SmartBrowser {
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
public smartpdf: plugins.smartpdf.SmartPdf;
}
/**
* Type of status that a bsInstance can have
*/
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
/**
* 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);
}
/**
* starts the server and returns the browserSync instance in a resolved Promise
* stop the SmartBrowser instance
*/
async 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 await done.promise
public async stop() {
await this.headlessBrowser.close();
await this.smartpdf.stop();
}
/**
* stops the smartbrowser instance
* create a pdf from page
* @param urlArg
*/
async stop (): Promise<void> {
this.bsInstance.exit()
this.bsStatus = 'idle'
public async pdfFromPage(urlArg: string) {
const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
return result;
}
async reload (): Promise<void> {
this.bsInstance.reload()
/**
* make a screenshot from a page
* @param urlArg
*/
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',
}) 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
View File

@ -0,0 +1 @@
export * from './interfaces.screenshotresult.js';

View File

@ -0,0 +1,5 @@
export interface IScreenShotResult {
name: string;
id: string;
buffer: Buffer;
}

View File

@ -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

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}

2818
yarn.lock

File diff suppressed because it is too large Load Diff