Skip to content

Commit

Permalink
Modify stdf file structure to reduce NPM volume
Browse files Browse the repository at this point in the history
  • Loading branch information
dufu1991 committed Aug 14, 2023
1 parent e2ea553 commit 318555c
Show file tree
Hide file tree
Showing 91 changed files with 187 additions and 94 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 89 additions & 0 deletions packages/stdf/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import Button from './button/Button.svelte';
import NavBar from './navBar/NavBar.svelte';
import Icon from './icon/Icon.svelte';
import Divider from './divider/Divider.svelte';
import Cell from './cell/Cell.svelte';
import CellGroup from './cell/CellGroup.svelte';
import Switch from './switch/Switch.svelte';
import Avatar from './avatar/Avatar.svelte';
import Tabs from './tabs/Tabs.svelte';
import Tab from './tabs/Tab.svelte';
import TabContent from './tabs/TabContent.svelte';
import TabBar from './tabBar/TabBar.svelte';
import Steps from './steps/Steps.svelte';
import IndexBar from './indexBar/IndexBar.svelte';
import Radio from './radio/Radio.svelte';
import RadioGroup from './radio/RadioGroup.svelte';
import Checkbox from './checkbox/Checkbox.svelte';
import CheckboxGroup from './checkbox/CheckboxGroup.svelte';
import Input from './input/Input.svelte';
import Grids from './grids/Grids.svelte';
import Grid from './grids/Grid.svelte';
import Swiper from './swiper/Swiper.svelte';
import Placeholder from './placeholder/Placeholder.svelte';
import Skeleton from './skeleton/Skeleton.svelte';
import Rate from './rate/Rate.svelte';
import Slider from './slider/Slider.svelte';
import Badge from './badge/Badge.svelte';
import NoticeBar from './noticeBar/NoticeBar.svelte';
import Progress from './progress/Progress.svelte';
import ProgressLoop from './progressLoop/ProgressLoop.svelte';
import Mask from './mask/Mask.svelte';
import Toast from './toast/Toast.svelte';
import Loading from './loading/Loading.svelte';
import Popup from './popup/Popup.svelte';
import BottomSheet from './bottomSheet/BottomSheet.svelte';
import Modal from './modal/Modal.svelte';
import Dialog from './dialog/Dialog.svelte';
import ActionSheet from './actionSheet/ActionSheet.svelte';
import Picker from './picker/Picker.svelte';
import AsyncPicker from './asyncPicker/AsyncPicker.svelte';
import TimePicker from './timePicker/TimePicker.svelte';
import Calendar from './calendar/Calendar.svelte';
import Pagination from './pagination/Pagination.svelte';

export {
Button,
NavBar,
Icon,
Divider,
Cell,
CellGroup,
Switch,
Avatar,
Tabs,
Tab,
TabContent,
TabBar,
Steps,
IndexBar,
Radio,
RadioGroup,
Checkbox,
CheckboxGroup,
Input,
Grids,
Grid,
Swiper,
Placeholder,
Skeleton,
Rate,
Slider,
Badge,
NoticeBar,
Progress,
ProgressLoop,
Toast,
Mask,
Loading,
Popup,
BottomSheet,
Modal,
Dialog,
ActionSheet,
Picker,
AsyncPicker,
TimePicker,
Calendar,
Pagination,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 0 additions & 89 deletions packages/stdf/index.js

This file was deleted.

9 changes: 6 additions & 3 deletions packages/stdf/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "stdf",
"version": "0.2.2",
"version": "0.2.3",
"description": "Mobile web component library based on Svelte and Tailwind",
"main": "index.js",
"main": "dist/components/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -22,5 +22,8 @@
"type": "git",
"url": "https://github.com/dufu1991/stdf"
},
"type": "module"
"type": "module",
"files": [
"dist/**"
]
}
92 changes: 92 additions & 0 deletions packages/stdf/script/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 1. 将 components 下所有文件复制到 dist/components 下
// 2. 将 lang 和 assets 下所有文件复制到 dist 下
// 3. 将 dist 下所有 svelte 和 js 文件中的注释和空行,合并为一行

import fs from 'node:fs';
import path from 'node:path';

// 创建 dist 目录
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist');
}

// 创建 dist/components 目录
if (!fs.existsSync('dist/components')) {
fs.mkdirSync('dist/components');
}

// 创建 dist/lang 目录
if (!fs.existsSync('dist/lang')) {
fs.mkdirSync('dist/lang');
}

// 创建 dist/assets 目录
if (!fs.existsSync('dist/assets')) {
fs.mkdirSync('dist/assets');
}

function copyDirRecursive(sourceDir, targetDir) {
// 创建目标文件夹
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}

// 读取源文件夹中的所有文件和子文件夹
const files = fs.readdirSync(sourceDir);

files.forEach(file => {
const sourcePath = path.join(sourceDir, file);
const targetPath = path.join(targetDir, file);

const stats = fs.statSync(sourcePath);

if (stats.isFile()) {
// 如果是文件,则直接复制
fs.copyFileSync(sourcePath, targetPath);
} else if (stats.isDirectory()) {
// 如果是文件夹,则递归复制
copyDirRecursive(sourcePath, targetPath);
}
});
}

// 复制 components 目录下的所有文件到 dist/components 目录下
copyDirRecursive('components', 'dist/components');

// 复制 lang 目录下的所有文件到 dist 目录下
copyDirRecursive('lang', 'dist/lang');

// 复制 assets 目录下的所有文件到 dist 目录下
copyDirRecursive('assets', 'dist/assets');

// 递归遍历目录下的所有 svelte 和 js 文件
function processFiles(dir) {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory()) {
// 如果是目录,则递归处理
processFiles(filePath);
} else if (file.endsWith('.svelte') || file.endsWith('.js')) {
// 处理 svelte 和 js 文件
let content = fs.readFileSync(filePath, 'utf8');

// 删除 /* ... */ 形式的注释
content = content.replace(/\/\*[\s\S]*?\*\//g, '');

// 删除 // 形式的注释
content = content.replace(/\/\/.*/g, '');

// 删除空行
content = content.replace(/^\s*[\r\n]/gm, '');

// 合并为一行,仅留一个空格
content = content.replace(/\s+/g, ' ');

fs.writeFileSync(filePath, content, 'utf8');
}
});
}

processFiles('dist');
1 change: 0 additions & 1 deletion packages/stdf/src/dialog/FAQ_en.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/stdf/src/icon/remixicon.symbol.svg

This file was deleted.

0 comments on commit 318555c

Please sign in to comment.