Skip to content

Commit

Permalink
refactor(app-builder): stop using barrel files
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 5, 2024
1 parent c42b781 commit f8b310b
Show file tree
Hide file tree
Showing 89 changed files with 280 additions and 307 deletions.
5 changes: 3 additions & 2 deletions apps/app-builder/src/__tests__/createTestContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Command} from 'commander';
import {type RecursivePartial} from '@myparcel/ts-utils';
import {createDebugger, mergeDefaultConfig} from '../utils';
import {type CommandArgs, type PdkBuilderContext} from '../types';
import {mergeDefaultConfig} from '../utils/mergeDefaultConfig';
import {createDebugger} from '../utils/command/createDebugger';
import {type CommandArgs, type PdkBuilderContext} from '../types/command';
import {PdkPlatformName} from '../constants';
import {MOCK_ROOT_DIR} from './constants';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type RecursivePartial} from '@myparcel/ts-utils';
import {type PdkBuilderContext} from '../types';
import {type PdkBuilderContext} from '../types/command';
import {createTestContext} from './createTestContext';

export const createTestContextWithMockedFs = (
Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/__tests__/mockFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import {type TestContext, vi} from 'vitest';
import {isObject, merge} from 'lodash-unified';
import {exists} from '../utils';
import {exists} from '../utils/fs/exists';
import {MOCK_ROOT_DIR} from './constants';

const DEFAULT_FILE_SYSTEM = Object.freeze({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type TestContext} from 'vitest';
import {type RecursivePartial} from '@myparcel/ts-utils';
import {type PdkBuilderContext} from '../types';
import {type PdkBuilderContext} from '../types/command';
import {mockFileSystem} from './mockFileSystem';
import {createTestContextWithMockedFs} from './createTestContextWithMockedFs';

Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/clean.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest';
import {exists} from '../utils';
import {exists} from '../utils/fs/exists';
import {fsModifyingMethodSpies} from '../__tests__/spies/fs';
import {mockFileSystemAndCreateContext} from '../__tests__/mockFileSystemAndCreateContext';
import clean from './clean';
Expand Down
4 changes: 2 additions & 2 deletions apps/app-builder/src/commands/clean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {rmDir} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {rmDir} from '../utils/fs/rmDir';
import {type PdkBuilderCommand} from '../types/command';

const clean: PdkBuilderCommand = async (context) => {
await rmDir(context.config.outDir, context);
Expand Down
24 changes: 11 additions & 13 deletions apps/app-builder/src/commands/copy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import chalk from 'chalk';
import {
addPlatformToContext,
copyFile,
copyScopedFiles,
executePromises,
getPlatformDistPath,
globFiles,
logPlatforms,
logTargetPath,
resolvePath,
resolveStrings,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {resolveStrings} from '../utils/resolveStrings';
import {resolvePath} from '../utils/resolvePath';
import {globFiles} from '../utils/globFiles';
import {getPlatformDistPath} from '../utils/getPlatformDistPath';
import {copyFile} from '../utils/fs/copyFile';
import {executePromises} from '../utils/executePromises';
import {logTargetPath} from '../utils/debug/logTargetPath';
import {logPlatforms} from '../utils/debug/logPlatforms';
import {copyScopedFiles} from '../utils/copyScopedFiles';
import {addPlatformToContext} from '../utils/addPlatformToContext';
import {type PdkBuilderCommand} from '../types/command';

const copy: PdkBuilderCommand = async (context) => {
const {config, args, debug} = context;
Expand Down
16 changes: 7 additions & 9 deletions apps/app-builder/src/commands/dumpAutoload.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
addPlatformToContext,
executeCommand,
getPlatformDistPath,
getRelativePath,
resolvePath,
rmFile,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {resolvePath} from '../utils/resolvePath';
import {getRelativePath} from '../utils/getRelativePath';
import {getPlatformDistPath} from '../utils/getPlatformDistPath';
import {rmFile} from '../utils/fs/rmFile';
import {executeCommand} from '../utils/executeCommand';
import {addPlatformToContext} from '../utils/addPlatformToContext';
import {type PdkBuilderCommand} from '../types/command';

const dumpAutoload: PdkBuilderCommand = async (context) => {
const {config, debug} = context;
Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import fs from 'fs';
import {describe, expect, it} from 'vitest';
import {parseJsonFile} from '../utils';
import {parseJsonFile} from '../utils/parseJsonFile';
import {fsModifyingMethodSpies} from '../__tests__/spies/fs';
import {mockFileSystemAndCreateContext} from '../__tests__/mockFileSystemAndCreateContext';
import increment from './increment';
Expand Down
33 changes: 14 additions & 19 deletions apps/app-builder/src/commands/increment.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import chalk from 'chalk';
import {isOfType} from '@myparcel/ts-utils';
import {
executePromises,
exists,
getFileContents,
globFiles,
isVerbose,
logSourcePath,
reportFileDoesNotExist,
resolvePath,
usesPhpScoper,
writeFile,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {
type RegexVersionSource,
replaceVersionByRegex,
replaceVersionInJson,
type VersionReplacerOutput,
} from '../increment';
import {usesPhpScoper} from '../utils/usesPhpScoper';
import {resolvePath} from '../utils/resolvePath';
import {globFiles} from '../utils/globFiles';
import {writeFile} from '../utils/fs/writeFile';
import {getFileContents} from '../utils/fs/getFileContents';
import {exists} from '../utils/fs/exists';
import {executePromises} from '../utils/executePromises';
import {reportFileDoesNotExist} from '../utils/debug/reportOnFile';
import {logSourcePath} from '../utils/debug/logSourcePath';
import {isVerbose} from '../utils/command/isVerbose';
import {type PdkBuilderCommand} from '../types/command';
import {type RegexVersionSource, type VersionReplacerOutput} from '../increment/types';
import {replaceVersionInJson} from '../increment/replaceVersionInJson';
import {replaceVersionByRegex} from '../increment/replaceVersionByRegex';
import {REGEX_VERSION} from '../constants';

const increment: PdkBuilderCommand = async (context) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs';
import {type PdkBuilderCommandWithoutConfig} from '../types';
import {type PdkBuilderCommandWithoutConfig} from '../types/command';

const TEMPLATE = `import type {PdkBuilderConfig} from '@myparcel-pdk/app-builder';
import {name, version} from './package.json' assert {type: 'json'};
Expand Down
23 changes: 10 additions & 13 deletions apps/app-builder/src/commands/rename.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* eslint-disable max-lines-per-function */
import path from 'path';
import chalk from 'chalk';
import {
addPlatformToContext,
executePromises,
getPlatformDistPath,
globFiles,
logRelativePath,
renameFile,
replaceCaseSensitive,
resolvePath,
validateDistPath,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {validateDistPath} from '../utils/validateDistPath';
import {replaceCaseSensitive} from '../utils/transformer/replaceCaseSensitive';
import {resolvePath} from '../utils/resolvePath';
import {globFiles} from '../utils/globFiles';
import {getPlatformDistPath} from '../utils/getPlatformDistPath';
import {renameFile} from '../utils/fs/renameFile';
import {executePromises} from '../utils/executePromises';
import {logRelativePath} from '../utils/debug/logRelativePath';
import {addPlatformToContext} from '../utils/addPlatformToContext';
import {type PdkBuilderCommand} from '../types/command';

const STRING_TO_REPLACE = 'myparcelnl';

Expand Down
6 changes: 4 additions & 2 deletions apps/app-builder/src/commands/scopePhp/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from 'path';
import {exists, resolveString, usesPhpScoper} from '../../utils';
import {type PdkBuilderCommand} from '../../types';
import {usesPhpScoper} from '../../utils/usesPhpScoper';
import {resolveString} from '../../utils/resolveString';
import {exists} from '../../utils/fs/exists';
import {type PdkBuilderCommand} from '../../types/command';
import {runPhpScoper} from './runPhpScoper';
import {installPhpScoper} from './installPhpScoper';

Expand Down
8 changes: 6 additions & 2 deletions apps/app-builder/src/commands/scopePhp/installPhpScoper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {executeCommand, exists, mkdirs, resolvePath, resolveString} from '../../utils';
import {type PdkBuilderContext} from '../../types';
import {resolveString} from '../../utils/resolveString';
import {resolvePath} from '../../utils/resolvePath';
import {mkdirs} from '../../utils/fs/mkdirs';
import {exists} from '../../utils/fs/exists';
import {executeCommand} from '../../utils/executeCommand';
import {type PdkBuilderContext} from '../../types/command';
import {VerbosityLevel} from '../../constants';
import {PACKAGE_NAME} from './constants';

Expand Down
9 changes: 7 additions & 2 deletions apps/app-builder/src/commands/scopePhp/runPhpScoper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {executeCommand, exists, isEmptyDir, mkdirs, resolvePath, resolveString} from '../../utils';
import {type PdkBuilderContext} from '../../types';
import {resolveString} from '../../utils/resolveString';
import {resolvePath} from '../../utils/resolvePath';
import {mkdirs} from '../../utils/fs/mkdirs';
import {isEmptyDir} from '../../utils/fs/isEmptyDir';
import {exists} from '../../utils/fs/exists';
import {executeCommand} from '../../utils/executeCommand';
import {type PdkBuilderContext} from '../../types/command';

export const runPhpScoper = async (context: PdkBuilderContext, outDir: string, config?: string): Promise<void> => {
const {debug} = context;
Expand Down
4 changes: 2 additions & 2 deletions apps/app-builder/src/commands/scopePhp/scopePhp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import scopePhp from './index';
import * as child_process from 'child_process';
import {describe, expect, it, vi} from 'vitest';
import {resolveString} from '../../utils';
import {type PdkBuilderContext} from '../../types';
import {resolveString} from '../../utils/resolveString';
import {type PdkBuilderContext} from '../../types/command';
import {fsModifyingMethodSpies} from '../../__tests__/spies/fs';
import {mockFileSystemAndCreateContext} from '../../__tests__/mockFileSystemAndCreateContext';
import {PACKAGE_NAME} from './constants';
Expand Down
31 changes: 14 additions & 17 deletions apps/app-builder/src/commands/transform.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/* eslint-disable max-lines-per-function */
import chalk from 'chalk';
import {
addPlatformToContext,
executePromises,
getFileContents,
getOccurrences,
globFiles,
isVeryVeryVerbose,
logPlatforms,
logSourcePath,
logTargetPath,
replaceCaseSensitive,
resolvePath,
validateDistPath,
writeFile,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {validateDistPath} from '../utils/validateDistPath';
import {replaceCaseSensitive} from '../utils/transformer/replaceCaseSensitive';
import {getOccurrences} from '../utils/transformer/getOccurrences';
import {resolvePath} from '../utils/resolvePath';
import {globFiles} from '../utils/globFiles';
import {writeFile} from '../utils/fs/writeFile';
import {getFileContents} from '../utils/fs/getFileContents';
import {executePromises} from '../utils/executePromises';
import {logTargetPath} from '../utils/debug/logTargetPath';
import {logSourcePath} from '../utils/debug/logSourcePath';
import {logPlatforms} from '../utils/debug/logPlatforms';
import {isVeryVeryVerbose} from '../utils/command/isVeryVeryVerbose';
import {addPlatformToContext} from '../utils/addPlatformToContext';
import {type PdkBuilderCommand} from '../types/command';
import {PdkPlatformName} from '../constants';

const SOURCE_PLATFORM = PdkPlatformName.MyParcelNl;
Expand Down
21 changes: 9 additions & 12 deletions apps/app-builder/src/commands/translations.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* eslint-disable max-lines-per-function,@typescript-eslint/no-magic-numbers */
import fs from 'fs';
import chalk from 'chalk';
import {type ImportSheetConfig, importTranslations} from '@edielemoine/google-docs-importer';
import {
executePromises,
getRelativePath,
isVerbose,
isVeryVerbose,
parseJsonFile,
resolvePath,
rmDir,
writeFile,
} from '../utils';
import {type PdkBuilderCommand} from '../types';
import {resolvePath} from '../utils/resolvePath';
import {parseJsonFile} from '../utils/parseJsonFile';
import {getRelativePath} from '../utils/getRelativePath';
import {writeFile} from '../utils/fs/writeFile';
import {rmDir} from '../utils/fs/rmDir';
import {executePromises} from '../utils/executePromises';
import {isVeryVerbose} from '../utils/command/isVeryVerbose';
import {isVerbose} from '../utils/command/isVerbose';
import {type PdkBuilderCommand} from '../types/command';
import {PLATFORM_SHEET_ID_MAP} from '../constants';

interface SheetDefinition extends ImportSheetConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type ParsedEntry, type UpgradeSubContext} from '../types';
import {parseGitHubUrl} from '../parseGitHubUrl';
import {executeCommand} from '../../../utils';
import {executeCommand} from '../../../utils/executeCommand';

export const getComposerPackageVersion = async (context: UpgradeSubContext): Promise<ParsedEntry[]> => {
const {config, packageName} = context;
Expand Down
2 changes: 0 additions & 2 deletions apps/app-builder/src/commands/upgrade/composer/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type UpgradeSubMethod} from '../types';
import {executeCommand} from '../../../utils';
import {executeCommand} from '../../../utils/executeCommand';
import {getComposerPackageVersion} from './getComposerPackageVersion';

export const upgradeComposerPackage: UpgradeSubMethod = async (context) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/app-builder/src/commands/upgrade/ensureCleanLockfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Debugger} from 'debug';
import {executeCommand} from '../../utils';
import {type ExecuteCommandContext} from '../../types';
import {executeCommand} from '../../utils/executeCommand';
import {type ExecuteCommandContext} from '../../types/command';

export const ensureCleanLockfile = async (
lockfilePath: string,
Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/upgrade/getCommitType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import diff from 'semver/functions/diff.js';
import {type PdkBuilderContext} from '../../types';
import {type PdkBuilderContext} from '../../types/command';
import {COMMIT_TYPE_AUTO} from '../../constants';
import {type UpgradedEntry} from './types';

Expand Down
5 changes: 2 additions & 3 deletions apps/app-builder/src/commands/upgrade/getRepositoryUrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-case-declarations */
import {executeCommand} from '../../utils';
import {type NpmInfo} from '../../types';
import {executeCommand} from '../../utils/executeCommand';
import {type NpmInfo} from '../../types/common';
import {VerbosityLevel} from '../../constants';
import {NodePackageManager, type ParsedEntry, UpgradeMode, type UpgradeSubContext} from './types';
import {parseGitHubUrl} from './parseGitHubUrl';
Expand Down
5 changes: 2 additions & 3 deletions apps/app-builder/src/commands/upgrade/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable max-lines-per-function */
import fs from 'fs';
import {executeCommand} from '../../utils';
import {type PdkBuilderCommand} from '../../types';
import {executeCommand} from '../../utils/executeCommand';
import {type PdkBuilderCommand} from '../../types/command';
import {VerbosityLevel} from '../../constants';
import {verifyLockfile} from './verifyLockfile';
import {upgradePackage} from './upgradePackage';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NodePackageManager, type UpgradeSubContextWithLockfile} from '../types';
import {executeCommand} from '../../../utils';
import {executeCommand} from '../../../utils/executeCommand';

export const executeNodeUpgrade = async (context: UpgradeSubContextWithLockfile): Promise<void> => {
const {config, packageName} = context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type ParsedEntry, type UpgradeSubContextWithLockfile} from '../types';
import {executeCommand} from '../../../utils';
import {executeCommand} from '../../../utils/executeCommand';

export async function getPackageEntriesForBun(
context: UpgradeSubContextWithLockfile,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type ParsedEntry, type UpgradeSubContextWithLockfile} from '../types';
import {executeCommand} from '../../../utils';
import {executeCommand} from '../../../utils/executeCommand';

export async function getPackageEntriesForYarn(
context: UpgradeSubContextWithLockfile,
Expand Down
6 changes: 0 additions & 6 deletions apps/app-builder/src/commands/upgrade/node/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/upgrade/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type MakeOptional, type PromiseOr} from '@myparcel/ts-utils';
import {type CommandArgs, type PdkBuilderContext} from '../../types';
import {type CommandArgs, type PdkBuilderContext} from '../../types/command';

export interface ParsedEntry {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions apps/app-builder/src/commands/upgrade/upgradePackage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type PromiseOr} from '@myparcel/ts-utils';
import {UpgradeMode, type UpgradeSubContextWithLockfile, type UpgradeSubResult} from './types';
import {upgradeNodePackage} from './node';
import {upgradeComposerPackage} from './composer';
import {upgradeNodePackage} from './node/upgradeNodePackage';
import {upgradeComposerPackage} from './composer/upgradeComposerPackage';

export const upgradePackage = (context: UpgradeSubContextWithLockfile): PromiseOr<UpgradeSubResult> => {
switch (context.mode) {
Expand Down
2 changes: 1 addition & 1 deletion apps/app-builder/src/commands/upgrade/verifyLockfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {UpgradeMode, type UpgradeSubContext} from './types';
import {getDefaultNodeLockfilePath} from './node';
import {getDefaultNodeLockfilePath} from './node/getDefaultNodeLockfilePath';
import {ensureCleanLockfile} from './ensureCleanLockfile';

export const verifyLockfile = async (context: UpgradeSubContext): Promise<string> => {
Expand Down
Loading

0 comments on commit f8b310b

Please sign in to comment.