Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate create command to standalone package #27

Merged
merged 14 commits into from
Nov 13, 2024
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.
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
Loading