Skip to content

Commit

Permalink
feat: support checkinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Apr 6, 2024
1 parent d4681a3 commit bb7b25b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
3 changes: 3 additions & 0 deletions lib/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import generateTiddlyWikiInfo from '../tiddlywiki.config.mjs';
import config from '../config/index.mjs';
import genSidebar from './genSidebar.mjs';
import useId from './utils/useId.mjs';
import checkinfo from './utils/checkinfo.mjs';

const OUTPUTDIR = config.output;

Expand Down Expand Up @@ -69,6 +70,7 @@ const build = async () => {
case 'Netlify CI':
case 'Vercel':
case 'GitHub Actions':
case 'GitLab CI':
fs.rmSync('.gitignore'); // to support autocorrect to format
emitter.clone(`${config.wiki}`).then(() => {
// CRLF 会导致格式化卡住???
Expand All @@ -82,6 +84,7 @@ const build = async () => {
});
break;
default:
checkinfo();
log.warn(
chalk.red.bold(
`检测到是${
Expand Down
31 changes: 6 additions & 25 deletions lib/startup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { TiddlyWiki } from 'tiddlywiki';
import generateTiddlyWikiInfo from '../tiddlywiki.config.mjs';
import address from 'address';
import chalk from 'chalk';
import fs from 'fs';
import getPort from 'get-port';
import ora from 'ora';
import QRCode from 'qrcode';
import config from '../config/index.mjs';
import useId from './utils/useId.mjs';
import startup from '../config/startup.mjs';
import checkinfo from './utils/checkinfo.mjs';

// preloadTiddlerArray
const { boot: app, preloadTiddler } = TiddlyWiki();
Expand All @@ -23,11 +23,12 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
const spinner = ora('starting\n');
spinner.start();

generateTiddlyWikiInfo();
// const SyncerLogger = Boolean(process.env.SyncerLogger);

const port = await getPort({ port: [config.server.port, 8001, 8080, 8081] });
const { wiki: wikiLocation, info, checkfilesize } = config;
const { wiki: wikiLocation, checkfilesize } = config;

// const SyncerLogger = Boolean(process.env.SyncerLogger);
generateTiddlyWikiInfo();
checkinfo();

if (checkfilesize) {
const unnormallFileSizes = await checkFileSize(wikiLocation);
Expand All @@ -49,26 +50,6 @@ const { boot: app, preloadTiddler } = TiddlyWiki();
app.argv.push('host=' + config.server.hostname);
}

// Check if tiddlywiki.info does not exist in the wikiLocation directory, create and notify
const infoFile = `${wikiLocation}/tiddlywiki.info`;

if (!fs.existsSync(wikiLocation)) {
console.log(
chalk.yellow(
`${wikiLocation} folder does not exist Created this folder.`,
),
);
fs.mkdirSync(wikiLocation);
}
if (!fs.existsSync(infoFile)) {
fs.writeFileSync(infoFile, JSON.stringify(info, null, 2));
console.log(
chalk.yellow(
`tiddlywiki.info file does not exist in ${wikiLocation} directory. Created a new file.`,
),
);
}

// preloadTiddler({
// title: '$:/config/tiddlyweb/host',
// text: `$protocol$//$host$/src`,
Expand Down
27 changes: 27 additions & 0 deletions lib/utils/checkinfo.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'fs';
import chalk from 'chalk';
import config from '../../config/index.mjs';

const checkinfo = () => {
const { wiki: wikiLocation } = config;
const infoFile = `${wikiLocation}/tiddlywiki.info`;

if (!fs.existsSync(wikiLocation)) {
console.log(
chalk.yellow(
`${wikiLocation} folder does not exist Created this folder.`,
),
);
fs.mkdirSync(wikiLocation);
}
if (!fs.existsSync(infoFile)) {
fs.writeFileSync(infoFile, JSON.stringify(config.info, null, 2));
console.log(
chalk.yellow(
`tiddlywiki.info file does not exist in ${wikiLocation} directory. Created a new file.`,
),
);
}
};

export default checkinfo;
3 changes: 0 additions & 3 deletions plugins/oeyoews/neotw/tiddlers/system/sitetitle.tid
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
title: $:/SiteTitle

<% if [{$:/info/url/protocol}!match[https:]] %>
🔴
<% endif %>
TiddlyWiki Starter Kit

0 comments on commit bb7b25b

Please sign in to comment.