Skip to content

Commit caf27b3

Browse files
author
linfeng
committed
feat: support material component
1 parent 8c788ad commit caf27b3

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

package.json

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

src/built-in-plugins/command-publish/plugin/run-publish.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,12 @@ async function moveSourceFilesToTempFolderAndPublish(
326326

327327
await fs.remove(tempRoot);
328328

329-
await fs.copy(path.join(pri.projectRootPath, targetConfig.distDir), path.join(tempRoot, targetConfig.distDir));
329+
if (pri.sourceConfig.materialComponent) {
330+
await fs.copy(path.join(pri.sourceRoot, 'es'), path.join(tempRoot, 'es'));
331+
await fs.copy(path.join(pri.sourceRoot, 'lib'), path.join(tempRoot, 'lib'));
332+
} else {
333+
await fs.copy(path.join(pri.projectRootPath, targetConfig.distDir), path.join(tempRoot, targetConfig.distDir));
334+
}
330335
await copyDeclaration(sourceType, publishTempName);
331336
await fs.copy(path.join(targetRoot, 'package.json'), path.join(tempRoot, 'package.json'));
332337

@@ -430,8 +435,13 @@ async function addMissingDeps(
430435
}
431436

432437
if (sourceType !== 'root') {
433-
_.set(newPackageJson, 'main', `${pri.projectConfig.distDir}/main`);
434-
_.set(newPackageJson, 'module', `${pri.projectConfig.distDir}/module`);
438+
if (pri.sourceConfig.materialComponent) {
439+
_.set(newPackageJson, 'main', `lib`);
440+
_.set(newPackageJson, 'module', `es`);
441+
} else {
442+
_.set(newPackageJson, 'main', `${pri.projectConfig.distDir}/main`);
443+
_.set(newPackageJson, 'module', `${pri.projectConfig.distDir}/module`);
444+
}
435445
_.set(newPackageJson, 'types', 'declaration/index.d.ts');
436446
}
437447

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

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function ensureEntryFile() {
2222
return prettier.format(
2323
`
2424
import * as React from 'react'
25+
2526
export default () => {
2627
return (
2728
<div>My Component</div>

src/utils/define.ts

+5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ export class ProjectConfig {
267267
* Enable ensure files
268268
*/
269269
public ensureFiles = true;
270+
271+
/**
272+
* is material component
273+
*/
274+
public materialComponent = false;
270275
}
271276

272277
export type SetPipe = (pipeName: string, callback: PipeCallback) => void;

src/utils/ts-plus-babel.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ function importRename(packageAbsoluteToRelative = false) {
115115
export const tsPlusBabel = async (watch = false, wholeProject = false, packageInfo: PackageInfo = null) => {
116116
const packagePath = packageInfo ? packageInfo.name : '';
117117
const rootDistPath = path.join(globalState.projectRootPath, pri.sourceConfig.distDir, packagePath);
118-
const mainDistPath = path.join(rootDistPath, 'main');
119-
const moduleDistPath = path.join(rootDistPath, 'module');
118+
let mainDistPath = path.join(rootDistPath, 'main');
119+
let moduleDistPath = path.join(rootDistPath, 'module');
120+
121+
if (pri.sourceConfig.materialComponent) {
122+
mainDistPath = path.join(globalState.sourceRoot, 'lib');
123+
moduleDistPath = path.join(globalState.sourceRoot, 'es');
124+
}
120125

121126
const sourcePath = packageInfo ? packageInfo.rootPath : null;
122127
const sourceType = packageInfo ? packageInfo.name : null;

0 commit comments

Comments
 (0)