mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 15:39:24 +08:00
feat: add defaut txt match
This commit is contained in:
parent
4c46c71ae3
commit
a93eecbbb8
@ -377,12 +377,12 @@ export async function buildProPluginServer(cwd: string, userConfig: UserConfig,
|
|||||||
'.json': 'copy',
|
'.json': 'copy',
|
||||||
},
|
},
|
||||||
esbuildPlugins: [pluginEsbuildCommercialInject],
|
esbuildPlugins: [pluginEsbuildCommercialInject],
|
||||||
onSuccess: async () => {
|
// onSuccess: async () => {
|
||||||
const serverFiles = [path.join(cwd, target_dir, 'server', 'index.js')];
|
// const serverFiles = [path.join(cwd, target_dir, 'server', 'index.js')];
|
||||||
serverFiles.forEach((file) => {
|
// serverFiles.forEach((file) => {
|
||||||
obfuscate(file);
|
// obfuscate(file);
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
fs.removeSync(tsconfig.path);
|
fs.removeSync(tsconfig.path);
|
||||||
|
@ -12,20 +12,31 @@ import fs from 'node:fs'
|
|||||||
const pluginEsbuildCommercialInject = {
|
const pluginEsbuildCommercialInject = {
|
||||||
name: 'plugin-esbuild-commercial-inject',
|
name: 'plugin-esbuild-commercial-inject',
|
||||||
setup(build) {
|
setup(build) {
|
||||||
|
build.onLoad({ filter: /src\/server\/index\.ts$/ }, async (args) => {
|
||||||
build.onLoad({ filter: /src\/index\.ts$/ }, async (args) => {
|
|
||||||
let source = fs.readFileSync(args.path, 'utf8');
|
let source = fs.readFileSync(args.path, 'utf8');
|
||||||
const regex = /export\s*\{\s*default\s*\}\s*from\s*(?:'([^']*)'|"([^"]*)");?/; // match: export { default } from './plugin';
|
const regex = /export\s*\{\s*default\s*\}\s*from\s*(?:'([^']*)'|"([^"]*)");?/; // match: export { default } from './plugin';
|
||||||
|
const regex2 = /export\s+default\s+([a-zA-Z_0-9]+)\s*;?/; // match: export default xxx;
|
||||||
const match = source.match(regex);
|
const match = source.match(regex);
|
||||||
|
const match2 = source.match(regex2);
|
||||||
if (match) {
|
if (match) {
|
||||||
source = source.replace(regex, ``);
|
source = source.replace(regex, ``);
|
||||||
const moduleName = match[1] || match[2];
|
const moduleName = match[1] || match[2];
|
||||||
source =
|
source =
|
||||||
`
|
`
|
||||||
import { withCommercial } from '@nocobase/plugin-commercial/server';
|
import { withCommercial } from '@nocobase/plugin-commercial/server';
|
||||||
import _plugin from '${moduleName}';
|
import _plugin from '${moduleName}';
|
||||||
export default withCommercial(_plugin);
|
export default withCommercial(_plugin);
|
||||||
${source}
|
${source}
|
||||||
|
`;
|
||||||
|
console.log(`Insert commercial server code success`);
|
||||||
|
} else if (match2) {
|
||||||
|
source = source.replace(regex2, ``);
|
||||||
|
const moduleName = match2[1] || match2[2];
|
||||||
|
source =
|
||||||
|
`
|
||||||
|
import { withCommercial } from '@nocobase/plugin-commercial/server';
|
||||||
|
${source}
|
||||||
|
export default withCommercial(${moduleName});
|
||||||
`;
|
`;
|
||||||
console.log(`Insert commercial server code success`);
|
console.log(`Insert commercial server code success`);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user