From 87b4d3ed610e13e6910edcffc62b87a82c24738d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Tue, 12 Nov 2024 17:55:59 +0800 Subject: [PATCH 01/12] feat: migrate create command to standalone package --- .gitignore | 2 ++ create-tnf/.fatherrc.ts | 8 +++++ create-tnf/package.json | 26 ++++++++++++++ create-tnf/src/index.ts | 73 ++++++++++++++++++++++++++++++++++++++++ create-tnf/tsconfig.json | 14 ++++++++ package.json | 7 ++-- pnpm-workspace.yaml | 1 + src/cli.ts | 2 +- tsconfig.json | 6 +++- 9 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 create-tnf/.fatherrc.ts create mode 100644 create-tnf/package.json create mode 100644 create-tnf/src/index.ts create mode 100644 create-tnf/tsconfig.json diff --git a/.gitignore b/.gitignore index 33fe186..9a408dc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /examples/*/src/.tnf /examples/*/dist /examples/*/node_modules +/create-tnf/node_modules +/create-tnf/dist diff --git a/create-tnf/.fatherrc.ts b/create-tnf/.fatherrc.ts new file mode 100644 index 0000000..c24d9b4 --- /dev/null +++ b/create-tnf/.fatherrc.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + cjs: { + input: 'src', + output: 'dist', + }, +}); diff --git a/create-tnf/package.json b/create-tnf/package.json new file mode 100644 index 0000000..6760715 --- /dev/null +++ b/create-tnf/package.json @@ -0,0 +1,26 @@ +{ + "name": "create-tnf", + "version": "0.1.2", + "description": "A standalone create command for TNF.", + "main": "dist/index.js", + "types": "dist/types/index.d.ts", + "scripts": { + "build": "father build" + }, + "files": [ + "dist" + ], + "dependencies": { + "@clack/prompts": "^0.7.0", + "pathe": "^1.1.2" + }, + "devDependencies": { + "father": "^4.5.1", + "typescript": "^5.6.3" + }, + "keywords": [ + "tnf", + "create", + "project" + ] +} diff --git a/create-tnf/src/index.ts b/create-tnf/src/index.ts new file mode 100644 index 0000000..2aaca39 --- /dev/null +++ b/create-tnf/src/index.ts @@ -0,0 +1,73 @@ +import { intro, isCancel, outro, select, text } from '@clack/prompts'; +import fs from 'fs'; +import path from 'pathe'; + +export async function create({ + cwd, + name, + template, +}: { + cwd: string; + name?: string; + template?: string; +}) { + intro('Creating a new project...'); + + const templatesPath = path.join(__dirname, '../../templates'); + const templateList = fs + .readdirSync(templatesPath) + .filter((file) => + fs.statSync(path.join(templatesPath, file)).isDirectory(), + ); + const selectedTemplate = + template || + (await select({ + message: 'Select a template:', + options: templateList.map((template) => ({ + label: template, + value: template, + })), + })); + if (isCancel(selectedTemplate)) { + outro('Aborted'); + return; + } + const projectName = await (async () => { + if (name) { + const error = validate(name); + if (error) { + throw new Error(error); + } + return name; + } + return await text({ + message: 'Project name:', + initialValue: 'myapp', + validate, + }); + function validate(value: string) { + if (!value) { + return `Project name is required but got ${value}`; + } + if (fs.existsSync(path.join(cwd, value))) { + return `Project ${path.join(cwd, value)} already exists`; + } + } + })(); + if (isCancel(projectName)) { + outro('Aborted'); + return; + } + if (fs.existsSync(path.join(cwd, projectName))) { + throw new Error('Project already exists'); + } + const templatePath = path.join(templatesPath, selectedTemplate as string); + const projectPath = path.join(cwd, projectName); + fs.cpSync(templatePath, projectPath, { recursive: true }); + outro(`Project created in ${projectPath}.`); + console.log(`Now run: + + cd ${projectPath} + npm install + npm run build`); +} diff --git a/create-tnf/tsconfig.json b/create-tnf/tsconfig.json new file mode 100644 index 0000000..8bc8a3c --- /dev/null +++ b/create-tnf/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "CommonJS", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "declarationDir": "dist/types", + "outDir": "dist" + }, + "include": ["src/**/*.ts"] +} diff --git a/package.json b/package.json index 0865cb6..5a3f05b 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "compression": "^1.7.5", "connect-history-api-fallback": "^2.0.0", "cors": "^2.8.5", + "create-tnf": "^0.1.2", "express": "^4.21.1", "express-http-proxy": "^2.1.1", "fs-extra": "^11.1.0", @@ -63,6 +64,8 @@ "devDependencies": { "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.9", + "@commitlint/cli": "^19.0.3", + "@commitlint/config-conventional": "^19.0.3", "@manypkg/get-packages": "^2.2.2", "@playwright/test": "^1.48.2", "@total-typescript/tsconfig": "^1.0.4", @@ -76,9 +79,7 @@ "tsx": "^4.19.2", "typescript": "^5.6.3", "vitest": "^2.1.4", - "zx": "^8.2.0", - "@commitlint/cli": "^19.0.3", - "@commitlint/config-conventional": "^19.0.3" + "zx": "^8.2.0" }, "lint-staged": { "*.{jsx,less,md,json}": [ diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 19b49ed..d34745c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,4 @@ packages: - "." + - "create-tnf" - "examples/*" diff --git a/src/cli.ts b/src/cli.ts index 78bd268..7699338 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,7 +15,7 @@ async function run(cwd: string) { assert(cmd, 'Command is required'); switch (cmd) { case 'create': - const { create } = await import('./create.js'); + const { create } = await import('create-tnf/dist/index.js'); return create({ cwd: cwd, name: argv._[1] as string | undefined, diff --git a/tsconfig.json b/tsconfig.json index 95cb908..471e335 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,12 @@ { "extends": "@total-typescript/tsconfig/bundler/no-dom", "compilerOptions": { + "baseUrl": ".", "outDir": "./dist", - "rootDir": "./src" + "rootDir": "./src", + "paths": { + "create-tnf": ["create-tnf"] + } }, "include": ["src"] } From de398e792c30f0397be91e87d5aca9ed1a2c8375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 09:17:13 +0800 Subject: [PATCH 02/12] feat: cancel pkg config --- package.json | 9 ++++----- tsconfig.json | 6 +----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index c9dff6e..153e79a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "compression": "^1.7.5", "connect-history-api-fallback": "^2.0.0", "cors": "^2.8.5", - "create-tnf": "^0.1.2", "express": "^4.21.1", "express-http-proxy": "^2.1.1", "fs-extra": "^11.1.0", @@ -65,8 +64,6 @@ "devDependencies": { "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.9", - "@commitlint/cli": "^19.0.3", - "@commitlint/config-conventional": "^19.0.3", "@manypkg/get-packages": "^2.2.2", "@playwright/test": "^1.48.2", "@total-typescript/tsconfig": "^1.0.4", @@ -80,7 +77,9 @@ "tsx": "^4.19.2", "typescript": "^5.6.3", "vitest": "^2.1.4", - "zx": "^8.2.0" + "zx": "^8.2.0", + "@commitlint/cli": "^19.0.3", + "@commitlint/config-conventional": "^19.0.3" }, "lint-staged": { "*.{jsx,less,md,json}": [ @@ -97,4 +96,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 471e335..95cb908 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,8 @@ { "extends": "@total-typescript/tsconfig/bundler/no-dom", "compilerOptions": { - "baseUrl": ".", "outDir": "./dist", - "rootDir": "./src", - "paths": { - "create-tnf": ["create-tnf"] - } + "rootDir": "./src" }, "include": ["src"] } From 713101f0fa72693d30fbd7a35799852db06d5a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 09:19:00 +0800 Subject: [PATCH 03/12] feat: delete main create and move template --- .../templates}/simple/package.json | 0 .../templates}/simple/public/index.html | 0 .../templates}/simple/src/pages/__root.tsx | 0 .../simple/src/pages/index.module.less | 0 .../templates}/simple/src/pages/index.tsx | 0 .../templates}/simple/tsconfig.json | 0 .../templates}/simple/typings.d.ts | 0 src/cli.ts | 7 -- src/create.ts | 72 ------------------- 9 files changed, 79 deletions(-) rename {templates => create-tnf/templates}/simple/package.json (100%) rename {templates => create-tnf/templates}/simple/public/index.html (100%) rename {templates => create-tnf/templates}/simple/src/pages/__root.tsx (100%) rename {templates => create-tnf/templates}/simple/src/pages/index.module.less (100%) rename {templates => create-tnf/templates}/simple/src/pages/index.tsx (100%) rename {templates => create-tnf/templates}/simple/tsconfig.json (100%) rename {templates => create-tnf/templates}/simple/typings.d.ts (100%) delete mode 100644 src/create.ts diff --git a/templates/simple/package.json b/create-tnf/templates/simple/package.json similarity index 100% rename from templates/simple/package.json rename to create-tnf/templates/simple/package.json diff --git a/templates/simple/public/index.html b/create-tnf/templates/simple/public/index.html similarity index 100% rename from templates/simple/public/index.html rename to create-tnf/templates/simple/public/index.html diff --git a/templates/simple/src/pages/__root.tsx b/create-tnf/templates/simple/src/pages/__root.tsx similarity index 100% rename from templates/simple/src/pages/__root.tsx rename to create-tnf/templates/simple/src/pages/__root.tsx diff --git a/templates/simple/src/pages/index.module.less b/create-tnf/templates/simple/src/pages/index.module.less similarity index 100% rename from templates/simple/src/pages/index.module.less rename to create-tnf/templates/simple/src/pages/index.module.less diff --git a/templates/simple/src/pages/index.tsx b/create-tnf/templates/simple/src/pages/index.tsx similarity index 100% rename from templates/simple/src/pages/index.tsx rename to create-tnf/templates/simple/src/pages/index.tsx diff --git a/templates/simple/tsconfig.json b/create-tnf/templates/simple/tsconfig.json similarity index 100% rename from templates/simple/tsconfig.json rename to create-tnf/templates/simple/tsconfig.json diff --git a/templates/simple/typings.d.ts b/create-tnf/templates/simple/typings.d.ts similarity index 100% rename from templates/simple/typings.d.ts rename to create-tnf/templates/simple/typings.d.ts diff --git a/src/cli.ts b/src/cli.ts index 1846032..ce2ccdf 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,13 +15,6 @@ async function run(cwd: string) { const cmd = argv._[0]; assert(cmd, 'Command is required'); switch (cmd) { - case 'create': - const { create } = await import('create-tnf/dist/index.js'); - return create({ - cwd: cwd, - name: argv._[1] as string | undefined, - template: argv.template, - }); case 'build': const { build } = await import('./build.js'); return build({ diff --git a/src/create.ts b/src/create.ts deleted file mode 100644 index c7d4940..0000000 --- a/src/create.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { intro, isCancel, outro, select, text } from '@clack/prompts'; -import fs from 'fs'; -import path from 'pathe'; - -export async function create({ - cwd, - name, - template, -}: { - cwd: string; - name?: string; - template?: string; -}) { - intro('Creating a new project...'); - const templatesPath = path.join(__dirname, '../templates'); - const templateList = fs - .readdirSync(templatesPath) - .filter((file) => - fs.statSync(path.join(templatesPath, file)).isDirectory(), - ); - const selectedTemplate = - template || - (await select({ - message: 'Select a template:', - options: templateList.map((template) => ({ - label: template, - value: template, - })), - })); - if (isCancel(selectedTemplate)) { - outro('Aborted'); - return; - } - const projectName = await (async () => { - if (name) { - const error = validate(name); - if (error) { - throw new Error(error); - } - return name; - } - return await text({ - message: 'Project name:', - initialValue: 'myapp', - validate, - }); - function validate(value: string) { - if (!value) { - return `Project name is required but got ${value}`; - } - if (fs.existsSync(path.join(cwd, value))) { - return `Project ${path.join(cwd, value)} already exists`; - } - } - })(); - if (isCancel(projectName)) { - outro('Aborted'); - return; - } - if (fs.existsSync(path.join(cwd, projectName))) { - throw new Error('Project already exists'); - } - const templatePath = path.join(templatesPath, selectedTemplate as string); - const projectPath = path.join(cwd, projectName); - fs.cpSync(templatePath, projectPath, { recursive: true }); - outro(`Project created in ${projectPath}.`); - console.log(`Now run: - - cd ${projectPath} - npm install - npm run build`); -} From fdfc78ff7f8d899014205464182441ccb7cb69e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 10:44:57 +0800 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- create-tnf/bin/create-tnf.js | 20 +++++++ create-tnf/package.json | 11 ++-- create-tnf/src/constants.ts | 2 + create-tnf/src/create.ts | 73 +++++++++++++++++++++++++ create-tnf/src/fishkit/node.ts | 30 +++++++++++ create-tnf/src/index.ts | 97 ++++++++++------------------------ create-tnf/tsconfig.json | 14 ++--- 7 files changed, 163 insertions(+), 84 deletions(-) create mode 100755 create-tnf/bin/create-tnf.js create mode 100644 create-tnf/src/constants.ts create mode 100644 create-tnf/src/create.ts create mode 100644 create-tnf/src/fishkit/node.ts diff --git a/create-tnf/bin/create-tnf.js b/create-tnf/bin/create-tnf.js new file mode 100755 index 0000000..5191234 --- /dev/null +++ b/create-tnf/bin/create-tnf.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +// patch console for debug +// ref: https://remysharp.com/2014/05/23/where-is-that-console-log +if (process.env.DEBUG_CONSOLE) { + ['log', 'warn', 'error'].forEach((method) => { + const old = console[method]; + console[method] = function () { + let stack = new Error().stack.split(/\n/); + // Chrome includes a single "Error" line, FF doesn't. + if (stack[0].indexOf('Error') === 0) { + stack = stack.slice(1); + } + const args = [].slice.apply(arguments).concat([stack[1].trim()]); + return old.apply(console, args); + }; + }); +} + +require('../dist'); diff --git a/create-tnf/package.json b/create-tnf/package.json index 6760715..9b3a450 100644 --- a/create-tnf/package.json +++ b/create-tnf/package.json @@ -1,14 +1,17 @@ { - "name": "create-tnf", + "name": "@umijs/create-tnf", "version": "0.1.2", "description": "A standalone create command for TNF.", - "main": "dist/index.js", - "types": "dist/types/index.d.ts", + "bin": { + "create-tnf": "bin/create-tnf.js" + }, "scripts": { "build": "father build" }, "files": [ - "dist" + "bin", + "dist", + "templates" ], "dependencies": { "@clack/prompts": "^0.7.0", diff --git a/create-tnf/src/constants.ts b/create-tnf/src/constants.ts new file mode 100644 index 0000000..a05d7d3 --- /dev/null +++ b/create-tnf/src/constants.ts @@ -0,0 +1,2 @@ +export const MIN_NODE_VERSION = 18; +export const FRAMEWORK_NAME = 'tnf'; diff --git a/create-tnf/src/create.ts b/create-tnf/src/create.ts new file mode 100644 index 0000000..c4a052a --- /dev/null +++ b/create-tnf/src/create.ts @@ -0,0 +1,73 @@ +import { intro, isCancel, outro, select, text } from '@clack/prompts'; +import fs from 'fs'; +import path from 'pathe'; + +export async function create({ + cwd, + name, + template, +}: { + cwd: string; + name?: string; + template?: string; +}) { + intro('Creating a new project...'); + + const templatesPath = path.join(__dirname, '../templates'); + const templateList = fs + .readdirSync(templatesPath) + .filter((file) => + fs.statSync(path.join(templatesPath, file)).isDirectory(), + ); + const selectedTemplate = + template || + (await select({ + message: 'Select a template:', + options: templateList.map((template) => ({ + label: template, + value: template, + })), + })); + if (isCancel(selectedTemplate)) { + outro('Aborted'); + return; + } + const projectName = await (async () => { + if (name) { + const error = validate(name); + if (error) { + throw new Error(error); + } + return name; + } + return await text({ + message: 'Project name:', + initialValue: 'myapp', + validate, + }); + function validate(value: string) { + if (!value) { + return `Project name is required but got ${value}`; + } + if (fs.existsSync(path.join(cwd, value))) { + return `Project ${path.join(cwd, value)} already exists`; + } + } + })(); + if (isCancel(projectName)) { + outro('Aborted'); + return; + } + if (fs.existsSync(path.join(cwd, projectName))) { + throw new Error('Project already exists'); + } + const templatePath = path.join(templatesPath, selectedTemplate as string); + const projectPath = path.join(cwd, projectName); + fs.cpSync(templatePath, projectPath, { recursive: true }); + outro(`Project created in ${projectPath}.`); + console.log(`Now run: + + cd ${projectPath} + npm install + npm run build`); +} diff --git a/create-tnf/src/fishkit/node.ts b/create-tnf/src/fishkit/node.ts new file mode 100644 index 0000000..8745486 --- /dev/null +++ b/create-tnf/src/fishkit/node.ts @@ -0,0 +1,30 @@ +export function setNoDeprecation() { + // Use magic to suppress node deprecation warnings + // See: https://github.com/nodejs/node/blob/6311de332223e855e7f1ce03b7c920f51f308e95/lib/internal/process/warning.js#L95 + // @ts-ignore + process.noDeprecation = '1'; +} + +export function checkVersion(minVersion: number, message?: string) { + const ver = parseInt(process.version.slice(1)); + const isOdd = ver % 2 === 1; + if (isOdd) { + console.error( + `Odd node version is not supported, your node version is ${ver}.`, + ); + process.exit(1); + } + if (ver < minVersion) { + console.error( + message || + `Your node version ${ver} is not supported, please upgrade to ${minVersion} or above.`, + ); + process.exit(1); + } +} + +export function setNodeTitle(name: string) { + if (process.title === 'node') { + process.title = name; + } +} diff --git a/create-tnf/src/index.ts b/create-tnf/src/index.ts index 2aaca39..a0c8a70 100644 --- a/create-tnf/src/index.ts +++ b/create-tnf/src/index.ts @@ -1,73 +1,30 @@ -import { intro, isCancel, outro, select, text } from '@clack/prompts'; -import fs from 'fs'; -import path from 'pathe'; +import assert from 'assert'; +import yargsParser from 'yargs-parser'; +import { FRAMEWORK_NAME, MIN_NODE_VERSION } from './constants.js'; +import { create } from './create.js'; +import { + checkVersion, + setNoDeprecation, + setNodeTitle, +} from './fishkit/node.js'; -export async function create({ - cwd, - name, - template, -}: { - cwd: string; - name?: string; - template?: string; -}) { - intro('Creating a new project...'); +async function run(cwd: string) { + const argv = yargsParser(process.argv.slice(1)); + const cmd = argv._[0]; + assert(cmd, 'Command is required'); - const templatesPath = path.join(__dirname, '../../templates'); - const templateList = fs - .readdirSync(templatesPath) - .filter((file) => - fs.statSync(path.join(templatesPath, file)).isDirectory(), - ); - const selectedTemplate = - template || - (await select({ - message: 'Select a template:', - options: templateList.map((template) => ({ - label: template, - value: template, - })), - })); - if (isCancel(selectedTemplate)) { - outro('Aborted'); - return; - } - const projectName = await (async () => { - if (name) { - const error = validate(name); - if (error) { - throw new Error(error); - } - return name; - } - return await text({ - message: 'Project name:', - initialValue: 'myapp', - validate, - }); - function validate(value: string) { - if (!value) { - return `Project name is required but got ${value}`; - } - if (fs.existsSync(path.join(cwd, value))) { - return `Project ${path.join(cwd, value)} already exists`; - } - } - })(); - if (isCancel(projectName)) { - outro('Aborted'); - return; - } - if (fs.existsSync(path.join(cwd, projectName))) { - throw new Error('Project already exists'); - } - const templatePath = path.join(templatesPath, selectedTemplate as string); - const projectPath = path.join(cwd, projectName); - fs.cpSync(templatePath, projectPath, { recursive: true }); - outro(`Project created in ${projectPath}.`); - console.log(`Now run: - - cd ${projectPath} - npm install - npm run build`); + return create({ + cwd: cwd, + name: argv._[1] as string | undefined, + template: argv.template, + }); } + +setNoDeprecation(); +checkVersion(MIN_NODE_VERSION); +setNodeTitle(FRAMEWORK_NAME); + +run(process.cwd()).catch((err) => { + console.error(err.message); + process.exit(1); +}); diff --git a/create-tnf/tsconfig.json b/create-tnf/tsconfig.json index 8bc8a3c..95cb908 100644 --- a/create-tnf/tsconfig.json +++ b/create-tnf/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@total-typescript/tsconfig/bundler/no-dom", "compilerOptions": { - "target": "ES6", - "module": "CommonJS", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "declaration": true, - "declarationDir": "dist/types", - "outDir": "dist" + "outDir": "./dist", + "rootDir": "./src" }, - "include": ["src/**/*.ts"] + "include": ["src"] } From 8390a97955b356f6b1addd632455c1d88707774c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 10:48:49 +0800 Subject: [PATCH 05/12] feat: format --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 153e79a..29acec9 100644 --- a/package.json +++ b/package.json @@ -96,4 +96,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From bb6cf3235ff85fe86eac3d1a8181c2730aedb775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 11:00:26 +0800 Subject: [PATCH 06/12] feat: change release templates pkg dependencies version --- scripts/release.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release.ts b/scripts/release.ts index 9d426cb..b79908d 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -30,7 +30,7 @@ import 'zx/globals'; ); console.log('update templates'); - const templateDir = path.join(__dirname, '../templates'); + const templateDir = path.join(__dirname, '../create-tnf/templates'); const templateDirs = fs .readdirSync(templateDir) .filter((dir) => fs.statSync(path.join(templateDir, dir)).isDirectory()); From 12ed6527102803a64b117e51b7dedc4622b6fc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 13 Nov 2024 11:14:41 +0800 Subject: [PATCH 07/12] feat: dep --- pnpm-lock.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f927466..a0fceb2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -166,6 +166,22 @@ importers: specifier: ^8.2.0 version: 8.2.0 + create-tnf: + dependencies: + '@clack/prompts': + specifier: ^0.7.0 + version: 0.7.0 + pathe: + specifier: ^1.1.2 + version: 1.1.2 + devDependencies: + father: + specifier: ^4.5.1 + version: 4.5.1(@babel/core@7.26.0)(@types/node@22.9.0)(styled-components@6.1.13)(webpack@5.96.1) + typescript: + specifier: ^5.6.3 + version: 5.6.3 + examples/hackernews: dependencies: '@types/react': From 91ed25ab9e271d59a011fe8d2bbe698add5f6705 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Wed, 13 Nov 2024 13:41:03 +0800 Subject: [PATCH 08/12] chore: improve --- README.md | 1 - create-tnf/README.md | 15 +++++++++++++ create-tnf/bin/create-tnf.js | 19 +---------------- create-tnf/package.json | 26 +++++++++++++---------- create-tnf/src/{index.ts => cli.ts} | 15 +------------ create-tnf/src/constants.ts | 2 -- create-tnf/src/create.ts | 2 +- create-tnf/src/fishkit/node.ts | 30 -------------------------- package.json | 7 ++++++ scripts/releasePackage.ts | 33 +++++++++++++++++++++++++++++ 10 files changed, 73 insertions(+), 77 deletions(-) create mode 100644 create-tnf/README.md rename create-tnf/src/{index.ts => cli.ts} (50%) delete mode 100644 create-tnf/src/constants.ts delete mode 100644 create-tnf/src/fishkit/node.ts create mode 100644 scripts/releasePackage.ts diff --git a/README.md b/README.md index 94f1f79..556a467 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ $ pnpm preview ## Commands -- `tnf create --template=`: Create a new project with the given template. - `tnf build`: Build the project. - `tnf dev`: Start the development server. - `tnf generate/g `: Generate a new page (or component and other types in the future). diff --git a/create-tnf/README.md b/create-tnf/README.md new file mode 100644 index 0000000..e3e014f --- /dev/null +++ b/create-tnf/README.md @@ -0,0 +1,15 @@ +# create-tnf + +Create a new TNF project. + +## Usage + +```bash +$ npm create tnf +# Create a new project with the given name and template +$ npm create tnf --template= +``` + +## LICENSE + +MIT diff --git a/create-tnf/bin/create-tnf.js b/create-tnf/bin/create-tnf.js index 5191234..4f46430 100755 --- a/create-tnf/bin/create-tnf.js +++ b/create-tnf/bin/create-tnf.js @@ -1,20 +1,3 @@ #!/usr/bin/env node -// patch console for debug -// ref: https://remysharp.com/2014/05/23/where-is-that-console-log -if (process.env.DEBUG_CONSOLE) { - ['log', 'warn', 'error'].forEach((method) => { - const old = console[method]; - console[method] = function () { - let stack = new Error().stack.split(/\n/); - // Chrome includes a single "Error" line, FF doesn't. - if (stack[0].indexOf('Error') === 0) { - stack = stack.slice(1); - } - const args = [].slice.apply(arguments).concat([stack[1].trim()]); - return old.apply(console, args); - }; - }); -} - -require('../dist'); +require('../dist/cli'); diff --git a/create-tnf/package.json b/create-tnf/package.json index 9b3a450..df0cbdb 100644 --- a/create-tnf/package.json +++ b/create-tnf/package.json @@ -1,12 +1,19 @@ { - "name": "@umijs/create-tnf", - "version": "0.1.2", - "description": "A standalone create command for TNF.", + "name": "create-tnf", + "version": "0.0.0-alpha.0", + "homepage": "https://github.com/umijs/tnf/tree/master/create-tnf", + "bugs": "https://github.com/umijs/tnf/issues", + "repository": { + "type": "git", + "url": "https://github.com/umijs/tnf" + }, "bin": { "create-tnf": "bin/create-tnf.js" }, "scripts": { - "build": "father build" + "build": "father build", + "doctor": "father doctor", + "release": "tsx ../scripts/releasePackage.ts --pkg create-tnf" }, "files": [ "bin", @@ -14,16 +21,13 @@ "templates" ], "dependencies": { + "@types/yargs-parser": "^21.0.3", "@clack/prompts": "^0.7.0", - "pathe": "^1.1.2" + "yargs-parser": "^21.1.1" }, "devDependencies": { "father": "^4.5.1", + "tsx": "^4.19.2", "typescript": "^5.6.3" - }, - "keywords": [ - "tnf", - "create", - "project" - ] + } } diff --git a/create-tnf/src/index.ts b/create-tnf/src/cli.ts similarity index 50% rename from create-tnf/src/index.ts rename to create-tnf/src/cli.ts index a0c8a70..4d5cc59 100644 --- a/create-tnf/src/index.ts +++ b/create-tnf/src/cli.ts @@ -1,29 +1,16 @@ import assert from 'assert'; import yargsParser from 'yargs-parser'; -import { FRAMEWORK_NAME, MIN_NODE_VERSION } from './constants.js'; import { create } from './create.js'; -import { - checkVersion, - setNoDeprecation, - setNodeTitle, -} from './fishkit/node.js'; async function run(cwd: string) { const argv = yargsParser(process.argv.slice(1)); - const cmd = argv._[0]; - assert(cmd, 'Command is required'); - return create({ cwd: cwd, - name: argv._[1] as string | undefined, + name: argv._[0] as string | undefined, template: argv.template, }); } -setNoDeprecation(); -checkVersion(MIN_NODE_VERSION); -setNodeTitle(FRAMEWORK_NAME); - run(process.cwd()).catch((err) => { console.error(err.message); process.exit(1); diff --git a/create-tnf/src/constants.ts b/create-tnf/src/constants.ts deleted file mode 100644 index a05d7d3..0000000 --- a/create-tnf/src/constants.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const MIN_NODE_VERSION = 18; -export const FRAMEWORK_NAME = 'tnf'; diff --git a/create-tnf/src/create.ts b/create-tnf/src/create.ts index c4a052a..dc256dd 100644 --- a/create-tnf/src/create.ts +++ b/create-tnf/src/create.ts @@ -1,6 +1,6 @@ import { intro, isCancel, outro, select, text } from '@clack/prompts'; import fs from 'fs'; -import path from 'pathe'; +import path from 'path'; export async function create({ cwd, diff --git a/create-tnf/src/fishkit/node.ts b/create-tnf/src/fishkit/node.ts deleted file mode 100644 index 8745486..0000000 --- a/create-tnf/src/fishkit/node.ts +++ /dev/null @@ -1,30 +0,0 @@ -export function setNoDeprecation() { - // Use magic to suppress node deprecation warnings - // See: https://github.com/nodejs/node/blob/6311de332223e855e7f1ce03b7c920f51f308e95/lib/internal/process/warning.js#L95 - // @ts-ignore - process.noDeprecation = '1'; -} - -export function checkVersion(minVersion: number, message?: string) { - const ver = parseInt(process.version.slice(1)); - const isOdd = ver % 2 === 1; - if (isOdd) { - console.error( - `Odd node version is not supported, your node version is ${ver}.`, - ); - process.exit(1); - } - if (ver < minVersion) { - console.error( - message || - `Your node version ${ver} is not supported, please upgrade to ${minVersion} or above.`, - ); - process.exit(1); - } -} - -export function setNodeTitle(name: string) { - if (process.title === 'node') { - process.title = name; - } -} diff --git a/package.json b/package.json index 29acec9..26984a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,12 @@ { "name": "@umijs/tnf", "version": "0.1.2", + "homepage": "https://github.com/umijs/tnf", + "bugs": "https://github.com/umijs/tnf/issues", + "repository": { + "type": "git", + "url": "https://github.com/umijs/tnf" + }, "scripts": { "build": "father build", "changeset": "tsx scripts/changeset.ts && changeset", @@ -9,6 +15,7 @@ "dev": "father dev", "format": "prettier --write .", "release": "tsx scripts/release.ts", + "release:create-tnf": "pnpm --filter create-tnf release", "test": "vitest", "test:e2e": "tsx scripts/e2e.ts" }, diff --git a/scripts/releasePackage.ts b/scripts/releasePackage.ts new file mode 100644 index 0000000..9169167 --- /dev/null +++ b/scripts/releasePackage.ts @@ -0,0 +1,33 @@ +import assert from 'assert'; +import 'zx/globals'; + +(async () => { + const pkg = argv.pkg; + assert(pkg, 'pkg is required, specify with --pkg '); + const pkgDir = path.join(__dirname, '../', pkg); + assert(fs.existsSync(pkgDir), `pkg ${pkg} not found: ${pkgDir}`); + + console.log('Building package...'); + await $`cd ${pkgDir} && npm run build`; + + console.log('Bumping version...'); + const npmVersion = argv.minor ? 'minor' : 'patch'; + await $`cd ${pkgDir} && npm version ${npmVersion}`; + + console.log('Publishing package...'); + await $`cd ${pkgDir} && npm publish`; + + console.log('Adding to git...'); + await $`pnpm install`; + const newVersion = require(path.join(pkgDir, 'package.json')).version; + await $`git add ${pkgDir}`; + await $`git commit -m "release: ${pkg}@${newVersion}"`; + + console.log('Pushing to git...'); + await $`git push`; + + console.log(`Published ${pkg}@${newVersion}`); +})().catch((err) => { + console.error(err); + process.exit(1); +}); From 099ab6d384f8e8569d911a513e3117469b32e575 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Wed, 13 Nov 2024 13:43:58 +0800 Subject: [PATCH 09/12] chore: improve --- CONTRIBUTING.md | 14 ++++++++++++++ create-tnf/package.json | 3 +++ 2 files changed, 17 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e614be7..e23e520 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,3 +70,17 @@ $ pnpm changeset Based on the modified package name, select the type to be published, usually choosing `patch`.Then enter `changelog`. After the code is merged into the main branch, it will be sent to GitHub CI to automatically change the version number of the corresponding package. + +## Release + +Release tnf package: + +```bash +$ pnpm release +``` + +Release create-tnf package: + +```bash +$ pnpm release:create-tnf +``` diff --git a/create-tnf/package.json b/create-tnf/package.json index df0cbdb..842850b 100644 --- a/create-tnf/package.json +++ b/create-tnf/package.json @@ -29,5 +29,8 @@ "father": "^4.5.1", "tsx": "^4.19.2", "typescript": "^5.6.3" + }, + "engines": { + "node": ">=18.13" } } From e2f89908aa4880b98dd02b4283ee0e8e879d06c2 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Wed, 13 Nov 2024 13:46:12 +0800 Subject: [PATCH 10/12] chore: update pnpm-lock.yaml --- pnpm-lock.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0fceb2..4af4a18 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -171,13 +171,19 @@ importers: '@clack/prompts': specifier: ^0.7.0 version: 0.7.0 - pathe: - specifier: ^1.1.2 - version: 1.1.2 + '@types/yargs-parser': + specifier: ^21.0.3 + version: 21.0.3 + yargs-parser: + specifier: ^21.1.1 + version: 21.1.1 devDependencies: father: specifier: ^4.5.1 version: 4.5.1(@babel/core@7.26.0)(@types/node@22.9.0)(styled-components@6.1.13)(webpack@5.96.1) + tsx: + specifier: ^4.19.2 + version: 4.19.2 typescript: specifier: ^5.6.3 version: 5.6.3 From 6ad416010d9d43360b68d66823ddcd5e308fa9ff Mon Sep 17 00:00:00 2001 From: sorrycc Date: Wed, 13 Nov 2024 13:49:57 +0800 Subject: [PATCH 11/12] chore: add changelog --- .changeset/config.json | 7 ++++++- .changeset/lemon-melons-sort.md | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/lemon-melons-sort.md diff --git a/.changeset/config.json b/.changeset/config.json index af9ea7c..5be92ba 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -15,5 +15,10 @@ "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { "updateInternalDependents": "always" }, - "ignore": ["@examples/hackernews", "@examples/normal", "@examples/with-antd4"] + "ignore": [ + "@examples/hackernews", + "@examples/normal", + "@examples/normal", + "@examples/with-antd4" + ] } diff --git a/.changeset/lemon-melons-sort.md b/.changeset/lemon-melons-sort.md new file mode 100644 index 0000000..b6521a2 --- /dev/null +++ b/.changeset/lemon-melons-sort.md @@ -0,0 +1,6 @@ +--- +'create-tnf': patch +'@umijs/tnf': patch +--- + +use standalone create-tnf package From 62656e3f179ff038b8e441c76a947c08ef1894ae Mon Sep 17 00:00:00 2001 From: sorrycc Date: Wed, 13 Nov 2024 13:52:05 +0800 Subject: [PATCH 12/12] chore: update --- create-tnf/src/cli.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/create-tnf/src/cli.ts b/create-tnf/src/cli.ts index 4d5cc59..b6ba26e 100644 --- a/create-tnf/src/cli.ts +++ b/create-tnf/src/cli.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import yargsParser from 'yargs-parser'; import { create } from './create.js';