Skip to content

Commit 0ce41be

Browse files
committed
refactor: split modules and reorganize files
1 parent 5fc130c commit 0ce41be

24 files changed

Lines changed: 569 additions & 304 deletions

eslint.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import antfu from "@antfu/eslint-config";
33

44
export default antfu({
5-
javascript: {
6-
overrides: {
7-
"no-console": "off",
8-
},
9-
},
5+
javascript: true,
106
typescript: true,
117
stylistic: {
128
semi: true,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"chalk": "5.3.0",
6868
"chokidar": "3.6.0",
6969
"commander": "12.1.0",
70-
"consola": "3.2.3",
7170
"conventional-changelog": "6.0.0",
7271
"esbuild": "0.23.0",
7372
"fast-glob": "3.3.2",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import process from "node:process";
44
import { Command } from "commander";
5-
import consola from "consola";
65
import updateNotifier from "update-notifier";
76
import pkg from "../package.json";
7+
import { Log } from "./utils/log.js";
88
import { Build, Config, Release, Serve } from "./index.js";
99

10+
const logger = new Log();
11+
1012
export default async function main() {
1113
updateNotifier({ pkg }).notify();
1214

@@ -53,38 +55,38 @@ export default async function main() {
5355
.command("create")
5456
.description("Create the plugin template.")
5557
.action((_options: any) => {
56-
consola.error("The create not yet implemented");
58+
logger.error("The create not yet implemented");
5759
// new Create().run();
5860
});
5961

6062
cli
6163
.command("release")
6264
.description("Release.")
6365
.action(async (_options: any) => {
64-
// consola.error("The release not yet implemented");
66+
// logger.error("The release not yet implemented");
6567
process.env.NODE_ENV = "production";
6668
const config = await Config.loadConfig({});
6769
new Release(config).run();
6870
});
6971

7072
cli.arguments("<command>").action((cmd) => {
7173
cli.outputHelp();
72-
consola.error(`Unknown command name=${cmd}.`);
74+
logger.error(`Unknown command name=${cmd}.`);
7375
});
7476

7577
cli.parse();
7678
}
7779

7880
main().catch((err) => {
79-
console.log("");
80-
consola.error(err);
81-
console.log("");
81+
logger.newLine();
82+
logger.error(err);
83+
logger.newLine();
8284
process.exit(1);
8385
});
8486

8587
process.on("unhandledRejection", (err) => {
86-
console.log("");
87-
consola.error(err);
88-
console.log("");
88+
logger.newLine();
89+
logger.error(err);
90+
logger.newLine();
8991
process.exit(1);
9092
});

src/config.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { loadConfig as c12 } from "c12";
33
import fs from "fs-extra";
44
import { createHooks } from "hookable";
55
import { dash, mapValues, template } from "radash";
6-
import { createConsola } from "consola";
76
import type { Config, Context, OverrideConfig, UserConfig } from "./types/index.js";
8-
import { LogLevels, bumppProgress } from "./utils/log.js";
7+
import { Log, bumppProgress } from "./utils/log.js";
98
import { dateFormat } from "./utils/string.js";
109

1110
/**
@@ -37,11 +36,7 @@ export async function loadConfig(overrides?: OverrideConfig): Promise<Context> {
3736
}
3837

3938
function resolveConfig(config: Config): Context {
40-
// this.logger = new Log(config);
41-
const logger = createConsola({
42-
level: LogLevels[config.logLevel],
43-
fancy: true,
44-
});
39+
const logger = new Log(config);
4540

4641
// Load user's package.json
4742
const pkg = fs.readJsonSync(path.join("package.json"), {
@@ -164,6 +159,24 @@ const defaultConfig = {
164159
push: true,
165160
progress: bumppProgress,
166161
},
162+
changelog: "",
163+
github: {
164+
release: true,
165+
updater: "release",
166+
comment: false,
167+
releaseNote(ctx) {
168+
return ctx.release.changelog;
169+
},
170+
},
171+
gitee: {
172+
release: false,
173+
updater: "release",
174+
comment: false,
175+
releaseNote(ctx) {
176+
return ctx.release.changelog;
177+
},
178+
},
179+
hooks: {},
167180
},
168181
logLevel: "info",
169182
} satisfies Config;

src/lib/base.ts renamed to src/core/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export abstract class Base {
66
this.ctx = ctx;
77
}
88

9+
abstract run(): any;
10+
911
get logger() {
1012
return this.ctx.logger;
1113
}

src/lib/build.ts renamed to src/core/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class Build extends Base {
3232

3333
const t = new Date();
3434
this.buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
35-
this.logger.start(
35+
this.logger.info(
3636
`Building version ${chalk.blue(version)} to ${chalk.blue(dist)} at ${chalk.blue(this.buildTime)} in ${chalk.blue(env.NODE_ENV)} mode.`,
3737
);
3838
await this.ctx.hooks.callHook("build:init", this.ctx);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// npx 创建模板
22
import { input } from "@inquirer/prompts";
3+
import { Base } from "./base.js";
34

4-
export default class Create {
5+
export default class Create extends Base {
56
async run() {
67
const answers = await this.prompting();
7-
console.log(answers);
8+
this.logger.log(answers);
89
}
910

1011
async prompting() {

src/core/linter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// AddonLint
2+
import type { Context } from "../types/index.js";
3+
import { Base } from "./base.js";
4+
5+
export default class Lint extends Base {
6+
constructor(ctx: Context) {
7+
super(ctx);
8+
}
9+
10+
run() {
11+
// webext.cmd.lint({});
12+
}
13+
}

src/core/releaser/base.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { isCI } from "std-env";
2+
import type { Context } from "../../types/index.js";
3+
import { Base } from "../base.js";
4+
5+
export abstract class ReleaseBase extends Base {
6+
isCI: boolean;
7+
constructor(ctx: Context) {
8+
super(ctx);
9+
this.isCI = isCI;
10+
}
11+
12+
abstract run(): Promise<Context> | Context;
13+
14+
get owner(): string {
15+
return this.ctx.templateDate.owner;
16+
}
17+
18+
get repo(): string {
19+
return this.ctx.templateDate.repo;
20+
}
21+
}

0 commit comments

Comments
 (0)