Skip to content

Commit

Permalink
build: commonjs to esmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Apr 23, 2024
1 parent 19b9664 commit 60655f4
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['@webank/eslint-config-ts/vue'],

parserOptions: {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Generate Release Notes
run: |
./.github/workflows/release-notes.mjs ${{ env.RELEASE_VERSION }}
./.github/workflows/release-notes.js ${{ env.RELEASE_VERSION }}
cat notes-${{ env.RELEASE_VERSION }}.md
- name: Create Release for Tag
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
semi: true,
trailingComma: 'all',
singleQuote: true,
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// for jest
module.exports = {
export default {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
plugins: ['@vue/babel-plugin-jsx'],
};
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
export default { extends: ['@commitlint/config-conventional'] };
8 changes: 5 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import path from 'node:path';
import process from 'node:process';

import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig } from 'vitepress';
import { withPwa } from '@vite-pwa/vitepress';
import { getProjectRootDir } from '../../scripts/utils.mjs';
import { genComponentDocWatch } from '../../scripts/genComponentDoc.mjs';
import { getProjectRootDir } from '../../scripts/utils.js';
import { genComponentDocWatch } from '../../scripts/genComponentDoc.js';
import { navbar, sidebar } from './configs/index';
import { pwa } from './pwa';

Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/configs/navbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type DefaultTheme } from 'vitepress';
import { getPackageJsonVersion } from '../../../../scripts/utils.mjs';
import { getPackageJsonVersion } from '../../../../scripts/utils.js';

const currentVersion = getPackageJsonVersion();

Expand Down
3 changes: 0 additions & 3 deletions docs/package.json

This file was deleted.

File renamed without changes.
File renamed without changes.
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"name": "@fesjs/fes-design",
"type": "module",
"version": "0.8.44",
"description": "fes-design for PC",
"main": "dist/fes-design.js",
"module": "es/index.js",
"scripts": {
"prepare": "husky install",
"docs:dev": "node scripts/genComponentDoc.mjs && vitepress dev docs",
"docs:build": "NODE_ENV=production node scripts/genComponentDoc.mjs && vitepress build docs",
"docs:dev": "node scripts/genComponentDoc.js && vitepress dev docs",
"docs:build": "NODE_ENV=production node scripts/genComponentDoc.js && vitepress build docs",
"docs:preview": "vitepress preview docs --port 8999",
"test": "jest",
"test:watch": "jest --watch",
"gen:component": "node scripts/createComponent.mjs",
"gen:icon": "node scripts/genIcons.mjs",
"build:version": "node scripts/genVersion.mjs",
"build:esm": "node scripts/build-esm.mjs",
"build:esm-browser": "node scripts/build-browser.mjs",
"build:umd": "node scripts/build-umd.mjs",
"build:style": "node scripts/build-style.mjs",
"build:type": "node scripts/build-types.mjs",
"build:icon": "node scripts/build-icon.mjs",
"gen:component": "node scripts/createComponent.js",
"gen:icon": "node scripts/genIcons.js",
"build:version": "node scripts/genVersion.js",
"build:esm": "node scripts/build-esm.js",
"build:esm-browser": "node scripts/build-browser.js",
"build:umd": "node scripts/build-umd.js",
"build:style": "node scripts/build-style.js",
"build:type": "node scripts/build-types.js",
"build:icon": "node scripts/build-icon.js",
"build": "npm run build:version && npm run build:esm && npm run build:type && cp -rf es/icon . && npm run build:esm-browser && npm run build:umd && npm run build:style && npm run build:icon",
"release": "node scripts/release.mjs",
"release": "node scripts/release.js",
"lint-staged": "lint-staged --allow-empty",
"commitlint": "commitlint --config commitlint.config.js -e -V",
"lint:script": "eslint --ext .js,.ts,.vue,.tsx ./components --fix",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-browser.mjs → scripts/build-browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import path from 'node:path';
import fse from 'fs-extra';
import { rollup } from 'rollup';

import { getRollupConfig, OUTPUT_DIR } from './build-shard.mjs';
import { getRollupConfig, OUTPUT_DIR } from './build-shard.js';

fse.mkdirsSync(OUTPUT_DIR);

Expand Down
10 changes: 5 additions & 5 deletions scripts/build-esm.mjs → scripts/build-esm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import fse from 'fs-extra';
import compiler from './esm-jsc.mjs';
import { compilerStyleDir } from './compilerCss.mjs';
import { getProjectRootDir } from './utils.mjs';
import compiler from './esm-jsc.js';
import { compilerStyleDir } from './compilerCss.js';
import { getProjectRootDir } from './utils.js';

const rootDir = getProjectRootDir();
const SOURCE = path.join(rootDir, './components');
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-icon.mjs → scripts/build-icon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import path from 'node:path';
import fse from 'fs-extra';
import { rollup } from 'rollup';
import { getProjectRootDir } from './utils.mjs';
import { getProjectRootDir } from './utils.js';

import { getRollupConfig, OUTPUT_DIR } from './build-shard.mjs';
import { getRollupConfig, OUTPUT_DIR } from './build-shard.js';

const rootDir = getProjectRootDir();
const SOURCE_PATH = path.join(rootDir, './components/icon/index.ts');
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-shard.mjs → scripts/build-shard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path';
import path from 'node:path';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import vuePlugin from 'rollup-plugin-vue';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import postcss from 'rollup-plugin-postcss';
import { getProjectRootDir } from './utils.mjs';
import { getProjectRootDir } from './utils.js';

const rootDir = getProjectRootDir();
const SOURCE_PATH = path.join(rootDir, './components/index.ts');
Expand Down
8 changes: 4 additions & 4 deletions scripts/build-style.mjs → scripts/build-style.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';
import path from 'node:path';
import csso from 'csso';
import fse from 'fs-extra';

import { compilerCss } from './compilerCss.mjs';
import { OUTPUT_DIR } from './build-shard.mjs';
import { getProjectRootDir } from './utils.mjs';
import { compilerCss } from './compilerCss.js';
import { OUTPUT_DIR } from './build-shard.js';
import { getProjectRootDir } from './utils.js';

const rootDir = getProjectRootDir();
const STYLE_SOURCE = path.join(rootDir, './components/_style.ts');
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-types.mjs → scripts/build-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import fs from 'fs';
import fs from 'node:fs';
import path from 'node:path';
import glob from 'fast-glob';
import { Project } from 'ts-morph';
import { parse, compileScript } from 'vue/compiler-sfc';
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-umd.mjs → scripts/build-umd.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';
import path from 'node:path';
import fse from 'fs-extra';
import { rollup } from 'rollup';
import replace from '@rollup/plugin-replace';
import { minify } from 'terser';

import { getRollupConfig, OUTPUT_DIR } from './build-shard.mjs';
import { getRollupConfig, OUTPUT_DIR } from './build-shard.js';

fse.mkdirsSync(OUTPUT_DIR);

Expand Down
2 changes: 1 addition & 1 deletion scripts/compilerCss.mjs → scripts/compilerCss.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { rollup } from 'rollup';
import fse from 'fs-extra';
import { nodeResolve } from '@rollup/plugin-node-resolve';
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions scripts/createComponent.mjs → scripts/createComponent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// 使用方式: npm run gen:component component-name
import { join } from 'path';
import { join } from 'node:path';
import process from 'node:process';
import { pathExistsSync, outputFileSync, copySync } from 'fs-extra';
import { INDEX_TPL } from './constants.mjs';
import { getProjectRootDir } from './utils.mjs';
import { INDEX_TPL } from './constants.js';
import { getProjectRootDir } from './utils.js';

function hyphenate(str) {
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase();
Expand Down
6 changes: 3 additions & 3 deletions scripts/esm-jsc.mjs → scripts/esm-jsc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path';
import path from 'node:path';
import { rollup } from 'rollup';
import babel from '@rollup/plugin-babel';
import vuePlugin from 'rollup-plugin-vue';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import pluginRenameExtensions from '@betit/rollup-plugin-rename-extensions';

import { extensions } from './build-shard.mjs';
import injectCss from './injectcss.mjs';
import { extensions } from './build-shard.js';
import injectCss from './injectcss.js';

const renameExtensions =
pluginRenameExtensions.default || pluginRenameExtensions;
Expand Down
6 changes: 3 additions & 3 deletions scripts/genComponentDoc.mjs → scripts/genComponentDoc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import path from 'node:path';
import fse from 'fs-extra';
import { getHighlighter } from 'shiki';
import cheapWatch from 'cheap-watch';
import { getProjectRootDir } from './utils.mjs';
import { SCRIPT_TEMPLATE, DEMO_ENTRY_FILE } from './constants.mjs';
import { getProjectRootDir } from './utils.js';
import { SCRIPT_TEMPLATE, DEMO_ENTRY_FILE } from './constants.js';

const rootDir = getProjectRootDir();
const CODE_PATH = path.join(
Expand Down
10 changes: 5 additions & 5 deletions scripts/genIcons.mjs → scripts/genIcons.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join, basename } from 'path';
import { readdirSync, writeFileSync } from 'fs';
import { readdirSync, writeFileSync } from 'node:fs';
import { basename, join } from 'node:path';

import optimizeSvg from './optimizeSvg.mjs';
import { getProjectRootDir, stringToCamelCase } from './utils.mjs';
import { SVG_COMPONENT_TMPLATE } from './constants.mjs';
import optimizeSvg from './optimizeSvg.js';
import { getProjectRootDir, stringToCamelCase } from './utils.js';
import { SVG_COMPONENT_TMPLATE } from './constants.js';

const rootDir = getProjectRootDir();
const outputPath = join(rootDir, './components/icon');
Expand Down
6 changes: 3 additions & 3 deletions scripts/genVersion.mjs → scripts/genVersion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import { getProjectRootDir, getPackageJsonVersion } from './utils.mjs';
import fs from 'node:fs';
import path from 'node:path';
import { getProjectRootDir, getPackageJsonVersion } from './utils.js';

const rootDir = getProjectRootDir();
const currentVersion = getPackageJsonVersion();
Expand Down
4 changes: 2 additions & 2 deletions scripts/injectcss.mjs → scripts/injectcss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import fs from 'fs';
import fs from 'node:fs';
import path from 'node:path';

function injectCss() {
return {
Expand Down
4 changes: 2 additions & 2 deletions scripts/optimizeSvg.mjs → scripts/optimizeSvg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extname, basename } from 'path';
import { statSync, readFileSync } from 'fs';
import { readFileSync, statSync } from 'node:fs';
import { basename, extname } from 'node:path';

import { optimize } from 'svgo';

Expand Down
8 changes: 5 additions & 3 deletions scripts/release.mjs → scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';

import minimist from 'minimist';
import chalk from 'chalk';
import semver from 'semver';
Expand All @@ -9,7 +11,7 @@ import {
getProjectRootDir,
getPackageJsonVersion,
loadJsonFile,
} from './utils.mjs';
} from './utils.js';
const prompt = enquirer.prompt;

const args = minimist(process.argv.slice(2));
Expand Down
5 changes: 3 additions & 2 deletions scripts/utils.mjs → scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';

export function stringToCamelCase(str) {
const re = /-(\w)/g;
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"docs/.vitepress/**/*.tsx",
"docs/.vitepress/**/*.vue",
/* 与 tsconfig.json 保持一致 End */
"scripts/**/*.mjs",
"scripts/**/*.js",
"./.eslintrc.js",
"./.prettierrc.js",
"./babel.config.js",
"./commitlint.config.js",
"./jest.config.js",
"./jest.setup.js"
"./jest.config.cjs",
"./jest.setup.cjs"
],
"exclude": [
"docs/.vitepress/cache/**/*",
Expand Down

0 comments on commit 60655f4

Please sign in to comment.