Skip to content

Commit

Permalink
👷 [cli/build] remove dts and only rename types index file to 'mts' an…
Browse files Browse the repository at this point in the history
…d 'cts'
  • Loading branch information
higuaifan committed Jul 28, 2023
1 parent ae3d536 commit c39efd0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
45 changes: 14 additions & 31 deletions cli/build/config/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const pRm = promisify(fs.rm);

const execSync = (cmd: string) => {
return new Promise((resolve, reject) => {
exec(cmd, (res,stdout) => {
exec(cmd, (res, stdout) => {
if (res) {
console.error(res);
reject(false);
Expand All @@ -43,30 +43,12 @@ const execSync = (cmd: string) => {
});
};

// tsc shuimo-ui.mjs --target esnext --declaration --emitDeclarationOnly --allowJs --skipLibCheck --declarationMap --exactOptionalPropertyTypes

const tscDeclaration = (path: string, fileName: string) => {

const filePath = `./config/output/dist/${path}/${fileName}`;
const outPath = `./config/output/dist/${path}`;

const args = [
`../../node_modules/.bin/vue-tsc ${filePath}`,
`--outDir ${outPath}`,
'--target esnext',
'--declaration',
'--emitDeclarationOnly',
'--allowJs',
'--skipLibCheck',
'--declarationMap',
];

return execSync(args.join(' '));
};
const init = (lib: 'vue' | 'react' | 'lit') => {
const cp = async (name: string, path: string = '', type: 'file' | 'document' = 'document') => {
return pCp(`../../${path}${name}`, `./config/output/${name}`, type === 'document' ? { recursive: true } : undefined);
};

const rm = (path: string, options?: RmOptions) => {
return pRm(path, options ?? { recursive: true, force: true });
};
Expand All @@ -88,13 +70,21 @@ const init = (lib: 'vue' | 'react' | 'lit') => {
};


return { cp, cpLib, rename, rmLib };
const renameTypes = async () => {
await Promise.all([
pCp(`./config/output/types/shuimo-ui.d.ts`, `./config/output/types/shuimo-ui.d.mts`),
pCp(`./config/output/types/shuimo-ui.d.ts`, `./config/output/types/shuimo-ui.d.cts`),
]);
return rm(`./config/output/types/shuimo-ui.d.ts`);
};

return { cp, cpLib, rename, rmLib, renameTypes };

};

const run = async () => {

const { cp, rename, cpLib, rmLib } = init('vue');
const { cp, rename, cpLib, rmLib, renameTypes } = init('vue');

const removeRes = await rmLib('dist');
const buildRes = await execSync('vite build -c ./config/vue.config.ts');
Expand All @@ -114,17 +104,10 @@ const run = async () => {
cpLib('types'),
cpLib('dist'),
cpLib('index.ts'),
cpLib('package.json', '', 'file')
cpLib('package.json', '', 'file'),
]);

if (res.every(r => r)) {
console.log('build success, now build ts declaration file');
Promise.all([
// tscDeclaration('es', 'shuimo-ui.mjs'),
tscDeclaration('cjs', 'shuimo-ui.cjs'),
tscDeclaration('umd', 'shuimo-ui.umd.js')
]);
}
await renameTypes()


// todo remove "@shuimo-design/types": "workspace:*"
Expand Down
8 changes: 2 additions & 6 deletions cli/build/config/vue.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ export default defineConfig({
plugins: [
lightningcss({ drafts: { nesting: true }, browserslist: '>= 0.25%' }),
vue({ include: [/\.vue$/], exclude: ['**/react/*.tsx'] }),
vueJSX(),
dts({
outDir: `${outputRoot}/es`,
staticImport: true,
entryRoot: path.resolve(__dirname, '../../../packages/vue')
})
vueJSX()
],
resolve: {
alias: {
Expand All @@ -53,6 +48,7 @@ export default defineConfig({
case 'umd':
return `umd/shuimo-ui.umd.js`;
}
return entryName;
},
entry: getPath('./index.ts')
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export {
MVirtualList
};

export function createMUI(options: MUIOption | undefined) {
export function createMUI(options: MUIOption | undefined = {}) {
return {
install: (app: App) => {
// todo support nuxt
Expand Down
6 changes: 3 additions & 3 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"test:update": "vitest -u",
"coverage": "vitest --coverage"
},
"types": "./dist/es/shuimo-ui.d.mts",
"types": "./types/shuimo-ui.d.mts",
"main": "./dist/umd/shuimo-ui.umd.js",
"module": "./dist/es/shuimo-ui.mjs",
"exports": {
".": {
"import": {
"types": "./dist/es/shuimo-ui.d.mts",
"types": "./types/shuimo-ui.d.mts",
"default": "./dist/es/shuimo-ui.mjs"
},
"require": {
"types": "./dist/cjs/shuimo-ui.d.cts",
"types": "./types/shuimo-ui.d.cts",
"default": "./dist/cjs/shuimo-ui.cjs"
}
},
Expand Down

0 comments on commit c39efd0

Please sign in to comment.