Skip to content

update packages to work with latest node LTS version #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 140,
"trailingComma": "all",
"bracketSpacing": false,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid"
}
50 changes: 27 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env node

const path = require('path');
const fs = require('fs-extra');
const meow = require('meow');
const puppeteer = require('puppeteer');
const liveServer = require('live-server');
const chalk = require('chalk');
const ora = require('ora');
import process from 'node:process';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {existsSync, mkdirSync, readFileSync} from 'node:fs';
import fs from 'fs-extra';
import meow from 'meow';
import * as puppeteer from 'puppeteer';
import LiveServer from 'alive-server';
import chalk from 'chalk';
import ora from 'ora';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const cli = meow({
description: false,
Expand Down Expand Up @@ -104,6 +110,7 @@ const cli = meow({
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
`,
importMeta: import.meta,
flags: {
name: {
type: 'string',
Expand Down Expand Up @@ -142,7 +149,7 @@ switch (cli.input[0]) {
}

function serve(flags) {
liveServer.start({
LiveServer.start({
port: 8180,
root: process.cwd(),
open: `/${flags.input}`,
Expand All @@ -155,11 +162,11 @@ function init(flags) {
const {name} = flags;
const presentationPath = path.resolve(name);

if (fs.existsSync(presentationPath)) {
if (existsSync(presentationPath)) {
abort(`The directory ${chalk.underline(name)} is already existing.`, spinner);
}

fs.mkdirSync(presentationPath);
mkdirSync(presentationPath);
fs.copySync(path.resolve(__dirname, 'template'), presentationPath);
spinner.succeed(`Directory ${chalk.underline(name)} has been initialized.`);
}
Expand All @@ -168,48 +175,45 @@ function update() {
const spinner = ora('Updating ...').start();
const file = 'onepunch.json';

if (!fs.existsSync(file)) {
if (!existsSync(file)) {
abort(`File ${chalk.underline('onepunch.json')} is not present. Are you sure this is the right directory?`, spinner);
}

fs.copySync(
path.resolve(__dirname, 'template/src'),
'src',
{overwrite: true},
);
fs.copySync(path.resolve(__dirname, 'template/src'), 'src', {
overwrite: true,
});
spinner.succeed(`Directory ${chalk.underline('src')} has been updated to release ${cli.pkg.version}.`);
}

function print(flags) {
const spinner = ora('Printing ...').start();
const {input, output} = flags;

liveServer.start({
LiveServer.start({
port: 8181,
root: process.cwd(),
open: false,
logLevel: 0,
});

const config = JSON.parse(fs.readFileSync('onepunch.json'));
const config = JSON.parse(readFileSync('onepunch.json'));
const width = config.width || 960;
const height = config.height || 600;

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
`http://127.0.0.1:8181/${input}`,
{waitUntil: 'networkidle0'},
);
await page.goto(`http://127.0.0.1:8181/${input}`, {
waitUntil: 'networkidle0',
});
await page.pdf({
path: output,
width,
height,
printBackground: true,
});
await browser.close();
liveServer.shutdown();
LiveServer.shutdown();
spinner.succeed(`File ${chalk.underline(output)} has been successfully created.`);
})();
}
Expand Down
Loading