zotero-plugin-scaffold 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/dist/config.js +15 -21
- package/dist/{utils/libBase.d.ts → lib/base.d.ts} +2 -2
- package/dist/{utils/libBase.js → lib/base.js} +2 -2
- package/dist/lib/build.d.ts +2 -2
- package/dist/lib/build.js +3 -2
- package/dist/lib/release.d.ts +4 -3
- package/dist/lib/release.js +47 -24
- package/dist/lib/serve.d.ts +4 -3
- package/dist/lib/serve.js +26 -10
- package/dist/types.d.ts +0 -6
- package/dist/utils/log.js +2 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -23,8 +23,6 @@ pnpm dlx zotero-plugin create
|
|
|
23
23
|
|
|
24
24
|
#### From NPM
|
|
25
25
|
|
|
26
|
-
> WIP
|
|
27
|
-
|
|
28
26
|
```bash
|
|
29
27
|
npm install -D zotero-plugin-scaffold
|
|
30
28
|
|
|
@@ -66,7 +64,7 @@ You can import `defineConfig` in js module to get type hints. If no value is spe
|
|
|
66
64
|
import { defineConfig } from "zotero-plugin-scaffold";
|
|
67
65
|
|
|
68
66
|
export default defineConfig({
|
|
69
|
-
|
|
67
|
+
define: {
|
|
70
68
|
addonName: "Test Addon for Zotero",
|
|
71
69
|
addonID: "",
|
|
72
70
|
addonRef: "",
|
|
@@ -137,7 +135,7 @@ import { Build, Config } from "zotero-plugin-scaffold";
|
|
|
137
135
|
|
|
138
136
|
const config = await Config.loadConfig();
|
|
139
137
|
|
|
140
|
-
const Builder = new Build(config
|
|
138
|
+
const Builder = new Build(config);
|
|
141
139
|
await Builder.run();
|
|
142
140
|
```
|
|
143
141
|
|
package/dist/config.js
CHANGED
|
@@ -28,8 +28,7 @@ export async function loadConfig(file) {
|
|
|
28
28
|
const dotenvResult = dotenv.config({
|
|
29
29
|
path: path.resolve(process.cwd(), userConfig.dotEnvPath ?? ".env"),
|
|
30
30
|
}).parsed;
|
|
31
|
-
if (!dotenvResult)
|
|
32
|
-
throw new Error(".env file not found");
|
|
31
|
+
// if (!dotenvResult) throw new Error(".env file not found");
|
|
33
32
|
// Load user's package.json
|
|
34
33
|
const pkg = fs.readJsonSync(path.join("package.json"), {
|
|
35
34
|
encoding: "utf-8",
|
|
@@ -56,7 +55,7 @@ export async function loadConfig(file) {
|
|
|
56
55
|
ghOwner: owner,
|
|
57
56
|
ghRepo: repo,
|
|
58
57
|
addonRef: pkg.config?.addonRef || _.kebabCase(addonName),
|
|
59
|
-
addonInstance: pkg.config?.
|
|
58
|
+
addonInstance: pkg.config?.addonInstance || _.camelCase(addonName),
|
|
60
59
|
prefsPrefix: `extensions.zotero.${addonRef}`,
|
|
61
60
|
xpiName: xpiName,
|
|
62
61
|
releasePage: releasePage,
|
|
@@ -135,19 +134,19 @@ export async function loadConfig(file) {
|
|
|
135
134
|
extraBuilder: () => { },
|
|
136
135
|
addonLint: {},
|
|
137
136
|
release: {
|
|
138
|
-
releaseIt: {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
},
|
|
137
|
+
// releaseIt: {
|
|
138
|
+
// preReleaseId: "beta",
|
|
139
|
+
// git: {
|
|
140
|
+
// tagName: "v${version}",
|
|
141
|
+
// requireCleanWorkingDir: false,
|
|
142
|
+
// },
|
|
143
|
+
// npm: {
|
|
144
|
+
// publish: false,
|
|
145
|
+
// },
|
|
146
|
+
// github: {
|
|
147
|
+
// assets: [`${userConfig.dist}/*.xpi`],
|
|
148
|
+
// },
|
|
149
|
+
// },
|
|
151
150
|
bumpp: {
|
|
152
151
|
release: "prompt",
|
|
153
152
|
preid: "beta",
|
|
@@ -160,11 +159,6 @@ export async function loadConfig(file) {
|
|
|
160
159
|
},
|
|
161
160
|
logLevel: "info",
|
|
162
161
|
dotEnvPath: ".env",
|
|
163
|
-
cmd: {
|
|
164
|
-
zoteroBinPath: dotenvResult["zoteroBinPath"],
|
|
165
|
-
profilePath: dotenvResult["profilePath"],
|
|
166
|
-
dataDir: dotenvResult["dataDir"],
|
|
167
|
-
},
|
|
168
162
|
pkgUser: pkg,
|
|
169
163
|
pkgAbsolute: path.join(path.dirname(fileURLToPath(import.meta.url)), "../"),
|
|
170
164
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config } from "../types.js";
|
|
2
|
-
import Log from "
|
|
3
|
-
export declare abstract class
|
|
2
|
+
import Log from "../utils/log.js";
|
|
3
|
+
export declare abstract class Base {
|
|
4
4
|
config: Config;
|
|
5
5
|
logger: InstanceType<typeof Log>;
|
|
6
6
|
constructor(config: Config);
|
package/dist/lib/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config } from "../types.js";
|
|
2
|
-
import {
|
|
3
|
-
export default class Build extends
|
|
2
|
+
import { Base } from "./base.js";
|
|
3
|
+
export default class Build extends Base {
|
|
4
4
|
private buildTime;
|
|
5
5
|
private isPreRelease;
|
|
6
6
|
constructor(config: Config);
|
package/dist/lib/build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateHashSync } from "../utils/crypto.js";
|
|
2
|
-
import { LibBase } from "../utils/libBase.js";
|
|
3
2
|
import { dateFormat } from "../utils/string.js";
|
|
3
|
+
import { Base } from "./base.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { zip } from "compressing";
|
|
6
6
|
import { buildSync } from "esbuild";
|
|
@@ -9,11 +9,12 @@ import fs from "fs-extra";
|
|
|
9
9
|
import path from "path";
|
|
10
10
|
import replaceInFile from "replace-in-file";
|
|
11
11
|
const { replaceInFileSync } = replaceInFile;
|
|
12
|
-
export default class Build extends
|
|
12
|
+
export default class Build extends Base {
|
|
13
13
|
buildTime;
|
|
14
14
|
isPreRelease;
|
|
15
15
|
constructor(config) {
|
|
16
16
|
super(config);
|
|
17
|
+
process.env.NODE_ENV ??= "production";
|
|
17
18
|
this.buildTime = "";
|
|
18
19
|
this.isPreRelease = this.version.includes("-");
|
|
19
20
|
}
|
package/dist/lib/release.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Config } from "../types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Base } from "./base.js";
|
|
3
3
|
import { Octokit } from "@octokit/rest";
|
|
4
|
-
export default class Release extends
|
|
4
|
+
export default class Release extends Base {
|
|
5
5
|
isCI: boolean;
|
|
6
6
|
client: Octokit;
|
|
7
7
|
constructor(config: Config);
|
|
@@ -22,7 +22,7 @@ export default class Release extends LibBase {
|
|
|
22
22
|
/**
|
|
23
23
|
* Create new release and upload XPI to asset
|
|
24
24
|
*/
|
|
25
|
-
uploadXPI(): void
|
|
25
|
+
uploadXPI(): Promise<void>;
|
|
26
26
|
getReleaseByTag(tag: string): Promise<{
|
|
27
27
|
url: string;
|
|
28
28
|
html_url: string;
|
|
@@ -249,6 +249,7 @@ export default class Release extends LibBase {
|
|
|
249
249
|
} | null;
|
|
250
250
|
}>;
|
|
251
251
|
uploadUpdateJSON(): Promise<void>;
|
|
252
|
+
getChangelog(): Promise<unknown>;
|
|
252
253
|
getClient(): Octokit;
|
|
253
254
|
get owner(): string;
|
|
254
255
|
get repo(): string;
|
package/dist/lib/release.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Base } from "./base.js";
|
|
2
2
|
import { Octokit } from "@octokit/rest";
|
|
3
|
+
import versionBump from "bumpp";
|
|
3
4
|
import ci from "ci-info";
|
|
5
|
+
import conventionalChangelog from "conventional-changelog";
|
|
4
6
|
import { default as glob } from "fast-glob";
|
|
5
7
|
import fs from "fs-extra";
|
|
6
|
-
import _ from "lodash";
|
|
7
8
|
import mime from "mime";
|
|
8
9
|
import path from "path";
|
|
9
|
-
|
|
10
|
-
export default class Release extends LibBase {
|
|
10
|
+
export default class Release extends Base {
|
|
11
11
|
isCI;
|
|
12
12
|
client;
|
|
13
13
|
constructor(config) {
|
|
@@ -40,30 +40,38 @@ export default class Release extends LibBase {
|
|
|
40
40
|
* release: bump version, run build, git add, git commit, git tag, git push
|
|
41
41
|
*/
|
|
42
42
|
bump() {
|
|
43
|
-
|
|
44
|
-
const releaseItConfig = {
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
|
|
43
|
+
versionBump(this.config.release.bumpp);
|
|
44
|
+
// const releaseItConfig: ReleaseItConfig = {
|
|
45
|
+
// "only-version": true,
|
|
46
|
+
// };
|
|
47
|
+
// releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Create new release and upload XPI to asset
|
|
51
51
|
*/
|
|
52
|
-
uploadXPI() {
|
|
53
|
-
const releaseItConfig = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
async uploadXPI() {
|
|
53
|
+
// const releaseItConfig: ReleaseItConfig = {
|
|
54
|
+
// increment: false,
|
|
55
|
+
// git: { commit: false, tag: false, push: false },
|
|
56
|
+
// github: {
|
|
57
|
+
// release: true,
|
|
58
|
+
// },
|
|
59
|
+
// verbose: 2,
|
|
60
|
+
// ci: true,
|
|
61
|
+
// };
|
|
62
|
+
// releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
|
|
63
|
+
const release = await this.creatRelease({
|
|
64
|
+
owner: this.owner,
|
|
65
|
+
repo: this.repo,
|
|
66
|
+
tag_name: `v${this.version}`,
|
|
67
|
+
name: `Release v${this.version}`,
|
|
68
|
+
bofy: await this.getChangelog(),
|
|
69
|
+
prerelease: this.version.includes("-"),
|
|
70
|
+
make_latest: "true",
|
|
71
|
+
});
|
|
72
|
+
if (!release)
|
|
73
|
+
throw new Error("Creat release failed!");
|
|
74
|
+
this.uploadAsset(release.id, path.join(this.config.dist, `${this.xpiName}.xpi`));
|
|
67
75
|
}
|
|
68
76
|
async getReleaseByTag(tag) {
|
|
69
77
|
return await this.client.repos
|
|
@@ -147,6 +155,21 @@ export default class Release extends LibBase {
|
|
|
147
155
|
await this.uploadAsset(release.id, path.join(this.config.dist, asset));
|
|
148
156
|
}
|
|
149
157
|
}
|
|
158
|
+
getChangelog() {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
let changelog = "";
|
|
161
|
+
conventionalChangelog({ releaseCount: 2 }, { version: this.version })
|
|
162
|
+
.on("data", (chunk) => {
|
|
163
|
+
changelog += chunk.toString();
|
|
164
|
+
})
|
|
165
|
+
.on("end", () => {
|
|
166
|
+
resolve(changelog);
|
|
167
|
+
})
|
|
168
|
+
.on("error", (err) => {
|
|
169
|
+
reject(err);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
150
173
|
getClient() {
|
|
151
174
|
if (!process.env.GITHUB_TOKEN)
|
|
152
175
|
throw new Error("No GITHUB_TOKEN.");
|
package/dist/lib/serve.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Config } from "../types.js";
|
|
2
|
-
import {
|
|
3
|
-
export default class Serve extends
|
|
3
|
+
import { Base } from "./base.js";
|
|
4
|
+
export default class Serve extends Base {
|
|
4
5
|
private builder;
|
|
5
6
|
constructor(config: Config);
|
|
6
7
|
run(): Promise<void>;
|
|
@@ -8,7 +9,7 @@ export default class Serve extends LibBase {
|
|
|
8
9
|
* watch source dir and build when file changed
|
|
9
10
|
*/
|
|
10
11
|
watch(): Promise<void>;
|
|
11
|
-
startZotero():
|
|
12
|
+
startZotero(): Promise<import("child_process").ChildProcessWithoutNullStreams>;
|
|
12
13
|
/**
|
|
13
14
|
* start zotero with plugin installed and reload when dist changed
|
|
14
15
|
*/
|
package/dist/lib/serve.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Base } from "./base.js";
|
|
2
2
|
import Build from "./build.js";
|
|
3
3
|
import { execSync, spawn } from "child_process";
|
|
4
4
|
import chokidar from "chokidar";
|
|
@@ -7,18 +7,19 @@ import _ from "lodash";
|
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { exit } from "process";
|
|
9
9
|
import webext from "web-ext";
|
|
10
|
-
export default class Serve extends
|
|
10
|
+
export default class Serve extends Base {
|
|
11
11
|
builder;
|
|
12
12
|
constructor(config) {
|
|
13
13
|
super(config);
|
|
14
|
+
process.env.NODE_ENV ??= "development";
|
|
14
15
|
this.builder = new Build(config);
|
|
15
16
|
}
|
|
16
17
|
async run() {
|
|
17
18
|
// build
|
|
18
|
-
this.builder.run();
|
|
19
|
+
await this.builder.run();
|
|
19
20
|
// start Zotero
|
|
20
|
-
|
|
21
|
-
this.startZoteroWebExt();
|
|
21
|
+
this.startZotero();
|
|
22
|
+
// this.startZoteroWebExt();
|
|
22
23
|
// watch
|
|
23
24
|
await this.config.extraServer(this.config);
|
|
24
25
|
await this.watch();
|
|
@@ -62,19 +63,33 @@ export default class Serve extends LibBase {
|
|
|
62
63
|
this.logger.error("Server start failed!", err);
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
|
-
startZotero() {
|
|
66
|
+
async startZotero() {
|
|
67
|
+
let isZoteroReady = false;
|
|
66
68
|
if (!fs.existsSync(this.zoteroBinPath)) {
|
|
67
69
|
throw new Error("Zotero binary does not exist.");
|
|
68
70
|
}
|
|
69
71
|
if (!fs.existsSync(this.profilePath)) {
|
|
70
72
|
throw new Error("The given Zotero profile does not exist.");
|
|
71
73
|
}
|
|
74
|
+
this.prepareDevEnv();
|
|
72
75
|
const zoteroProcess = spawn(this.zoteroBinPath, [
|
|
73
76
|
"--debugger",
|
|
74
77
|
"--purgecaches",
|
|
75
78
|
"-profile",
|
|
76
79
|
this.profilePath,
|
|
77
80
|
]);
|
|
81
|
+
zoteroProcess.stdout?.on("data", (data) => {
|
|
82
|
+
if (!isZoteroReady &&
|
|
83
|
+
data
|
|
84
|
+
.toString()
|
|
85
|
+
.includes(`Calling bootstrap method 'startup' for plugin ${this.addonID}`)) {
|
|
86
|
+
console.log(data.toString());
|
|
87
|
+
isZoteroReady = true;
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
this.openDevTool();
|
|
90
|
+
}, 1000);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
78
93
|
zoteroProcess.on("close", (code) => {
|
|
79
94
|
this.logger.info(`Zotero terminated with code ${code}.`);
|
|
80
95
|
exit(0);
|
|
@@ -84,14 +99,15 @@ export default class Serve extends LibBase {
|
|
|
84
99
|
zoteroProcess.kill();
|
|
85
100
|
exit();
|
|
86
101
|
});
|
|
102
|
+
return zoteroProcess;
|
|
87
103
|
}
|
|
88
104
|
/**
|
|
89
105
|
* start zotero with plugin installed and reload when dist changed
|
|
90
106
|
*/
|
|
91
107
|
async startZoteroWebExt() {
|
|
92
108
|
await webext.cmd.run({
|
|
93
|
-
firefox: this.
|
|
94
|
-
firefoxProfile: this.
|
|
109
|
+
firefox: this.zoteroBinPath,
|
|
110
|
+
firefoxProfile: this.profilePath,
|
|
95
111
|
sourceDir: path.resolve(`${this.config.dist}/addon`),
|
|
96
112
|
keepProfileChanges: true,
|
|
97
113
|
args: ["--debugger", "--purgecaches"],
|
|
@@ -220,11 +236,11 @@ export default class Serve extends LibBase {
|
|
|
220
236
|
execSync(command);
|
|
221
237
|
}
|
|
222
238
|
get zoteroBinPath() {
|
|
223
|
-
this.logger.debug("zoteroBinPath", process.env.zoteroBinPath);
|
|
239
|
+
// this.logger.debug("zoteroBinPath", process.env.zoteroBinPath);
|
|
224
240
|
return process.env.zoteroBinPath ?? "";
|
|
225
241
|
}
|
|
226
242
|
get profilePath() {
|
|
227
|
-
this.logger.debug("profilePath", process.env.profilePath);
|
|
243
|
+
// this.logger.debug("profilePath", process.env.profilePath);
|
|
228
244
|
return process.env.profilePath ?? "";
|
|
229
245
|
}
|
|
230
246
|
get dataDir() {
|
package/dist/types.d.ts
CHANGED
|
@@ -271,7 +271,6 @@ export interface ConfigBase {
|
|
|
271
271
|
* 发布相关配置
|
|
272
272
|
*/
|
|
273
273
|
release: {
|
|
274
|
-
releaseIt: Partial<ReleaseItConfig>;
|
|
275
274
|
bumpp: VersionBumpOptions;
|
|
276
275
|
};
|
|
277
276
|
/**
|
|
@@ -282,11 +281,6 @@ export interface ConfigBase {
|
|
|
282
281
|
logLevel: "trace" | "debug" | "info" | "warn" | "error";
|
|
283
282
|
}
|
|
284
283
|
export interface Config extends ConfigBase {
|
|
285
|
-
cmd: {
|
|
286
|
-
zoteroBinPath: string;
|
|
287
|
-
profilePath: string;
|
|
288
|
-
dataDir: string;
|
|
289
|
-
};
|
|
290
284
|
pkgUser: any;
|
|
291
285
|
pkgAbsolute: string;
|
|
292
286
|
}
|
package/dist/utils/log.js
CHANGED
|
@@ -42,8 +42,9 @@ export default class Log {
|
|
|
42
42
|
this.log(chalk.green("INFO"), ...args);
|
|
43
43
|
}
|
|
44
44
|
debug(...args) {
|
|
45
|
+
// if (this.logLevel <= 1) this.log(chalk.grey("DEBUG"), ...args);
|
|
45
46
|
if (this.logLevel <= 1)
|
|
46
|
-
this.log(
|
|
47
|
+
this.log(...args);
|
|
47
48
|
}
|
|
48
49
|
trace(...args) {
|
|
49
50
|
if (this.logLevel <= 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zotero-plugin-scaffold",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "A scaffold for Zotero plugin development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -52,9 +52,12 @@
|
|
|
52
52
|
"ci-info": "^4.0.0",
|
|
53
53
|
"commander": "^11.1.0",
|
|
54
54
|
"compressing": "^1.10.0",
|
|
55
|
+
"conventional-changelog": "^5.1.0",
|
|
56
|
+
"conventional-commits-detector": "^1.0.3",
|
|
55
57
|
"cosmiconfig": "^9.0.0",
|
|
56
58
|
"dotenv": "^16.4.1",
|
|
57
59
|
"esbuild": "^0.19.12",
|
|
60
|
+
"execa": "^8.0.1",
|
|
58
61
|
"fast-glob": "^3.3.2",
|
|
59
62
|
"fs-extra": "^11.2.0",
|
|
60
63
|
"lodash": "^4.17.21",
|
|
@@ -67,12 +70,13 @@
|
|
|
67
70
|
},
|
|
68
71
|
"devDependencies": {
|
|
69
72
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
73
|
+
"@types/conventional-changelog": "^3.1.5",
|
|
70
74
|
"@types/fs-extra": "^11.0.4",
|
|
71
75
|
"@types/lodash": "^4.14.202",
|
|
72
|
-
"@types/node": "^20.11.
|
|
76
|
+
"@types/node": "^20.11.16",
|
|
73
77
|
"@types/update-notifier": "^6.0.8",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
75
|
-
"@typescript-eslint/parser": "^6.
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
79
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
76
80
|
"eslint": "^8.56.0",
|
|
77
81
|
"eslint-config-prettier": "^9.1.0",
|
|
78
82
|
"prettier": "^3.2.4",
|