Skip to content

Commit

Permalink
feat: migrate create command to standalone package (#27)
Browse files Browse the repository at this point in the history
* feat: migrate create command to standalone package

* feat: cancel pkg config

* feat: delete main create and move template

* feat: 迁移

* feat: format

* feat: change release templates pkg dependencies version

* feat: dep

* chore: improve

* chore: improve

* chore: update pnpm-lock.yaml

* chore: add changelog

* chore: update

---------

Co-authored-by: sorrycc <[email protected]>
  • Loading branch information
QDyanbing and sorrycc authored Nov 13, 2024
1 parent cba7a99 commit ef81114
Show file tree
Hide file tree
Showing 25 changed files with 180 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
6 changes: 6 additions & 0 deletions .changeset/lemon-melons-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-tnf': patch
'@umijs/tnf': patch
---

use standalone create-tnf package
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/examples/*/src/.tailwindcss
/examples/*/dist
/examples/*/node_modules
/create-tnf/node_modules
/create-tnf/dist
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ $ pnpm preview

## Commands

- `tnf create <project-name> --template=<template-name>`: Create a new project with the given template.
- `tnf build`: Build the project.
- `tnf dev`: Start the development server.
- `tnf generate/g <type> <name>`: Generate a new page (or component and other types in the future).
Expand Down
8 changes: 8 additions & 0 deletions create-tnf/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'father';

export default defineConfig({
cjs: {
input: 'src',
output: 'dist',
},
});
15 changes: 15 additions & 0 deletions create-tnf/README.md
Original file line number Diff line number Diff line change
@@ -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 <project-name> --template=<template-name>
```

## LICENSE

MIT
3 changes: 3 additions & 0 deletions create-tnf/bin/create-tnf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/cli');
36 changes: 36 additions & 0 deletions create-tnf/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"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",
"doctor": "father doctor",
"release": "tsx ../scripts/releasePackage.ts --pkg create-tnf"
},
"files": [
"bin",
"dist",
"templates"
],
"dependencies": {
"@types/yargs-parser": "^21.0.3",
"@clack/prompts": "^0.7.0",
"yargs-parser": "^21.1.1"
},
"devDependencies": {
"father": "^4.5.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
},
"engines": {
"node": ">=18.13"
}
}
16 changes: 16 additions & 0 deletions create-tnf/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import yargsParser from 'yargs-parser';
import { create } from './create.js';

async function run(cwd: string) {
const argv = yargsParser(process.argv.slice(1));
return create({
cwd: cwd,
name: argv._[0] as string | undefined,
template: argv.template,
});
}

run(process.cwd()).catch((err) => {
console.error(err.message);
process.exit(1);
});
3 changes: 2 additions & 1 deletion src/create.ts → create-tnf/src/create.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,6 +12,7 @@ export async function create({
template?: string;
}) {
intro('Creating a new project...');

const templatesPath = path.join(__dirname, '../templates');
const templateList = fs
.readdirSync(templatesPath)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions create-tnf/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@total-typescript/tsconfig/bundler/no-dom",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"]
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- "."
- "create-tnf"
- "examples/*"
2 changes: 1 addition & 1 deletion scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
33 changes: 33 additions & 0 deletions scripts/releasePackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'assert';
import 'zx/globals';

(async () => {
const pkg = argv.pkg;
assert(pkg, 'pkg is required, specify with --pkg <pkg-name>');
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);
});
7 changes: 0 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.js');
return create({
cwd: cwd,
name: argv._[1] as string | undefined,
template: argv.template,
});
case 'build':
const { build } = await import('./build.js');
return build({
Expand Down

0 comments on commit ef81114

Please sign in to comment.