From 8ab2b10319219e36cf6a229a4ac898b0b1c1b5d4 Mon Sep 17 00:00:00 2001 From: Nicolas Froidure Date: Wed, 28 Feb 2024 20:59:08 +0100 Subject: [PATCH] fix(@whook/create): fix the npm init script --- .../__snapshots__/createWhook.test.ts.snap | 244 +++++++++--------- .../src/services/createWhook.test.ts | 50 ++-- .../whook-create/src/services/createWhook.ts | 86 +++--- packages/whook/src/services/compiler.test.ts | 6 +- 4 files changed, 191 insertions(+), 195 deletions(-) diff --git a/packages/whook-create/src/services/__snapshots__/createWhook.test.ts.snap b/packages/whook-create/src/services/__snapshots__/createWhook.test.ts.snap index 715757ca..2a0b7b7c 100644 --- a/packages/whook-create/src/services/__snapshots__/createWhook.test.ts.snap +++ b/packages/whook-create/src/services/__snapshots__/createWhook.test.ts.snap @@ -29,23 +29,15 @@ exports[`initCreateWhook should fail with access problems 2`] = ` "oraCalls": [], "oraStartCalls": [], "oraStopAndPersistCalls": [], - "readFileCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], + "outputFileCalls": [ [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", - ], - ], - "readdirCalls": [ - [ - "/var/lib/node/node_modules/whook-example/src/config", + "/home/whoiam/projects/yolo/src/watch.ts", + " +the watch.ts file contents + with'./' replaced so + equal to './'! +", ], - ], - "writeFileCalls": [ [ "/home/whoiam/projects/yolo/README.md", "# super-project @@ -271,14 +263,6 @@ DEV_MODE=1 "/home/whoiam/projects/yolo/LICENSE", "Copyright Wayne Campbell, all rights reserved.", ], - [ - "/home/whoiam/projects/yolo/src/watch.ts", - " -the watch.ts file contents - with'./' replaced so - equal to './'! -", - ], [ "/home/whoiam/projects/yolo/.gitignore", "node_modules @@ -289,6 +273,22 @@ builds/ ", ], ], + "readFileCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], + "readdirCalls": [ + [ + "/var/lib/node/node_modules/whook-example/src/config", + ], + ], } `; @@ -363,29 +363,15 @@ exports[`initCreateWhook should handle git initialization problems 2`] = ` }, ], ], - "readFileCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], - [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", - ], - ], - "readdirCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], + "outputFileCalls": [ [ - "/var/lib/node/node_modules/whook-example/README.md", - ], - [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", + "/home/whoiam/projects/yolo/src/watch.ts", + " +the watch.ts file contents + with'./' replaced so + equal to './'! +", ], - ], - "writeFileCalls": [ [ "/home/whoiam/projects/yolo/README.md", "# super-project @@ -611,14 +597,6 @@ DEV_MODE=1 "/home/whoiam/projects/yolo/LICENSE", "Copyright Wayne Campbell, all rights reserved.", ], - [ - "/home/whoiam/projects/yolo/src/watch.ts", - " -the watch.ts file contents - with'./' replaced so - equal to './'! -", - ], [ "/home/whoiam/projects/yolo/.gitignore", "node_modules @@ -629,6 +607,28 @@ builds/ ", ], ], + "readFileCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], + "readdirCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], } `; @@ -666,31 +666,31 @@ exports[`initCreateWhook should handle network issues 2`] = ` ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/package.json" => "/home/whoiam/projects/yolo/package.json ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/package.json" => "/home/whoiam/projects/yolo/package.json ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/package-lock.json" => "/home/whoiam/projects/yolo/package-lock.json ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/package-lock.json" => "/home/whoiam/projects/yolo/package-lock.json ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/LICENSE" => "/home/whoiam/projects/yolo/LICENSE ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/LICENSE" => "/home/whoiam/projects/yolo/LICENSE ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/dist/index.js" => "/home/whoiam/projects/yolo/dist/index.js ("../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/dist/index.js" => "/home/whoiam/projects/yolo/dist/index.js ("../..").", ], [ "debug", - "Moving "/var/lib/node/node_modules/whook-example/src/index.js" => "/home/whoiam/projects/yolo/src/index.js".", + "💱 - Moving "/var/lib/node/node_modules/whook-example/src/index.js" => "/home/whoiam/projects/yolo/src/index.js".", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/coverage/index.html" => "/home/whoiam/projects/yolo/coverage/index.html ("../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/coverage/index.html" => "/home/whoiam/projects/yolo/coverage/index.html ("../..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/node_modules/whook/index.js" => "/home/whoiam/projects/yolo/node_modules/whook/index.js ("../../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/node_modules/whook/index.js" => "/home/whoiam/projects/yolo/node_modules/whook/index.js ("../../..").", ], [ "error", @@ -735,29 +735,15 @@ exports[`initCreateWhook should handle network issues 2`] = ` }, ], ], - "readFileCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], - [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", - ], - ], - "readdirCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], + "outputFileCalls": [ [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", + "/home/whoiam/projects/yolo/src/watch.ts", + " +the watch.ts file contents + with'./' replaced so + equal to './'! +", ], - ], - "writeFileCalls": [ [ "/home/whoiam/projects/yolo/README.md", "# super-project @@ -983,13 +969,27 @@ DEV_MODE=1 "/home/whoiam/projects/yolo/LICENSE", "Copyright Wayne Campbell, all rights reserved.", ], + ], + "readFileCalls": [ [ - "/home/whoiam/projects/yolo/src/watch.ts", - " -the watch.ts file contents - with'./' replaced so - equal to './'! -", + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], + "readdirCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", ], ], } @@ -1029,31 +1029,31 @@ exports[`initCreateWhook should work 2`] = ` ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/package.json" => "/home/whoiam/projects/yolo/package.json ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/package.json" => "/home/whoiam/projects/yolo/package.json ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/package-lock.json" => "/home/whoiam/projects/yolo/package-lock.json ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/package-lock.json" => "/home/whoiam/projects/yolo/package-lock.json ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/LICENSE" => "/home/whoiam/projects/yolo/LICENSE ("..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/LICENSE" => "/home/whoiam/projects/yolo/LICENSE ("..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/dist/index.js" => "/home/whoiam/projects/yolo/dist/index.js ("../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/dist/index.js" => "/home/whoiam/projects/yolo/dist/index.js ("../..").", ], [ "debug", - "Moving "/var/lib/node/node_modules/whook-example/src/index.js" => "/home/whoiam/projects/yolo/src/index.js".", + "💱 - Moving "/var/lib/node/node_modules/whook-example/src/index.js" => "/home/whoiam/projects/yolo/src/index.js".", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/coverage/index.html" => "/home/whoiam/projects/yolo/coverage/index.html ("../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/coverage/index.html" => "/home/whoiam/projects/yolo/coverage/index.html ("../..").", ], [ "debug", - "Discarding "/var/lib/node/node_modules/whook-example/node_modules/whook/index.js" => "/home/whoiam/projects/yolo/node_modules/whook/index.js ("../../..").", + "💱 - Discarding "/var/lib/node/node_modules/whook-example/node_modules/whook/index.js" => "/home/whoiam/projects/yolo/node_modules/whook/index.js ("../../..").", ], [ "warning", @@ -1090,29 +1090,15 @@ exports[`initCreateWhook should work 2`] = ` }, ], ], - "readFileCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], - [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", - ], - ], - "readdirCalls": [ - [ - "/var/lib/node/node_modules/whook-example/package.json", - ], - [ - "/var/lib/node/node_modules/whook-example/README.md", - ], + "outputFileCalls": [ [ - "/var/lib/node/node_modules/whook-example/src/watch.ts", + "/home/whoiam/projects/yolo/src/watch.ts", + " +the watch.ts file contents + with'./' replaced so + equal to './'! +", ], - ], - "writeFileCalls": [ [ "/home/whoiam/projects/yolo/README.md", "# super-project @@ -1338,14 +1324,6 @@ DEV_MODE=1 "/home/whoiam/projects/yolo/LICENSE", "Copyright Wayne Campbell, all rights reserved.", ], - [ - "/home/whoiam/projects/yolo/src/watch.ts", - " -the watch.ts file contents - with'./' replaced so - equal to './'! -", - ], [ "/home/whoiam/projects/yolo/.gitignore", "node_modules @@ -1356,5 +1334,27 @@ builds/ ", ], ], + "readFileCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], + "readdirCalls": [ + [ + "/var/lib/node/node_modules/whook-example/package.json", + ], + [ + "/var/lib/node/node_modules/whook-example/src/watch.ts", + ], + [ + "/var/lib/node/node_modules/whook-example/README.md", + ], + ], } `; diff --git a/packages/whook-create/src/services/createWhook.test.ts b/packages/whook-create/src/services/createWhook.test.ts index 46d22e73..cc10d148 100644 --- a/packages/whook-create/src/services/createWhook.test.ts +++ b/packages/whook-create/src/services/createWhook.test.ts @@ -54,7 +54,7 @@ describe('initCreateWhook', () => { name: 'super-project', directory: '/home/whoiam/projects/yolo', }; - const writeFile = jest.fn<(file: PathLike, data: Buffer) => Promise>(); + const outputFile = jest.fn<(file: PathLike, data: Buffer) => Promise>(); const readFile = jest.fn<(file: PathLike) => Promise>(); const readdir = jest.fn<(file: PathLike) => Promise>(); const exec = jest.fn(); @@ -69,7 +69,7 @@ describe('initCreateWhook', () => { beforeEach(() => { axios.mockReset(); - writeFile.mockReset(); + outputFile.mockReset(); readFile.mockReset(); readdir.mockReset(); exec.mockReset(); @@ -118,9 +118,9 @@ describe('initCreateWhook', () => { axios.mockResolvedValueOnce({ data: 'node_modules', }); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Initialized an empty git repository!'), ); @@ -133,7 +133,7 @@ describe('initCreateWhook', () => { SOURCE_DIR, author, project, - writeFile: writeFile as any, + outputFile: outputFile as any, readFile: readFile as any, readdir: readdir as any, exec: exec as any, @@ -147,7 +147,7 @@ describe('initCreateWhook', () => { expect( JSON.parse( - writeFile.mock.calls + outputFile.mock.calls .find((call) => call[0].toString().endsWith('package.json'))?.[1] ?.toString() || '', ), @@ -310,7 +310,7 @@ describe('initCreateWhook', () => { `); expect({ copyCalls: copy.mock.calls, - writeFileCalls: writeFile.mock.calls, + outputFileCalls: outputFile.mock.calls, readFileCalls: readFile.mock.calls, execCalls: exec.mock.calls, oraCalls: ora.mock.calls, @@ -342,9 +342,9 @@ describe('initCreateWhook', () => { ), ); axios.mockRejectedValueOnce(new YError('E_NETWORK')); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); exec.mockImplementationOnce((_, _2, cb) => cb(new YError('E_ACCESS'))); exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'), @@ -355,7 +355,7 @@ describe('initCreateWhook', () => { SOURCE_DIR, author, project, - writeFile: writeFile as any, + outputFile: outputFile as any, readFile: readFile as any, readdir: readdir as any, exec: exec as any, @@ -369,7 +369,7 @@ describe('initCreateWhook', () => { expect( JSON.parse( - writeFile.mock.calls + outputFile.mock.calls .find((call) => call[0].toString().endsWith('package.json'))?.[1] ?.toString() || '', ), @@ -532,7 +532,7 @@ describe('initCreateWhook', () => { `); expect({ copyCalls: copy.mock.calls, - writeFileCalls: writeFile.mock.calls, + outputFileCalls: outputFile.mock.calls, readFileCalls: readFile.mock.calls, execCalls: exec.mock.calls, oraCalls: ora.mock.calls, @@ -549,9 +549,9 @@ describe('initCreateWhook', () => { axios.mockResolvedValueOnce({ data: 'node_modules', }); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); exec.mockImplementationOnce((_, _2, cb) => cb(new YError('E_ACCESS'))); exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'), @@ -562,7 +562,7 @@ describe('initCreateWhook', () => { SOURCE_DIR, author, project, - writeFile: writeFile as any, + outputFile: outputFile as any, readFile: readFile as any, readdir: readdir as any, exec: exec as any, @@ -576,7 +576,7 @@ describe('initCreateWhook', () => { expect( JSON.parse( - writeFile.mock.calls + outputFile.mock.calls .find((call) => call[0].toString().endsWith('package.json'))?.[1] ?.toString() || '', ), @@ -739,7 +739,7 @@ describe('initCreateWhook', () => { `); expect({ copyCalls: copy.mock.calls, - writeFileCalls: writeFile.mock.calls, + outputFileCalls: outputFile.mock.calls, readFileCalls: readFile.mock.calls, execCalls: exec.mock.calls, oraCalls: ora.mock.calls, @@ -756,9 +756,9 @@ describe('initCreateWhook', () => { axios.mockResolvedValueOnce({ data: 'node_modules', }); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); - writeFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); + outputFile.mockResolvedValueOnce(undefined); exec.mockImplementationOnce((_, _2, cb) => cb(null, '')); exec.mockImplementationOnce((_, _2, cb) => cb(null, 'Installed dependencies!'), @@ -770,7 +770,7 @@ describe('initCreateWhook', () => { SOURCE_DIR, author, project, - writeFile: writeFile as any, + outputFile: outputFile as any, readFile: readFile as any, readdir: readdir as any, exec: exec as any, @@ -795,7 +795,7 @@ describe('initCreateWhook', () => { `); expect({ copyCalls: copy.mock.calls, - writeFileCalls: writeFile.mock.calls, + outputFileCalls: outputFile.mock.calls, readFileCalls: readFile.mock.calls, execCalls: exec.mock.calls, oraCalls: ora.mock.calls, diff --git a/packages/whook-create/src/services/createWhook.ts b/packages/whook-create/src/services/createWhook.ts index 8d6be18f..250d654f 100644 --- a/packages/whook-create/src/services/createWhook.ts +++ b/packages/whook-create/src/services/createWhook.ts @@ -1,10 +1,11 @@ import { autoService } from 'knifecycle'; -import path from 'path'; +import { exec as _exec } from 'node:child_process'; +import { readFile as _readFile, readdir as _readdir } from 'node:fs/promises'; +import { copy as _copy, outputFile as _outputFile } from 'fs-extra'; +import { join, relative } from 'node:path'; import _axios from 'axios'; import _ora from 'ora'; import { printStackTrace, YError } from 'yerror'; -import { exec as _exec } from 'child_process'; -import { default as fsExtra } from 'fs-extra'; import type { LogService } from 'common-services'; import type { ProjectService } from './project.js'; import type { AuthorService } from './author.js'; @@ -13,12 +14,6 @@ const GIT_IGNORE_URL = 'https://www.toptal.com/developers/gitignore/api/osx,node,linux'; const README_REGEXP = /^(?:[^]*)\[\/\/\]: # \(::contents:start\)\r?\n\r?\n([^]*)\r?\n\r?\n\[\/\/\]: # \(::contents:end\)(?:[^]*)$/gm; -const { - writeFile: _writeFile, - readFile: _readFile, - copy: _copy, - readdir: _readdir, -} = fsExtra; export type CreateWhookService = () => Promise; @@ -27,7 +22,7 @@ export default autoService(async function initCreateWhook({ SOURCE_DIR, author, project, - writeFile = _writeFile, + outputFile = _outputFile, readFile = _readFile, readdir = _readdir, exec = _exec, @@ -40,7 +35,7 @@ export default autoService(async function initCreateWhook({ SOURCE_DIR: string; author: AuthorService; project: ProjectService; - writeFile: typeof _writeFile; + outputFile: typeof _outputFile; readFile: typeof _readFile; readdir: typeof _readdir; exec: typeof _exec; @@ -53,7 +48,7 @@ export default autoService(async function initCreateWhook({ log('warning', "🏁️ - Starting Whook project's creation!"); const basePackageJSON = JSON.parse( - (await readFile(path.join(SOURCE_DIR, 'package.json'))).toString(), + (await readFile(join(SOURCE_DIR, 'package.json'))).toString(), ); const finalPackageJSON = { @@ -89,37 +84,44 @@ export default autoService(async function initCreateWhook({ metapak: undefined, }; + await readFile(join(SOURCE_DIR, 'src/watch.ts')).then((data) => { + return outputFile( + join(project.directory, 'src/watch.ts'), + data.toString().replace('../../', './'), + ); + }); + await Promise.all([ copy(SOURCE_DIR, project.directory, { filter: (src, dest) => { if ( - src.startsWith(path.join(SOURCE_DIR, 'node_modules')) || - src.startsWith(path.join(SOURCE_DIR, 'dist')) || - src.startsWith(path.join(SOURCE_DIR, 'coverage')) || + src.startsWith(join(SOURCE_DIR, 'node_modules')) || + src.startsWith(join(SOURCE_DIR, 'dist')) || + src.startsWith(join(SOURCE_DIR, 'coverage')) || [ - path.join(SOURCE_DIR, 'package.json'), - path.join(SOURCE_DIR, 'package-lock.json'), - path.join(SOURCE_DIR, 'LICENSE'), - path.join(SOURCE_DIR, 'README.md'), - path.join(SOURCE_DIR, 'src/watch.ts'), + join(SOURCE_DIR, 'package.json'), + join(SOURCE_DIR, 'package-lock.json'), + join(SOURCE_DIR, 'LICENSE'), + join(SOURCE_DIR, 'README.md'), + join(SOURCE_DIR, 'src/watch.ts'), ].includes(src) ) { log( 'debug', - `Discarding "${src}" => "${dest} ("${path.relative( + `💱 - Discarding "${src}" => "${dest} ("${relative( src, SOURCE_DIR, )}").`, ); return false; } - log('debug', `Moving "${src}" => "${dest}".`); + log('debug', `💱 - Moving "${src}" => "${dest}".`); return true; }, }), - readFile(path.join(SOURCE_DIR, 'README.md')).then((data) => - writeFile( - path.join(project.directory, 'README.md'), + readFile(join(SOURCE_DIR, 'README.md')).then((data) => + outputFile( + join(project.directory, 'README.md'), `# ${project.name} ${data.toString().replace(README_REGEXP, '$1')} @@ -130,12 +132,12 @@ ${author.name} `, ), ), - ...(await readdir(path.join(SOURCE_DIR, 'src', 'config'))).map( + ...(await readdir(join(SOURCE_DIR, 'src', 'config'))).map( (environment) => environment === 'common' ? Promise.resolve() - : writeFile( - path.join(project.directory, `.env.app.${environment}`), + : outputFile( + join(project.directory, `.env.app.${environment}`), `# Loaded when APP_ENV=${environment} # For JWT signing @@ -143,8 +145,8 @@ JWT_SECRET=oudelali `, ), ), - writeFile( - path.join(project.directory, '.env.node.development'), + outputFile( + join(project.directory, '.env.node.development'), `# Loaded when NODE_ENV=development # Allow to kill the process with still open sockets @@ -154,18 +156,12 @@ DESTROY_SOCKETS=1' DEV_MODE=1 `, ), - writeFile( - path.join(project.directory, 'package.json'), + outputFile( + join(project.directory, 'package.json'), JSON.stringify(finalPackageJSON, null, 2), ), - readFile(path.join(SOURCE_DIR, 'src/watch.ts')).then((data) => { - return writeFile( - path.join(project.directory, 'src/watch.ts'), - data.toString().replace('../../', './'), - ); - }), - writeFile( - path.join(project.directory, 'tsconfig.json'), + outputFile( + join(project.directory, 'tsconfig.json'), JSON.stringify( { compilerOptions: { @@ -189,8 +185,8 @@ DEV_MODE=1 2, ), ), - writeFile( - path.join(project.directory, 'LICENSE'), + outputFile( + join(project.directory, 'LICENSE'), `Copyright ${author.name}, all rights reserved.`, ), axios({ @@ -202,8 +198,8 @@ DEV_MODE=1 }, }) .then((response) => - writeFile( - path.join(project.directory, '.gitignore'), + outputFile( + join(project.directory, '.gitignore'), `${response.data.toString()} # Whook's files @@ -277,7 +273,7 @@ builds/ log( 'warning', - `➕ - Run \`cd ${path.relative( + `➕ - Run \`cd ${relative( CWD, project.directory, )}\` to enter the project.`, diff --git a/packages/whook/src/services/compiler.test.ts b/packages/whook/src/services/compiler.test.ts index 9b07d7a3..e482f096 100644 --- a/packages/whook/src/services/compiler.test.ts +++ b/packages/whook/src/services/compiler.test.ts @@ -42,7 +42,7 @@ describe('Compiler', () => { logCalls: log.mock.calls, }).toMatchInlineSnapshot(` { - "contentsLength": 48297, + "contentsLength": 48080, "extension": ".mjs", "logCalls": [], "mappingsLength": 0, @@ -72,7 +72,7 @@ describe('Compiler', () => { logCalls: log.mock.calls, }).toMatchInlineSnapshot(` { - "contentsLength": 3684, + "contentsLength": 3608, "extension": ".mjs", "logCalls": [], "mappingsLength": 0, @@ -106,7 +106,7 @@ describe('Compiler', () => { logCalls: log.mock.calls, }).toMatchInlineSnapshot(` { - "contentsLength": 5282, + "contentsLength": 5206, "extension": ".cjs", "logCalls": [], "mappingsLength": 0,