Skip to content

Commit 9570923

Browse files
committed
fix(template): fix config template problem
- The `eject` command now creates a template file in the `templatePath` option instead of `output`. - This change was made because the `output` option is redundant with the `output` option of the `build` command, and because the `output` directory was being mixed up with templates and documentation when using `.erdiarc` files.
1 parent e3186f3 commit 9570923

File tree

16 files changed

+96
-60
lines changed

16 files changed

+96
-60
lines changed

src/common/__tests__/version.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getFileVersion } from '#/common/getFileVersion';
22
import { getVersion } from '#/common/getVersion';
33
import * as getFindFile from '#/modules/files/getFindFile';
4-
import * as getOutputDirectory from '#/modules/files/getOutputDirectory';
4+
import * as getOutputDirPath from '#/modules/files/getOutputDirPath';
55
import dayjs from 'dayjs';
66
import fs from 'fs';
77
import { describe, expect, test, vitest } from 'vitest';
@@ -78,7 +78,7 @@ describe('getVersion', () => {
7878
.spyOn(fs.promises, 'readFile')
7979
.mockImplementation(() => Promise.resolve(Buffer.from('1.1.1')));
8080
const tspSpyOn04 = vitest
81-
.spyOn(getOutputDirectory, 'getOutputDirectory')
81+
.spyOn(getOutputDirPath, 'getOutputDirPath')
8282
.mockImplementation(() => Promise.resolve('/a/b/c'));
8383

8484
const version = await getVersion({ version: '1.1.1' }, { versionFrom: 'file', versionPath: '/a/b/c' });

src/common/getVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CE_DEFAULT_VALUE } from '#/configs/const-enum/CE_DEFAULT_VALUE';
33
import type { IBuildCommandOption } from '#/configs/interfaces/IBuildCommandOption';
44
import { getCwd } from '#/configs/modules/getCwd';
55
import { getFindFile } from '#/modules/files/getFindFile';
6-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
6+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
77
import dayjs from 'dayjs';
88
import fs from 'fs';
99
import pathe from 'pathe';
@@ -14,7 +14,7 @@ async function getVersionFilename(
1414
) {
1515
if (option.versionPath != null) {
1616
const filename = await getFindFile(
17-
pathe.join(await getOutputDirectory({ output: option.versionPath }, getCwd(process.env)), versionFilename),
17+
pathe.join(await getOutputDirPath({ output: option.versionPath }, getCwd(process.env)), versionFilename),
1818
{ cwd: getCwd(process.env) },
1919
);
2020

src/configs/modules/getConfigContent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export async function getConfigContent() {
3636
*/
3737

3838
const sourceGlobFiles = new Glob(['**/*.js', '**/*.cjs', '**/*.mjs', '**/*.ts', '**/*.cts', '**/*.mts'], {
39-
absolute: true,
39+
// absolute: true,
4040
ignore: defaultExclude,
4141
cwd: process.cwd(),
4242
onlyFiles: true,
4343
});
4444
const sourceFiles = getGlobFiles(sourceGlobFiles);
4545

4646
const everyGlobFiles = new Glob(['**/*'], {
47-
absolute: true,
47+
// absolute: true,
4848
ignore: defaultExclude,
4949
cwd: process.cwd(),
5050
dot: true,
@@ -53,7 +53,7 @@ export async function getConfigContent() {
5353
const everyFiles = getGlobFiles(everyGlobFiles);
5454

5555
const directoryGlobDirPaths = new Glob(['**/*'], {
56-
absolute: true,
56+
// absolute: true,
5757
ignore: defaultExclude,
5858
cwd: process.cwd(),
5959
dot: true,
@@ -214,7 +214,7 @@ export async function getConfigContent() {
214214
]);
215215

216216
const templateDir = await (answer.isEjectTemplate
217-
? ejecting({ output: getCwd(process.env), showLogo: false })
217+
? ejecting({ templatePath: pathe.join(getCwd(process.env), CE_DEFAULT_VALUE.TEMPLATES_PATH), showLogo: false })
218218
: Promise.resolve(undefined));
219219
const renderer = container.resolve<TemplateRenderer>(SymbolTemplateRenderer);
220220
const file = await renderer.evaluate(CE_TEMPLATE_NAME.CONFIG_JSON, {

src/creators/createHtml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { getRenderData } from '#/creators/getRenderData';
77
import type { IErdiaDocument } from '#/creators/interfaces/IErdiaDocument';
88
import { container } from '#/modules/containers/container';
99
import { SymbolTemplateRenderer } from '#/modules/containers/keys/SymbolTemplateRenderer';
10-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
10+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
1111
import type { TemplateRenderer } from '#/templates/TemplateRenderer';
1212
import { CE_TEMPLATE_NAME } from '#/templates/cosnt-enum/CE_TEMPLATE_NAME';
1313
import consola from 'consola';
@@ -65,7 +65,7 @@ export async function createHtml(
6565
option: Pick<IBuildCommandOption, 'output' | 'components' | 'prettierConfig'>,
6666
renderData: AsyncReturnType<typeof getRenderData>,
6767
) {
68-
const outputDir = await getOutputDirectory(option, getCwd(process.env));
68+
const outputDir = await getOutputDirPath(option, getCwd(process.env));
6969

7070
consola.info(`export component: ${option.components.join(', ')}`);
7171

src/creators/createMarkdown.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { IBuildCommandOption } from '#/configs/interfaces/IBuildCommandOption';
2+
import { getCwd } from '#/configs/modules/getCwd';
23
import { applyPrettier } from '#/creators/applyPretter';
34
import type { getRenderData } from '#/creators/getRenderData';
45
import type { IErdiaDocument } from '#/creators/interfaces/IErdiaDocument';
56
import { container } from '#/modules/containers/container';
67
import { SymbolTemplateRenderer } from '#/modules/containers/keys/SymbolTemplateRenderer';
8+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
79
import type { TemplateRenderer } from '#/templates/TemplateRenderer';
810
import { CE_TEMPLATE_NAME } from '#/templates/cosnt-enum/CE_TEMPLATE_NAME';
9-
import { getDirname } from 'my-node-fp';
1011
import pathe from 'pathe';
1112
import type { AsyncReturnType } from 'type-fest';
1213

@@ -18,7 +19,7 @@ export async function createMarkdown(
1819
const rawMarkdown = await renderer.evaluate(CE_TEMPLATE_NAME.MARKDOWN_DOCUMENT, renderData);
1920
const prettiedMarkdown = await applyPrettier(rawMarkdown, 'md', option.prettierConfig);
2021
const markdownFileName = `${renderData.metadata.name}.md`;
21-
const outputDir = await getDirname(option.output ?? process.cwd());
22+
const outputDir = await getOutputDirPath(option, getCwd(process.env));
2223

2324
return {
2425
filename: pathe.resolve(pathe.join(outputDir, markdownFileName)),

src/databases/flushDatabase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { CE_DEFAULT_VALUE } from '#/configs/const-enum/CE_DEFAULT_VALUE';
22
import type { IBuildCommandOption } from '#/configs/interfaces/IBuildCommandOption';
33
import type { TDatabaseRecord } from '#/databases/interfaces/TDatabaseRecord';
4-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
4+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
55
import fs from 'node:fs';
66
import pathe from 'pathe';
77

88
export async function flushDatabase(
99
option: Pick<IBuildCommandOption, 'databasePath'>,
1010
records: TDatabaseRecord[],
1111
): Promise<TDatabaseRecord[]> {
12-
const dirname = await getOutputDirectory({ output: option.databasePath }, process.cwd());
12+
const dirname = await getOutputDirPath({ output: option.databasePath }, process.cwd());
1313
const filename = pathe.join(dirname, CE_DEFAULT_VALUE.DATABASE_FILENAME);
1414

1515
if (filename == null) {

src/databases/openDatabase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { CE_DEFAULT_VALUE } from '#/configs/const-enum/CE_DEFAULT_VALUE';
22
import type { IBuildCommandOption } from '#/configs/interfaces/IBuildCommandOption';
33
import type { TDatabaseRecord } from '#/databases/interfaces/TDatabaseRecord';
4-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
4+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
55
import { parse } from 'jsonc-parser';
66
import { isFalse } from 'my-easy-fp';
77
import { exists } from 'my-node-fp';
88
import fs from 'node:fs';
99
import pathe from 'pathe';
1010

1111
export async function openDatabase(option: Pick<IBuildCommandOption, 'databasePath'>): Promise<TDatabaseRecord[]> {
12-
const dirname = await getOutputDirectory({ output: option.databasePath }, process.cwd());
12+
const dirname = await getOutputDirPath({ output: option.databasePath }, process.cwd());
1313
const filename = pathe.join(dirname, CE_DEFAULT_VALUE.DATABASE_FILENAME);
1414

1515
if (filename == null) {

src/modules/commands/cleaning.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ICommonOption } from '#/configs/interfaces/ICommonOption';
44
import { getCwd } from '#/configs/modules/getCwd';
55
import { container } from '#/modules/containers/container';
66
import { SymbolDataSource } from '#/modules/containers/keys/SymbolDataSource';
7-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
7+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
88
import { getDataSource } from '#/typeorm/getDataSource';
99
import { showLogo } from '@maeum/cli-logo';
1010
import { asValue } from 'awilix';
@@ -37,7 +37,7 @@ export async function cleaning(option: ICommonOption) {
3737
container.register(SymbolDataSource, asValue(dataSource));
3838

3939
const metadata = await getMetadata({ ...option, versionFrom: 'package.json', projectName: 'app' });
40-
const outputDirPath = await getOutputDirectory(option, getCwd(process.env));
40+
const outputDirPath = await getOutputDirPath(option, getCwd(process.env));
4141

4242
const filenames = [
4343
pathe.join(outputDirPath, CE_DEFAULT_VALUE.HTML_MERMAID_FILENAME),

src/modules/commands/ejecting.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import { CE_DEFAULT_VALUE } from '#/configs/const-enum/CE_DEFAULT_VALUE';
22
import type { ICommonOption } from '#/configs/interfaces/ICommonOption';
3+
import type { IDocumentOption } from '#/configs/interfaces/IDocumentOption';
34
import { getCwd } from '#/configs/modules/getCwd';
45
import { container } from '#/modules/containers/container';
56
import { SymbolLogger } from '#/modules/containers/keys/SymbolLogger';
67
import { betterMkdir } from '#/modules/files/betterMkdir';
78
import { getGlobFiles } from '#/modules/files/getGlobFiles';
8-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
9+
import { getTemplateDirPath } from '#/modules/files/getTemplateDirPath';
910
import type { Logger } from '#/modules/loggers/Logger';
1011
import { createLogger } from '#/modules/loggers/createLogger';
1112
import { defaultExclude } from '#/modules/scopes/defaultExclude';
12-
import { getTemplatePath } from '#/templates/modules/getTemplatePath';
13+
import { getTemplateModulePath } from '#/templates/modules/getTemplateModulePath';
1314
import { Glob } from 'glob';
1415
import { isError } from 'my-easy-fp';
1516
import { getDirname, startSepRemove } from 'my-node-fp';
1617
import fs from 'node:fs';
1718
import pathe from 'pathe';
1819

19-
export async function ejecting(option: Pick<ICommonOption, 'output' | 'showLogo'>, logging?: boolean) {
20+
export async function ejecting(
21+
option: Pick<ICommonOption & IDocumentOption, 'showLogo' | 'templatePath'>,
22+
logging?: boolean,
23+
) {
2024
createLogger(logging);
2125
const logger = container.resolve<Logger>(SymbolLogger);
2226

2327
try {
24-
const outputDirPath = await getOutputDirectory(option, getCwd(process.env));
25-
const originTemplateDirPath = await getTemplatePath(CE_DEFAULT_VALUE.TEMPLATES_PATH);
28+
const templateDirPath = await getTemplateDirPath(option, getCwd(process.env));
29+
const originTemplateDirPath = await getTemplateModulePath(CE_DEFAULT_VALUE.TEMPLATES_PATH);
2630
const targetTemplateDirPath =
27-
option.output == null ? pathe.join(outputDirPath, CE_DEFAULT_VALUE.TEMPLATES_PATH) : outputDirPath;
31+
option.templatePath == null ? pathe.join(templateDirPath, CE_DEFAULT_VALUE.TEMPLATES_PATH) : templateDirPath;
2832

29-
logger.info('Output directory: ', targetTemplateDirPath);
33+
logger.info('Template directory: ', targetTemplateDirPath);
3034

3135
const originTemplateGlobPaths = new Glob(pathe.join(originTemplateDirPath, `**`, '*.eta'), {
3236
absolute: true,

src/modules/files/__tests__/file.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getOutputDirectory } from '#/modules/files/getOutputDirectory';
1+
import { getOutputDirPath } from '#/modules/files/getOutputDirPath';
22
import { getPuppeteerConfig } from '#/modules/getPuppeteerConfig';
33
import { getSlashEndRoutePath } from '#/modules/getSlashEndRoutePath';
44
import * as mnf from 'my-node-fp';
@@ -31,7 +31,7 @@ describe('getOutputDirectory', () => {
3131
const existsSpyOn = vitest.spyOn(mnf, 'exists').mockImplementation(() => Promise.resolve(false));
3232
const mkdirSpyOn = vitest.spyOn(fs.promises, 'mkdir').mockImplementation(() => Promise.resolve(''));
3333

34-
const p = await getOutputDirectory({ output: undefined }, 'i-am-cwd');
34+
const p = await getOutputDirPath({ output: undefined }, 'i-am-cwd');
3535

3636
existsSpyOn.mockRestore();
3737
mkdirSpyOn.mockRestore();
@@ -44,7 +44,7 @@ describe('getOutputDirectory', () => {
4444
const isDirectorySpyOn = vitest.spyOn(mnf, 'isDirectory').mockImplementation(() => Promise.resolve(false));
4545
const mkdirSpyOn = vitest.spyOn(fs.promises, 'mkdir').mockImplementation(() => Promise.resolve(''));
4646

47-
const p = await getOutputDirectory({ output: undefined }, 'examples');
47+
const p = await getOutputDirPath({ output: undefined }, 'examples');
4848

4949
existsSpyOn.mockRestore();
5050
isDirectorySpyOn.mockRestore();
@@ -58,7 +58,7 @@ describe('getOutputDirectory', () => {
5858
const isDirectorySpyOn = vitest.spyOn(mnf, 'isDirectory').mockImplementation(() => Promise.resolve(true));
5959
const mkdirSpyOn = vitest.spyOn(fs.promises, 'mkdir').mockImplementation(() => Promise.resolve(''));
6060

61-
const p = await getOutputDirectory({ output: undefined }, 'examples');
61+
const p = await getOutputDirPath({ output: undefined }, 'examples');
6262

6363
existsSpyOn.mockRestore();
6464
isDirectorySpyOn.mockRestore();

0 commit comments

Comments
 (0)