Skip to content

Commit

Permalink
chore(create-tnf): bundle create-tnf (#83)
Browse files Browse the repository at this point in the history
* chore(create-tnf): bundle create-tnf

* chore: update pnpm-lock.yaml
  • Loading branch information
sorrycc authored Dec 25, 2024
1 parent 92aa37a commit 7b4640c
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 58 deletions.
18 changes: 7 additions & 11 deletions create-tnf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"type": "git",
"url": "https://github.com/umijs/tnf"
},
"type": "module",
"bin": {
"create-tnf": "bin/create-tnf.js"
},
"scripts": {
"build": "father build",
"dev": "father dev",
"build": "tsx ../scripts/buildCreateTnf.ts",
"doctor": "father doctor",
"release": "tsx ../scripts/releasePackage.ts --pkg create-tnf"
},
Expand All @@ -22,19 +20,17 @@
"dist",
"templates"
],
"dependencies": {
"devDependencies": {
"@clack/prompts": "^0.9.0",
"yargs-parser": "^21.1.1",
"@types/yargs-parser": "^21.0.3",
"father": "^4.5.1",
"is-unicode-supported": "^1.3.0",
"picocolors": "^1.1.1",
"sisteransi": "^1.0.5",
"wrap-ansi": "^8.1.0"
},
"devDependencies": {
"@types/yargs-parser": "^21.0.3",
"father": "^4.5.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"wrap-ansi": "^8.1.0",
"yargs-parser": "^21.1.1"
},
"engines": {
"node": ">=18.13"
Expand Down
20 changes: 10 additions & 10 deletions create-tnf/src/clack/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { default as ConfirmPrompt } from './src/prompts/confirm.js';
export { default as GroupMultiSelectPrompt } from './src/prompts/group-multiselect.js';
export { default as MultiSelectPrompt } from './src/prompts/multi-select.js';
export { default as PasswordPrompt } from './src/prompts/password.js';
export { default as Prompt, isCancel } from './src/prompts/prompt.js';
export type { State } from './src/prompts/prompt.js';
export { default as SelectPrompt } from './src/prompts/select.js';
export { default as SelectKeyPrompt } from './src/prompts/select-key.js';
export { default as TextPrompt } from './src/prompts/text.js';
export { block } from './src/utils.js';
export { default as ConfirmPrompt } from './src/prompts/confirm';
export { default as GroupMultiSelectPrompt } from './src/prompts/group-multiselect';
export { default as MultiSelectPrompt } from './src/prompts/multi-select';
export { default as PasswordPrompt } from './src/prompts/password';
export { default as Prompt, isCancel } from './src/prompts/prompt';
export type { State } from './src/prompts/prompt';
export { default as SelectPrompt } from './src/prompts/select';
export { default as SelectKeyPrompt } from './src/prompts/select-key';
export { default as TextPrompt } from './src/prompts/text';
export { block } from './src/utils';
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/confirm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cursor } from 'sisteransi';
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
active: string;
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/group-multiselect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface GroupMultiSelectOptions<T extends { value: any }>
extends PromptOptions<GroupMultiSelectPrompt<T>> {
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/multi-select.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface MultiSelectOptions<T extends { value: any }>
extends PromptOptions<MultiSelectPrompt<T>> {
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/password.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'picocolors';
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface PasswordOptions extends PromptOptions<PasswordPrompt> {
mask?: string;
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/select-key.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface SelectKeyOptions<T extends { value: any }>
extends PromptOptions<SelectKeyPrompt<T>> {
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/select.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

interface SelectOptions<T extends { value: any }>
extends PromptOptions<SelectPrompt<T>> {
Expand Down
2 changes: 1 addition & 1 deletion create-tnf/src/clack/core/src/prompts/text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'picocolors';
import Prompt, { type PromptOptions } from './prompt.js';
import Prompt, { type PromptOptions } from './prompt';

export interface TextOptions extends PromptOptions<TextPrompt> {
placeholder?: string;
Expand Down
4 changes: 2 additions & 2 deletions create-tnf/src/clack/prompt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
TextPrompt,
block,
isCancel,
} from '../core/index.js';
} from '../core/index';

export { isCancel } from '../core/index.js';
export { isCancel } from '../core/index';

const unicode = isUnicodeSupported();
const s = (c: string, fallback: string) => (unicode ? c : fallback);
Expand Down
8 changes: 2 additions & 6 deletions create-tnf/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import yargsParser from 'yargs-parser';
import * as p from './clack/prompt/index.js';
import { create } from './create.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import * as p from './clack/prompt/index';
import { create } from './create';

async function run(cwd: string) {
const argv = yargsParser(process.argv.slice(2), {
Expand Down
5 changes: 1 addition & 4 deletions create-tnf/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
import pc from 'picocolors';
import { fileURLToPath } from 'url';
import * as p from './clack/prompt/index.js';
import * as p from './clack/prompt/index';

const CANCEL_TEXT = 'Operation cancelled.';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

type NpmClient = 'pnpm' | 'yarn' | 'npm';

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"bootstrap:e2e": "tsx scripts/bootstrapE2e.ts",
"bootstrap:funplugins": "tsx scripts/bootstrapFunplugin.ts",
"build": "father build",
"build:create-tnf": "pnpm --filter create-tnf build",
"compile": "tsx scripts/compile.ts",
"changeset": "tsx scripts/changeset.ts && changeset",
"check": "prettier --check .",
Expand Down
32 changes: 14 additions & 18 deletions pnpm-lock.yaml

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

43 changes: 43 additions & 0 deletions scripts/buildCreateTnf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from 'assert';
import 'zx/globals';

const compile = async () => {
const mako = await import('@umijs/mako');
await mako.build({
config: {
entry: {
cli: './src/cli.ts',
},
mode: 'production',
devtool: false,
output: {
path: `./dist`,
mode: 'bundle',
},
platform: 'node',
optimization: {
// @ts-ignore
concatenateModules: false,
},
minify: false,
cjs: true,
},
root: process.cwd(),
watch: false,
});

// patch the output file
// replace "src" with __dirname
const outputFile = path.join(process.cwd(), 'dist/cli.js');
assert(fs.existsSync(outputFile), 'Output file not found');
const content = fs.readFileSync(outputFile, 'utf-8');
const newContent = content.replace(/"src"/g, `__dirname`);
// make sure the new content has two "__dirname"
assert(newContent.includes('__dirname'), 'Output file not patched correctly');
fs.writeFileSync(outputFile, newContent);
console.log('Output file patched successfully');
};

(async () => {
await compile();
})().catch(console.error);

0 comments on commit 7b4640c

Please sign in to comment.