mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
feat: 升级midway,支持esm
This commit is contained in:
@@ -23,4 +23,4 @@ dist-ssr
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
test/user.secret.ts
|
||||
test/user.secret.*
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
link-workspace-packages=true
|
||||
prefer-workspace-packages=true
|
||||
@@ -0,0 +1,96 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
// https://gist.github.com/lovasoa/8691344
|
||||
async function* walk(dir) {
|
||||
for await (const d of await fs.promises.opendir(dir)) {
|
||||
const entry = path.join(dir, d.name);
|
||||
if (d.isDirectory()) {
|
||||
yield* walk(entry);
|
||||
} else if (d.isFile()) {
|
||||
yield entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveImportPath(sourceFile, importPath, options) {
|
||||
const sourceFileAbs = path.resolve(process.cwd(), sourceFile);
|
||||
const root = path.dirname(sourceFileAbs);
|
||||
const { moduleFilter = defaultModuleFilter } = options;
|
||||
|
||||
if (moduleFilter(importPath)) {
|
||||
const importPathAbs = path.resolve(root, importPath);
|
||||
let possiblePath = [path.resolve(importPathAbs, "./index.ts"), path.resolve(importPathAbs, "./index.js"), importPathAbs + ".ts", importPathAbs + ".js"];
|
||||
|
||||
if (possiblePath.length) {
|
||||
for (let i = 0; i < possiblePath.length; i++) {
|
||||
let entry = possiblePath[i];
|
||||
if (fs.existsSync(entry)) {
|
||||
const resolved = path.relative(root, entry.replace(/\.ts$/, ".js"));
|
||||
|
||||
if (!resolved.startsWith(".")) {
|
||||
return "./" + resolved;
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function replace(filePath, outFilePath, options) {
|
||||
const code = fs.readFileSync(filePath).toString();
|
||||
const newCode = code.replace(/(import|export) (.+?) from ('[^\n']+'|"[^\n"]+");/gs, function (found, action, imported, from) {
|
||||
const importPath = from.slice(1, -1);
|
||||
let resolvedPath = resolveImportPath(filePath, importPath, options);
|
||||
|
||||
if (resolvedPath) {
|
||||
resolvedPath = resolvedPath.replaceAll("\\", "/");
|
||||
console.log("\t", importPath, resolvedPath);
|
||||
return `${action} ${imported} from "${resolvedPath}";`;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
||||
if (code !== newCode) {
|
||||
fs.writeFileSync(outFilePath, newCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Then, use it with a simple async for loop
|
||||
async function run(srcDir, options = defaultOptions) {
|
||||
const { sourceFileFilter = defaultSourceFileFilter } = options;
|
||||
|
||||
for await (const entry of walk(srcDir)) {
|
||||
if (sourceFileFilter(entry)) {
|
||||
console.log(entry);
|
||||
replace(entry, entry, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultSourceFileFilter = function (sourceFilePath) {
|
||||
return /\.(js|ts)$/.test(sourceFilePath) && !/node_modules/.test(sourceFilePath);
|
||||
};
|
||||
|
||||
const defaultModuleFilter = function (importedModule) {
|
||||
return !path.isAbsolute(importedModule) && !importedModule.startsWith("@") && !importedModule.endsWith(".js");
|
||||
};
|
||||
|
||||
const defaultOptions = {
|
||||
sourceFileFilter: defaultSourceFileFilter,
|
||||
moduleFilter: defaultModuleFilter,
|
||||
};
|
||||
|
||||
// Switch this to test on one file or directly run on a directory.
|
||||
const DEBUG = false;
|
||||
|
||||
if (DEBUG) {
|
||||
replace("./src/index.ts", "./out.ts", defaultOptions);
|
||||
} else {
|
||||
await run("./src/", defaultOptions);
|
||||
}
|
||||
@@ -2,17 +2,13 @@
|
||||
"name": "@certd/plugin-cert",
|
||||
"private": false,
|
||||
"version": "1.21.0",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"publishConfig": {
|
||||
"main": "./dist/bundle.js",
|
||||
"module": "./dist/bundle.mjs",
|
||||
"types": "./dist/d/index.d.ts"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "rollup -c",
|
||||
"build": "tsc --skipLibCheck",
|
||||
"build3": "rollup -c",
|
||||
"build2": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
@@ -33,7 +29,6 @@
|
||||
"@rollup/plugin-terser": "^0.4.3",
|
||||
"@rollup/plugin-typescript": "^11.0.0",
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/lodash": "^4.14.186",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node-forge": "^1.3.0",
|
||||
"@types/psl": "^1.1.3",
|
||||
@@ -46,7 +41,7 @@
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash-es": "^4.17.21",
|
||||
"log4js": "^6.7.1",
|
||||
"mocha": "^10.1.0",
|
||||
"prettier": "^2.8.8",
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
],
|
||||
external: [
|
||||
"vue",
|
||||
"lodash",
|
||||
"lodash-es",
|
||||
"dayjs",
|
||||
"@certd/acme-client",
|
||||
"@certd/pipeline",
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./eab-access";
|
||||
export * from "./eab-access.js";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CreateRecordOptions, DnsProviderContext, IDnsProvider, RemoveRecordOptions } from "./api";
|
||||
import { CreateRecordOptions, DnsProviderContext, IDnsProvider, RemoveRecordOptions } from "./api.js";
|
||||
|
||||
export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
||||
ctx!: DnsProviderContext;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { dnsProviderRegistry } from "./registry";
|
||||
import { DnsProviderDefine } from "./api";
|
||||
import { dnsProviderRegistry } from "./registry.js";
|
||||
import { DnsProviderDefine } from "./api.js";
|
||||
import { Decorator, AUTOWIRE_KEY } from "@certd/pipeline";
|
||||
import _ from "lodash";
|
||||
import _ from "lodash-es";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const DNS_PROVIDER_CLASS_KEY = "pipeline:dns-provider";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./api";
|
||||
export * from "./registry";
|
||||
export * from "./decorator";
|
||||
export * from "./base";
|
||||
export * from "./api.js";
|
||||
export * from "./registry.js";
|
||||
export * from "./decorator.js";
|
||||
export * from "./base.js";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./plugin";
|
||||
export * from "./dns-provider";
|
||||
export * from "./access";
|
||||
export * from "./plugin/index.js";
|
||||
export * from "./dns-provider/index.js";
|
||||
export * from "./access/index.js";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// @ts-ignore
|
||||
import * as acme from "@certd/acme-client";
|
||||
import _ from "lodash";
|
||||
import _ from "lodash-es";
|
||||
import { Challenge } from "@certd/acme-client/types/rfc8555";
|
||||
import { Logger } from "log4js";
|
||||
import { IContext } from "@certd/pipeline";
|
||||
import { IDnsProvider } from "../../dns-provider";
|
||||
import { IDnsProvider } from "../../dns-provider/index.js";
|
||||
import psl from "psl";
|
||||
import { ClientExternalAccountBindingOptions } from "@certd/acme-client";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CertInfo } from "./acme";
|
||||
import { CertInfo } from "./acme.js";
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import forge from "node-forge";
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { AbstractTaskPlugin, Decorator, HttpClient, IAccessService, IContext, IsTaskPlugin, RunStrategy, Step, TaskInput, TaskOutput } from "@certd/pipeline";
|
||||
import dayjs from "dayjs";
|
||||
import { AcmeService, CertInfo, SSLProvider } from "./acme";
|
||||
import _ from "lodash";
|
||||
import { AcmeService } from "./acme.js";
|
||||
import type { CertInfo, SSLProvider } from "./acme.js";
|
||||
import _ from "lodash-es";
|
||||
import { Logger } from "log4js";
|
||||
import { DnsProviderContext, DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider";
|
||||
import { CertReader } from "./cert-reader";
|
||||
import { DnsProviderContext, DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider/index.js";
|
||||
import { CertReader } from "./cert-reader.js";
|
||||
import JSZip from "jszip";
|
||||
|
||||
export { CertReader };
|
||||
@@ -171,11 +172,11 @@ export class CertApplyPlugin extends AbstractTaskPlugin {
|
||||
async execute(): Promise<void> {
|
||||
const oldCert = await this.condition();
|
||||
if (oldCert != null) {
|
||||
return await this.output(oldCert);
|
||||
return await this.output(oldCert, false);
|
||||
}
|
||||
const cert = await this.doCertApply();
|
||||
if (cert != null) {
|
||||
await this.output(cert);
|
||||
await this.output(cert, true);
|
||||
//清空后续任务的状态,让后续任务能够重新执行
|
||||
this.clearLastStatus();
|
||||
} else {
|
||||
@@ -183,12 +184,18 @@ export class CertApplyPlugin extends AbstractTaskPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
async output(certReader: CertReader) {
|
||||
async output(certReader: CertReader, isNew: boolean) {
|
||||
const cert: CertInfo = certReader.toCertInfo();
|
||||
this.cert = cert;
|
||||
// this.logger.info(JSON.stringify(certReader.detail));
|
||||
const applyTime = dayjs(certReader.detail.validity.notBefore).format("YYYYMMDD_HHmmss");
|
||||
await this.zipCert(cert, applyTime);
|
||||
|
||||
if (isNew) {
|
||||
const applyTime = dayjs(certReader.detail.validity.notBefore).format("YYYYMMDD_HHmmss");
|
||||
await this.zipCert(cert, applyTime);
|
||||
} else {
|
||||
this.extendsFiles();
|
||||
}
|
||||
// thi
|
||||
// s.logger.info(JSON.stringify(certReader.detail));
|
||||
}
|
||||
|
||||
async zipCert(cert: CertInfo, applyTime: string) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./cert-plugin";
|
||||
export * from "./cert-plugin/index.js";
|
||||
|
||||
@@ -1,18 +1,41 @@
|
||||
{
|
||||
"compileOnSave": true,
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"inlineSourceMap":true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"stripInternal": true,
|
||||
"skipLibCheck": true,
|
||||
"experimentalDecorators": true
|
||||
"pretty": true,
|
||||
"declaration": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"typeRoots": [ "./typings", "./node_modules/@types"],
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"composite": true,
|
||||
"useDefineForClassFields": true,
|
||||
"strict": false,
|
||||
// "sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": false,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue","test/**/*.ts"],
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*.json"
|
||||
],
|
||||
"exclude": [
|
||||
"*.js",
|
||||
"*.ts",
|
||||
"dist",
|
||||
"node_modules",
|
||||
"test"
|
||||
],
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export default defineConfig({
|
||||
],
|
||||
external: [
|
||||
"vue",
|
||||
"lodash",
|
||||
"lodash-es",
|
||||
"dayjs",
|
||||
"@certd/acme-client",
|
||||
"@certd/pipeline",
|
||||
|
||||
Reference in New Issue
Block a user