Skip to content

Commit

Permalink
1.0.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel garcia committed Apr 1, 2020
1 parent 8dd12b3 commit c1cd3cc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [1.0.0-beta.3] - 2020-04-01
### Added
- Option --debug so you can the puppeteer running in case you need to debug
### Fixed
- Command start didn't finish

## [1.0.0-beta.2] - 2020-03-31
### BREAKING CHANGES
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Stop commands updates the time when you stop the task
holded-bot stop
```

### Options

- --debug you can pass the option argument so you can see puppeteer running
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "holded-bot",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Holded bot from terminal",
"author": "Gabriel García Seco <[email protected]>",
"keywords": [
Expand All @@ -16,7 +16,7 @@
"!dist/**/*.test.js"
],
"scripts": {
"dev": "NODE_ENV=development ts-node ./src/cli.ts",
"dev": "ts-node ./src/cli.ts",
"lint": "eslint --ext .ts src",
"clean": "rimraf ./dist/ ./exec/",
"build": "npm run clean && tsc",
Expand Down
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ function executeCli({ email, company, password }) {

program.version(packageJSON.version);

program.option('-debug, --debug', 'Debug puppeteer');

program
.command('start')
.description('writes into the holded the time')
.action(function () {
startWork({ email, password }, routes);
startWork({ email, password }, routes, { debug: program.debug });
});

program
.command('stop')
.description('updates holded time with the time')
.action(function () {
stopWork({ email, password }, routes);
stopWork({ email, password }, routes, { debug: program.debug });
});

program.parse(process.argv);
Expand Down
25 changes: 14 additions & 11 deletions src/holded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import {
editLastTimeline
} from './puppetter';

export interface HoldedArgs {
start: boolean;
stop: boolean;
}

export interface AccountArgs {
interface AccountArgs {
email: string;
password: string;
}

export async function startWork(account: AccountArgs, routes): Promise<any> {
interface CliArgs {
debug: boolean;
}

export async function startWork(
account: AccountArgs,
routes,
args: CliArgs
): Promise<any> {
try {
const url = routes.LOGIN;
const { page, browser } = await startWithUrl(puppeteer, url);
const { page, browser } = await startWithUrl(puppeteer, url, args);
const dayOfTheWeek = DateTime.local().weekday;

const time = DateTime.local().toLocaleString(DateTime.TIME_SIMPLE);
Expand All @@ -45,17 +48,17 @@ export async function startWork(account: AccountArgs, routes): Promise<any> {
timeEnd
});

//await browser.close();
await browser.close();

console.log(`Start work at ${time}`);
} catch (error) {
console.log(error);
}
}

export async function stopWork(account: AccountArgs, routes) {
export async function stopWork(account: AccountArgs, routes, args: CliArgs) {
const url = routes.LOGIN;
const { page, browser } = await startWithUrl(puppeteer, url);
const { page, browser } = await startWithUrl(puppeteer, url, args);
const time = DateTime.local().toLocaleString(DateTime.TIME_SIMPLE);
const date = DateTime.local().toFormat('dd-MM-yyyy');

Expand Down
8 changes: 6 additions & 2 deletions src/puppetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export async function login(page, form) {
}
}

export async function startWithUrl(puppeteer, url: string) {
export async function startWithUrl(
puppeteer,
url: string,
options: { debug: boolean }
) {
try {
const browser = await puppeteer.launch({
headless: process.env.NODE_ENV === 'development' ? false : true
headless: !options.debug
});
const page = await browser.newPage();
const override = Object.assign(page.viewport(), { width: 1366 });
Expand Down

0 comments on commit c1cd3cc

Please sign in to comment.