diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 67f4267..188f461 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -25,7 +25,7 @@ body: id: logs attributes: label: Logs - description: "Please include browser console and server logs around the time this bug occurred. Please try not to insert an image but copy paste the log text." + description: 'Please include browser console and server logs around the time this bug occurred. Please try not to insert an image but copy paste the log text.' render: Shell - type: dropdown id: severity diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index e91fd4f..62e9ddd 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,4 +1,4 @@ -name: "Feature Request" +name: 'Feature Request' description: Suggest an idea for this project body: - type: markdown diff --git a/README.md b/README.md index 18accf0..8bf1451 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ $ pnpm preview - `tnf dev`: Start the development server. - `tnf generate/g `: Generate a new page (or component and other types in the future). - `tnf preview`: Preview the product after building the project. +- `tnf sync`: Sync the project to the temporary directory. ## API diff --git a/src/build.ts b/src/build.ts index eeb78b7..872fc46 100644 --- a/src/build.ts +++ b/src/build.ts @@ -3,7 +3,7 @@ import chokidar from 'chokidar'; import path from 'pathe'; import type { Config } from './config'; import { FRAMEWORK_NAME } from './constants'; -import { prepare } from './prepare'; +import { sync } from './sync'; export async function build({ cwd, @@ -18,15 +18,15 @@ export async function build({ }) { const tmpPath = path.join(cwd, `src/.${FRAMEWORK_NAME}`); - const doPrepare = async () => { - await prepare({ + const doSync = async () => { + await sync({ cwd, tmpPath, config, }); }; - await doPrepare(); + await doSync(); if (watch) { const pagesDir = path.join(cwd, 'src/pages'); @@ -36,7 +36,7 @@ export async function build({ }) .on('all', async (event, path) => { console.log(`File ${path} has been ${event}`); - await doPrepare(); + await doSync(); }); } diff --git a/src/cli.ts b/src/cli.ts index 78bd268..4f33937 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,4 +1,5 @@ import assert from 'assert'; +import path from 'pathe'; import yargsParser from 'yargs-parser'; import { loadConfig } from './config.js'; import { FRAMEWORK_NAME, MIN_NODE_VERSION } from './constants.js'; @@ -50,6 +51,14 @@ async function run(cwd: string) { type, name, }); + case 'sync': + const { sync } = await import('./sync.js'); + const tmpPath = path.join(cwd, `src/.${FRAMEWORK_NAME}`); + return sync({ + cwd, + tmpPath, + config: await loadConfig({ cwd }), + }); default: throw new Error(`Unknown command: ${cmd}`); } diff --git a/src/prepare.ts b/src/sync.ts similarity index 95% rename from src/prepare.ts rename to src/sync.ts index fe0c3df..41371b0 100644 --- a/src/prepare.ts +++ b/src/sync.ts @@ -10,9 +10,9 @@ interface BaseOptions { config?: TnfConfig; } -interface PrepareOptions extends BaseOptions {} +interface SyncOptions extends BaseOptions {} -export async function prepare(opts: PrepareOptions) { +export async function sync(opts: SyncOptions) { const { cwd, tmpPath, config } = opts; fs.rmSync(tmpPath, { recursive: true, force: true }); diff --git a/templates/simple/package.json b/templates/simple/package.json index 9d7f739..56c744b 100644 --- a/templates/simple/package.json +++ b/templates/simple/package.json @@ -1,10 +1,10 @@ { - "name": "myapp", "private": true, "scripts": { - "build": "tnf build", "dev": "tnf dev", - "preview": "tnf preview" + "build": "tnf build", + "preview": "tnf preview", + "postinstall": "tnf sync" }, "dependencies": { "@types/react": "^18.3.12",