diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 76% rename from .eslintrc.js rename to .eslintrc.cjs index 4ec444e..700ffaf 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -10,6 +10,7 @@ module.exports = { // 'no-console': 'error' '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/ban-ts-comment': 'off' + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }] } }; diff --git a/.github/workflows/main-site-publish.yml b/.github/workflows/main-site-publish.yml new file mode 100644 index 0000000..ccc2f61 --- /dev/null +++ b/.github/workflows/main-site-publish.yml @@ -0,0 +1,30 @@ +name: main-site-publish +on: + push: + branches: + - main +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v6 + with: + node-version-file: .node-version + + - run: pnpm install + + - run: pnpm run site:preview + + - run: sleep 3s + + - uses: TDesignOteam/workflows/actions/setup-surge@main + with: + project: _site + domain: tdesign-starter-cli.surge.sh + token: ${{ secrets.TDESIGN_SURGE_TOKEN }} diff --git a/.github/workflows/pkg-pr-new.yml b/.github/workflows/pkg-pr-new.yml new file mode 100644 index 0000000..0351194 --- /dev/null +++ b/.github/workflows/pkg-pr-new.yml @@ -0,0 +1,27 @@ +name: pkg-pr-new +on: + push: + branches: [develop] + pull_request: + branches: [develop] + +jobs: + build: + if: ${{ github.repository == 'Tencent/tdesign-starter-cli' && !startsWith(github.head_ref, 'release/')}} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v6 + with: + node-version-file: .node-version + + - run: pnpm install + + - run: pnpm run build + + + - run: pnpm dlx pkg-pr-new publish --bin --compact --packageManager=pnpm,npm diff --git a/.github/workflows/preview-publish.yml b/.github/workflows/preview-publish.yml new file mode 100644 index 0000000..278ec79 --- /dev/null +++ b/.github/workflows/preview-publish.yml @@ -0,0 +1,15 @@ +# 文件名建议统一为 preview-publish +# 应用 preview.yml 的 demo +name: PREVIEW_PUBLISH + +on: + workflow_run: + workflows: ["MAIN_PULL_REQUEST"] + types: + - completed + +jobs: + call-preview: + uses: TDesignOteam/workflows/.github/workflows/reusable-pr-preview.yml@main + secrets: + TDESIGN_SURGE_TOKEN: ${{ secrets.TDESIGN_SURGE_TOKEN }} diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index a6dad24..0000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Build & deploy -on: - pull_request: - branches: - - develop -jobs: - build: - name: Build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: "20" - - uses: oven-sh/setup-bun@v2 - with: - bun-version: latest - - run: npm install pnpm -g && pnpm install && pnpm build - - run: bun scripts/deploy.ts - - run: sleep 3s - - run: | - npx surge --project ./dist --domain tdesign-starter-cli.surge.sh --token ${{ secrets.TDESIGN_SURGE_TOKEN }} - ls dist diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..20ae833 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,15 @@ +# 文件名建议统一为 pull-request.yml +# 应用 test-build.yml 的 demo + +name: MAIN_PULL_REQUEST + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + call-test-build: + uses: TDesignOteam/workflows/.github/workflows/reusable-unit-test.yml@main + with: + package-manager: pnpm + node-version-file: .node-version diff --git a/.github/workflows/tag-push.yml b/.github/workflows/tag-push.yml index 359679b..3ba2e08 100644 --- a/.github/workflows/tag-push.yml +++ b/.github/workflows/tag-push.yml @@ -7,8 +7,14 @@ on: create jobs: call-publish: - uses: Tencent/tdesign/.github/workflows/publish.yml@main + if: github.event.ref_type == 'tag' + uses: TDesignOteam/workflows/.github/workflows/reusable-publish-npm.yml@main secrets: TDESIGN_SURGE_TOKEN: ${{ secrets.TDESIGN_SURGE_TOKEN }} - TDESIGN_NPM_TOKEN: ${{ secrets.TDESIGN_NPM_TOKEN }} - PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} \ No newline at end of file + PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} + with: + package-manager: pnpm + node-version-file: .node-version + permissions: + contents: read + id-token: write diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..8fdd954 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +22 \ No newline at end of file diff --git a/package.json b/package.json index 9717da1..7dd5df6 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "tdesign-starter-cli", "version": "0.5.3", "description": "CLI tool for TDesign Starter project", + "packageManager": "pnpm@10.30.3", "type": "module", "main": "./src/main.ts", "lib": "./bin/index.js", @@ -11,13 +12,13 @@ "typings": "./src/types/index.d.ts", "scripts": { "watch": "rollup -w -c", - "test": "npm run dev", "dev": "node ./bin/index.js", "prebuild": "rimraf bin/", "build": "rollup -c ", "lint": "eslint 'src/**/*.{js,ts}'", "site": "echo 'no need to build site'", - "site:preview": "echo 'no need to run site preview'" + "site:preview": "npm run build && tsx scripts/deploy.ts", + "test": "echo \"No tests yet\" && exit 0" }, "repository": { "type": "git", @@ -46,7 +47,8 @@ "eslint": "^8.56.0", "prettier": "^3.2.5", "rollup": "^4.29.1", - "rollup-plugin-copy": "3.5.0" + "rollup-plugin-copy": "3.5.0", + "tsx": "^4.21.0" }, "dependencies": { "@babel/plugin-transform-typescript": "^7.24.4", diff --git a/scripts/deploy.ts b/scripts/deploy.ts index d8100e1..904d489 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -103,7 +103,7 @@ const configFilesReg = async (configReg: RegExp, reg: RegExp, getNewConfigFile: // webpack-react 使用 build 目录 const outputDir = template === 'template-webpack-react' ? 'build' : 'dist'; const distFilePath = path.join(cwd, template, outputDir); - const newDistFilePath = path.join(cwd, 'dist', template); + const newDistFilePath = path.join(cwd, '_site', template); console.log(`准备拷贝 ${outputDir}: ${distFilePath} -> ${newDistFilePath}`); if (!fs.existsSync(distFilePath)) { @@ -147,7 +147,7 @@ const TEMPLATES: TemplateConfig[] = [ const preview = async () => { try { // 创建 dist 目录 - mkdirSync('dist', { recursive: true }); + mkdirSync('_site', { recursive: true }); await initTemplates(TEMPLATES); diff --git a/src/core/CoreGitDownloader.ts b/src/core/CoreGitDownloader.ts index 36d2d4f..08f920a 100644 --- a/src/core/CoreGitDownloader.ts +++ b/src/core/CoreGitDownloader.ts @@ -4,7 +4,6 @@ import download from 'download-git-repo'; import ora from 'ora'; import chalk from 'chalk'; import path from 'path'; -import { SupportedTemplate } from '../types/type'; import { CoreOptionsFilterForVue2, IOptionsFilter } from './core-options/CoreOptionsFilterForVue2'; import { CoreOptionsFilterForVue3 } from './core-options/CoreOptionsFilterForVue3'; import { CoreOptionsFilterForReact } from './core-options/CoreOptionsFilterForReact'; diff --git a/src/core/CoreIndex.ts b/src/core/CoreIndex.ts index 027a91f..143c59c 100644 --- a/src/core/CoreIndex.ts +++ b/src/core/CoreIndex.ts @@ -15,7 +15,7 @@ import { CreatorOptions, SupportedTemplateSize } from '../types/type'; import { CoreLiteDownloader } from './core-lite/CoreLiteDownloader'; class Creator { - constructor(name: string, options: Omit, command: any) { + constructor(name: string, options: Omit, _command?: any) { clear(); console.log('*****************************'); console.log(chalk.green(figlet.textSync('TDesign Starter', { horizontalLayout: 'full' }))); @@ -65,8 +65,8 @@ class Creator { } } if (!isValid) { - return - }; + return; + } spinner.succeed(chalk.green('构建环境正常!')); console.log(); diff --git a/src/core/CoreSelector.ts b/src/core/CoreSelector.ts index 3a27bf3..611da85 100644 --- a/src/core/CoreSelector.ts +++ b/src/core/CoreSelector.ts @@ -8,7 +8,7 @@ import { IParsedSourceData } from './CoreParsedConfig'; import coreTemplateVue2Config from './core-template/CoreTemplateVue2Config'; import coreTemplateVue3Config from './core-template/CoreTemplateVue3Config'; import coreTemplateReactConfig from './core-template/CoreTemplateReactConfig'; -import { CreatorOptions, SupportedTemplate } from '../types/type'; +import { CreatorOptions } from '../types/type'; /** * 分段内容选择 diff --git a/src/core/core-options/CoreOptionsFilterForReact.ts b/src/core/core-options/CoreOptionsFilterForReact.ts index 0dbfef0..215ba48 100644 --- a/src/core/core-options/CoreOptionsFilterForReact.ts +++ b/src/core/core-options/CoreOptionsFilterForReact.ts @@ -15,7 +15,7 @@ import fs from 'fs'; export class CoreOptionsFilterForReact extends CoreOptionsFilterForVue2 { /** override 生成原始配置 */ - public generateSourceModulesData(options: any, finalOptions: any, downloadConfigSource: any = '') { + public generateSourceModulesData(options: any, finalOptions: any, _downloadConfigSource: any = '') { // REACT比较特殊,使用配置驱动 const configDataContent: any = [ { diff --git a/src/core/core-options/CoreOptionsFilterForVue2.ts b/src/core/core-options/CoreOptionsFilterForVue2.ts index bce3ab1..489ce5a 100644 --- a/src/core/core-options/CoreOptionsFilterForVue2.ts +++ b/src/core/core-options/CoreOptionsFilterForVue2.ts @@ -127,12 +127,12 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { * 去除生成目录内容 .github .husky .vscode * * @param {*} options - * @param {*} finalOptions + * @param {*} _finalOptions * * @memberOf CoreOptionsFilter */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - public async clearUnusedDirectories(options: any, finalOptions: any): Promise { + public async clearUnusedDirectories(options: any, _finalOptions: any): Promise { const localPath = `${process.env.PWD}/${options.name}`; // console.log('options.name==', localPath); @@ -274,13 +274,13 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { * 还原排除目录后的路由配置 * * @private - * @param {string} sourceModulesData - * @param {*} options + * @param {string} _sourceModulesData + * @param {*} _options * @param {*} finalOptions * * @memberOf CoreOptionsFilter */ - protected restoreSourceModulesRouterData(sourceModulesData: string, options: any, finalOptions: any) { + protected restoreSourceModulesRouterData(_sourceModulesData: string, _options: any, finalOptions: any) { // 找出不在列表中的目录,即为需要排除内容 const keepedTypeList: Array = []; // 找出需要保留的 @@ -302,11 +302,11 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { * @private * @param {string} sourceModulesData * @param {*} options - * @param {*} finalOptions + * @param {*} _finalOptions * * @memberOf CoreOptionsFilter */ - protected async excludeSouceDeleteFolder(keepedTypeList: Array, options: any, finalOptions: any) { + protected async excludeSouceDeleteFolder(keepedTypeList: Array, options: any, _finalOptions?: any) { for (const iterator of keepedTypeList) { const element: IParsedSourceData = iterator; const elementPath = `${process.env.PWD}/${options.name}/src/pages`; @@ -326,7 +326,7 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { * * @memberOf CoreOptionsFilter */ - protected async generateExcludeRouter(deletedTypeList: Array, sourceModulesData: any, options: any, finalOptions: any) { + protected async generateExcludeRouter(_deletedTypeList: Array, sourceModulesData: any, _options: any, finalOptions: any) { // 找出不在列表中的目录,即为需要排除内容 const saveedList = []; const selectTypeList: Array = []; @@ -370,7 +370,7 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { } /** 生成原始配置-START */ - public generateSourceModulesData(options: any, finalOptions: any, downloadConfigSource: any = '') { + public generateSourceModulesData(_options: any, _finalOptions: any, downloadConfigSource: any = '') { // 取单例配置 let configDataVue = this.getConfigTemplateInstanceData().getConfig(); @@ -442,11 +442,11 @@ export class CoreOptionsFilterForVue2 implements IOptionsFilter { * * @private * @param {any[]} saveedList - * @param {string} configData + * @param {string} _configData * * @memberOf CoreOptionsFilter */ - protected saveRouterFilter(saveedList: any[], configData: string, options: any, finalOptions: any) { + protected saveRouterFilter(saveedList: any[], _configData: string, options: any, _finalOptions: any) { let configDataContent = JSON.stringify(saveedList); configDataContent = this.formatJson(configDataContent); diff --git a/tsconfig.json b/tsconfig.json index 3ff0bb3..084e79e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "esModuleInterop": true, "resolveJsonModule": true, "removeComments": false, - "importHelpers": true, + "importHelpers": false, "strict": true, "skipLibCheck": true, "lib": ["ES6", "DOM"]