Skip to content

Commit

Permalink
fix: remove open package and use original open
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 15, 2024
1 parent f3177f6 commit 589326d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
43 changes: 31 additions & 12 deletions lib/startup.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#!/usr/bin/env node
import config from '../config/index.mjs';
import generateTiddlyWikiInfo from './generateInfo.mjs';
import { checkFileSize, checkinfo, useId } from './utils/index.mjs';
import address from 'address';
import chalk from 'chalk';
import { exec } from 'child_process';
import { consola } from 'consola';
import 'dotenv/config';
import getPort from 'get-port';
import open from 'open';
// more than node18
// import open from 'open';
import ora from 'ora';
import QRCode from 'qrcode';
import { TiddlyWiki } from 'tiddlywiki';
import config from '../config/index.mjs';
import generateTiddlyWikiInfo from './generateInfo.mjs';
import { useId, checkinfo, checkFileSize } from './utils/index.mjs';

// preloadTiddlerArray
const { boot: app, preloadTiddler } = TiddlyWiki();

/** @description: TiddlyWiki starter kit entry point */
(async function main() {
const spinner = ora('starting\n');
spinner.start();
// consola.box('Welcom to TiddlyWiki Starter Kit(DEV)');
// const spinner = ora('starting').start('Loading ...\n');

const port = await getPort({ port: [config.server.port, 8001, 8080, 8081] });
const { wiki: wikiLocation, checkfilesize } = config;
Expand All @@ -36,8 +39,6 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
const ip = address.ip();
const ipdata = `http://${ip}:${port}`;

spinner.start();

app.argv = config.startup({
port,
});
Expand All @@ -55,7 +56,8 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
const ipTiddler = {
title: '$:/info/url/ip',
text: ipdata,
description: `当前太微实例(${useId})服务器 IP 地址 ` + ip,
// description: `当前太微实例(${useId})服务器 IP 地址 ` + ip,
description: `Current TiddlyWiki Server (${useId})IP:` + ip,
};

String(ip).startsWith('192.168') && preloadTiddler(ipTiddler);
Expand All @@ -67,7 +69,8 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
if (config.server.zen) {
console.clear();
}
spinner.succeed(chalk.green.bold(`[太微启动]: 成功(${useId})`));
// spinner.succeed();
consola.success(chalk.green.bold(`[TiddlyWiki]: Succeed(${useId})`));

const data = Object.assign({}, config, config.server);
delete data.server;
Expand All @@ -80,12 +83,28 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
small: true,
},
function (_, url) {
console.log(url);
consola.log(url);
},
);
}
if (config.server.open) {
await open('http://localhost:' + port);
// await open('http://localhost:' + port);

const os = process.platform;
const url = 'http://localhost:' + port;
const open = {
darwin: 'open',
linux: 'xdg-open',
win32: 'start',
};
consola.info(chalk.cyan.bold('[OS]:', os));

exec(`${open[os]} ${url}`, (err) => {
if (err) {
consola.error(err);
} else {
}
});
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@
"@types/fs-extra": "11.0.4",
"@types/prompts": "2.4.9",
"@types/qrcode": "1.5.5",
"consola": "^3.2.3",
"prettier": "3.2.5",
"terser": "5.31.0",
"tw5-typed": "^0.5.12",
"typescript": "^5.5.4"
},
"engines": {
"node": ">16.8.0"
"node": ">=16.8.0"
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion tiddlywiki.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
hostname: '0.0.0.0', // 主机名
qrcode: true, // 是否显示二维码
zen: false, // 是否启用zen模式
open: false, // 是否在启动时打开浏览器
open: true, // 是否在启动时打开浏览器
},
auth: false,
username: 'oeyoews', // 用户名
Expand Down

0 comments on commit 589326d

Please sign in to comment.