Skip to content

Commit 5e0341a

Browse files
committed
fix: ensure plugin entry
1 parent 0aab564 commit 5e0341a

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {

src/built-in-plugins/ensure-project-files/plugin/ensure-plugin.ts

+46-28
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
22
import * as _ from 'lodash';
33
import * as path from 'path';
44
import * as pkg from '../../../../package.json';
5-
import { pluginEntry, pri } from '../../../node';
5+
import { pluginEntry, pri, srcPath } from '../../../node';
66
import { PRI_PACKAGE_NAME } from '../../../utils/constants';
77
import { globalState } from '../../../utils/global-state';
88
import { logSuccess, logText } from '../../../utils/log';
@@ -23,6 +23,26 @@ function ensureEntry() {
2323
}
2424

2525
const prettier = await import('prettier');
26+
27+
return prettier.format(`
28+
export const getPlugin = () => import('./plugin');
29+
30+
export const getConfig = () => ({
31+
name: 'pri-plugin-${pri.projectPackageJson.name}'
32+
});
33+
`);
34+
}
35+
});
36+
37+
pri.project.addProjectFiles({
38+
fileName: path.join(path.format(srcPath), 'plugin/index.ts'),
39+
pipeContent: async text => {
40+
if (text) {
41+
return text;
42+
}
43+
44+
const prettier = await import('prettier');
45+
2646
return prettier.format(
2747
`
2848
import * as path from "path"
@@ -34,38 +54,36 @@ function ensureEntry() {
3454
}
3555
}
3656
37-
export default async () => {
38-
pri.commands.registerCommand({
39-
name: ["deploy"],
40-
action: async () => {
41-
//
42-
}
43-
})
57+
pri.commands.registerCommand({
58+
name: ["deploy"],
59+
action: async () => {
60+
//
61+
}
62+
})
4463
45-
pri.commands.expandCommand({
46-
name: ["init"],
47-
beforeAction: async (...args: any[]) => {
48-
//
49-
}
50-
})
64+
pri.commands.expandCommand({
65+
name: ["init"],
66+
beforeAction: async (...args: any[]) => {
67+
//
68+
}
69+
})
5170
52-
pri.project.onAnalyseProject(files => {
53-
return { customPlugin: { hasComponents: judgeHasComponents(pri.projectRootPath, files) } } as IResult
54-
})
71+
pri.project.onAnalyseProject(files => {
72+
return { customPlugin: { hasComponents: judgeHasComponents(pri.projectRootPath, files) } } as IResult
73+
})
5574
56-
pri.project.onCreateEntry((analyseInfo: IResult, entry) => {
57-
if (!analyseInfo.customPlugin.hasComponents) {
58-
return
59-
}
75+
pri.project.onCreateEntry((analyseInfo: IResult, entry) => {
76+
if (!analyseInfo.customPlugin.hasComponents) {
77+
return
78+
}
6079
61-
entry.pipeAppHeader(header => {
62-
return \`
63-
\${header}
64-
import "src/components/xxx"
65-
\`
66-
})
80+
entry.pipeAppHeader(header => {
81+
return \`
82+
\${header}
83+
import "src/components/xxx"
84+
\`
6785
})
68-
}
86+
})
6987
7088
export function judgeHasComponents(projectRootPath: string, files: path.ParsedPath[]) {
7189
return files.some(file => {

src/utils/global-state-class.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export class GlobalState {
55
public projectConfig = new ProjectConfig();
66
public priPackageJson: any;
77
public projectPackageJson: {
8+
name?: string;
9+
version?: string;
810
pri?: {
911
/**
1012
* Project type

0 commit comments

Comments
 (0)