Skip to content

Commit 6a2e439

Browse files
author
chengyu.chengyulia
committed
feat: support plugins folder
1 parent b39284b commit 6a2e439

6 files changed

Lines changed: 30 additions & 15 deletions

File tree

src/built-in-plugins/white-files/plugin/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
srcPath,
1313
utilPath,
1414
packagesPath,
15+
pluginsPath,
1516
expandPath,
1617
typingsPath,
1718
} from '../../../utils/structor-config';
@@ -52,6 +53,7 @@ pri.project.whiteFileRules.add(file => {
5253
.concat(transferToAllAbsolutePaths(expandPath.dir))
5354
.concat(transferToAllAbsolutePaths(`src${path.sep}layouts`))
5455
.concat(path.join(pri.projectRootPath, packagesPath.dir))
56+
.concat(path.join(pri.projectRootPath, pluginsPath.dir))
5557
.some(absoluteFilePath => {
5658
return path.format(file).startsWith(absoluteFilePath);
5759
});

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const CONFIG_FILE = 'priconfig.json';
22
export const PRI_PACKAGE_NAME = 'pri';
33
export const PACKAGES_NAME = 'packages';
4+
export const PLUGINS_NAME = 'plugins';
45
export const README_FILE = 'README.md';

src/utils/define.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export class GlobalState {
126126
* packages info
127127
*/
128128
public packages: PackageInfo[] = [];
129+
130+
/**
131+
* plugins info
132+
*/
133+
public plugins: PackageInfo[] = [];
129134
}
130135

131136
/**

src/utils/global-state.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import * as yargs from 'yargs';
1010
import * as inquirer from 'inquirer';
1111
import * as pkg from '../../package.json';
12-
import { CONFIG_FILE, PACKAGES_NAME } from './constants';
12+
import { CONFIG_FILE, PACKAGES_NAME, PLUGINS_NAME } from './constants';
1313
import { logFatal } from './log';
1414
import { PackageJson, GlobalState, ProjectConfig } from './define';
1515

@@ -72,13 +72,13 @@ function getPriConfig(rootPath: string) {
7272
return fs.readJsonSync(configFilePath, { throws: false }) || {};
7373
}
7474

75-
function collectPackages(packageRootPath: string, deep = 0) {
75+
function collectPackages(packageRootPath: string, packageDir = PACKAGES_NAME, deep = 0) {
7676
// Only support two level packages
7777
if (deep >= 2) {
7878
return;
7979
}
8080

81-
const currentPackagesPath = path.join(packageRootPath, PACKAGES_NAME);
81+
const currentPackagesPath = path.join(packageRootPath, packageDir);
8282

8383
if (fs.existsSync(currentPackagesPath)) {
8484
fs.readdirSync(currentPackagesPath)
@@ -90,7 +90,7 @@ function collectPackages(packageRootPath: string, deep = 0) {
9090
return true;
9191
})
9292
.forEach(folderName => {
93-
const packagePath = path.join(packageRootPath, PACKAGES_NAME, folderName);
93+
const packagePath = path.join(packageRootPath, packageDir, folderName);
9494
const packageJson: PackageJson = fs.readJSONSync(path.join(packagePath, 'package.json'), { throws: false });
9595

9696
const config = fs.readJsonSync(path.join(packagePath, CONFIG_FILE), { throws: false }) || {};
@@ -102,16 +102,23 @@ function collectPackages(packageRootPath: string, deep = 0) {
102102
config,
103103
};
104104

105-
globalState.packages.push(eachPackage);
105+
if (packageDir === PLUGINS_NAME) {
106+
globalState.plugins.push(eachPackage);
107+
} else {
108+
globalState.packages.push(eachPackage);
109+
}
106110

107111
// find nested packages
108-
collectPackages(eachPackage.rootPath, deep + 1);
112+
if (packageDir !== PLUGINS_NAME) {
113+
collectPackages(eachPackage.rootPath, packageDir, deep + 1);
114+
}
109115
});
110116
}
111117
}
112118

113119
async function initPackages(projectRootPath: string, preSelectPackage: string) {
114120
collectPackages(projectRootPath);
121+
collectPackages(projectRootPath, PLUGINS_NAME);
115122

116123
if (globalState.packages.length > 0) {
117124
if (!preSelectPackage) {

src/utils/plugins.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,13 @@ async function getPriPlugins(pluginRootPath: string, packageJsonPaths: string[])
174174
return;
175175
}
176176

177-
for (const eachPackage of globalState.packages) {
178-
if (eachPackage.config?.type === 'plugin') {
179-
const distPath = path.join(globalState.projectRootPath, tempPath.dir, 'plugins', eachPackage.name);
180-
await spinner(`Build plugin ${eachPackage.name}`, async () => {
181-
await fs.remove(distPath);
182-
await buildPluginSource(eachPackage.rootPath, distPath);
183-
});
184-
addPluginFromEntry(distPath);
185-
}
177+
for (const eachPackage of globalState.plugins) {
178+
const distPath = path.join(globalState.projectRootPath, tempPath.dir, 'plugins', eachPackage.name);
179+
await spinner(`Build plugin ${eachPackage.name}`, async () => {
180+
await fs.remove(distPath);
181+
await buildPluginSource(eachPackage.rootPath, distPath);
182+
});
183+
addPluginFromEntry(distPath);
186184
}
187185

188186
const deps = packageJsonPaths.map(packageJsonPath => {

src/utils/structor-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const assetsPath = { dir: 'assets' };
2121

2222
export const packagesPath = { dir: 'packages' };
2323

24+
export const pluginsPath = { dir: 'plugins' };
25+
2426
export const declarationPath = { dir: 'declaration' };
2527

2628
/**

0 commit comments

Comments
 (0)