@codefast/cli 0.3.14-canary.1 → 0.3.14-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{commands/arrange.mjs → lib/arrange/adapters/primary/cli/arrange.command.mjs} +32 -33
- package/dist/lib/arrange/adapters/primary/cli/arrange.presentation.module.mjs +14 -0
- package/dist/lib/arrange/adapters/primary/cli/presentation.tokens.mjs +5 -0
- package/dist/lib/arrange/{infra → adapters/secondary}/domain-source-parser.adapter.mjs +5 -8
- package/dist/lib/arrange/{infra → adapters/secondary}/file-walker.adapter.mjs +11 -9
- package/dist/lib/arrange/adapters/secondary/workspace-resolver.adapter.mjs +233 -0
- package/dist/lib/arrange/application/services/arrange-file-processor.service.mjs +37 -12
- package/dist/lib/arrange/application/services/arrange-target-path-resolver.service.mjs +21 -0
- package/dist/lib/arrange/application/services/arrange-target-scanner.service.mjs +10 -4
- package/dist/lib/arrange/application/use-cases/analyze-directory.use-case.mjs +7 -10
- package/dist/lib/arrange/{presentation/prepare-arrange.orchestrator.mjs → application/use-cases/prepare-arrange-workspace.use-case.mjs} +25 -20
- package/dist/lib/arrange/application/use-cases/run-arrange-sync.use-case.mjs +10 -19
- package/dist/lib/arrange/application/use-cases/suggest-cn-groups.use-case.mjs +9 -5
- package/dist/lib/arrange/arrange.module.mjs +17 -13
- package/dist/lib/arrange/contracts/tokens.mjs +6 -5
- package/dist/lib/arrange/domain/arrange-analyze.service.mjs +1 -1
- package/dist/lib/arrange/domain/ast/ast-helpers.helper.mjs +1 -1
- package/dist/lib/arrange/domain/ast/ast-node.model.mjs +1 -21
- package/dist/lib/arrange/domain/ast/collectors-tv.collector.mjs +2 -2
- package/dist/lib/arrange/domain/ast/targets.model.mjs +6 -6
- package/dist/lib/arrange/domain/grouping.domain.mjs +3 -2
- package/dist/lib/arrange/domain/imports.domain.mjs +1 -1
- package/dist/lib/arrange/domain/source-text-formatters.formatter.mjs +19 -2
- package/dist/lib/{tag/presentation/create-tag-progress-listener.presenter.mjs → arrange/domain/tailwind-grouping.service.mjs} +10 -7
- package/dist/lib/arrange/domain/{tokenizer.util.mjs → tailwind-token-classifier.domain-service.mjs} +3 -29
- package/dist/lib/arrange/domain/tailwind-token.value-object.mjs +31 -0
- package/dist/lib/arrange/{infra/ts-ast-translator.adapter.mjs → infrastructure/typescript-ast-translator.adapter.mjs} +2 -2
- package/dist/lib/arrange/presentation/arrange-analyze.presenter.mjs +259 -0
- package/dist/lib/arrange/presentation/arrange-cli.schema.mjs +18 -0
- package/dist/lib/arrange/presentation/arrange-sync.presenter.mjs +23 -2
- package/dist/lib/arrange/presentation/group-file-preview.presenter.mjs +10 -14
- package/dist/lib/bootstrap/composition-root.mjs +33 -0
- package/dist/lib/config/application/services/load-config.service.mjs +17 -0
- package/dist/lib/config/contracts/tokens.mjs +2 -1
- package/dist/lib/config/infrastructure/config-loader.adapter.mjs +306 -0
- package/dist/lib/config/{infra → infrastructure}/config-schema.adapter.mjs +2 -2
- package/dist/lib/{arrange/presentation/present-analyze-report.presenter.mjs → config/infrastructure/config-warning-reporter.adapter.mjs} +9 -8
- package/dist/lib/core/{presentation/try-load-codefast-config.presenter.mjs → application/load-codefast-config.use-case.mjs} +22 -22
- package/dist/lib/core/{presentation/global-cli-options.presenter.mjs → application/services/global-cli-options-parser.service.mjs} +3 -3
- package/dist/lib/core/application/services/schema-validator.service.mjs +17 -0
- package/dist/lib/core/contracts/tokens.mjs +7 -2
- package/dist/lib/core/core.module.mjs +3 -3
- package/dist/lib/core/{application/utils/caught-unknown-message.util.mjs → domain/caught-unknown-message.value-object.mjs} +1 -1
- package/dist/lib/core/domain/errors.domain.mjs +13 -12
- package/dist/lib/core/domain/result.model.mjs +1 -7
- package/dist/lib/core/infrastructure/infrastructure.module.mjs +30 -0
- package/dist/lib/core/infrastructure/path.adapter.mjs +246 -0
- package/dist/lib/core/{infra/logging-decorator.adapter.mjs → infrastructure/port-telemetry.decorator.mjs} +1 -1
- package/dist/lib/core/infrastructure/repo-root-resolver.adapter.mjs +233 -0
- package/dist/lib/core/{application/utils/verbose-diagnostics.util.mjs → infrastructure/verbose-diagnostics.policy.mjs} +1 -1
- package/dist/lib/core/presentation/cli-executor.presenter.mjs +3 -18
- package/dist/lib/core/presentation/cli-schema.parser.mjs +7 -0
- package/dist/lib/core/presentation/presentation.module.mjs +1 -7
- package/dist/lib/{infra → infrastructure}/node-io.adapter.mjs +22 -3
- package/dist/lib/{infra/workspace/repo-root.adapter.mjs → infrastructure/workspace/repo-root-resolver.service.mjs} +1 -1
- package/dist/lib/kernel/contracts/tokens.mjs +5 -0
- package/dist/{commands/mirror.mjs → lib/mirror/adapters/primary/cli/mirror.command.mjs} +17 -12
- package/dist/lib/mirror/{infra → adapters/secondary}/file-system-service.adapter.mjs +14 -9
- package/dist/lib/mirror/{infra → adapters/secondary}/mirror-sync-reporter.adapter.mjs +12 -5
- package/dist/lib/mirror/{infra → adapters/secondary}/package-repository.adapter.mjs +12 -6
- package/dist/lib/mirror/{application/services/sync-workspace-package.service.mjs → adapters/secondary/sync-workspace-package.adapter.mjs} +29 -29
- package/dist/lib/mirror/{infra → adapters/secondary}/workspace-service.adapter.mjs +12 -7
- package/dist/lib/mirror/application/{use-cases/generate-mirror-exports.use-case.mjs → services/generate-mirror-exports.service.mjs} +7 -7
- package/dist/lib/mirror/{presentation/resolve-mirror-package-arg.presenter.mjs → application/services/mirror-package-arg-resolver.service.mjs} +4 -4
- package/dist/lib/mirror/{presentation/prepare-mirror.orchestrator.mjs → application/use-cases/prepare-mirror-sync.use-case.mjs} +23 -22
- package/dist/lib/mirror/application/use-cases/run-mirror-sync.use-case.mjs +12 -12
- package/dist/lib/mirror/contracts/tokens.mjs +3 -3
- package/dist/lib/mirror/domain/package-display-name.policy.mjs +9 -0
- package/dist/lib/mirror/{infra/path-normalizer.adapter.mjs → domain/path-normalizer.value-object.mjs} +1 -1
- package/dist/lib/mirror/{infra/dirent-list.adapter.mjs → infrastructure/dirent-list.guard.mjs} +1 -1
- package/dist/lib/mirror/infrastructure/mirror-console-reporter.presenter.mjs +99 -0
- package/dist/lib/mirror/{infra/package-filter.adapter.mjs → infrastructure/package-filter-resolver.service.mjs} +2 -2
- package/dist/lib/mirror/{infra/update-pkg.adapter.mjs → infrastructure/package-json-exports.repository.mjs} +4 -19
- package/dist/lib/mirror/{infra/workspace-packages.adapter.mjs → infrastructure/workspace-packages.service.mjs} +4 -4
- package/dist/lib/mirror/mirror.module.mjs +17 -15
- package/dist/lib/mirror/presentation/{mirror-cli-schema.presenter.mjs → mirror-cli.schema.mjs} +1 -1
- package/dist/lib/shared/source-code/domain/text-edit.model.mjs +32 -5
- package/dist/lib/shared/source-code/{infra/tsx-file-walk.adapter.mjs → infrastructure/typescript-source-file-walker.service.mjs} +2 -2
- package/dist/lib/tag/adapters/primary/cli/presentation.tokens.mjs +6 -0
- package/dist/{commands/tag.mjs → lib/tag/adapters/primary/cli/tag.command.mjs} +23 -21
- package/dist/lib/tag/adapters/primary/cli/tag.presentation.module.mjs +13 -0
- package/dist/lib/tag/{infra → adapters/secondary}/tag-since-writer.adapter.mjs +12 -7
- package/dist/lib/tag/{infra → adapters/secondary}/tag-target-resolver.adapter.mjs +12 -5
- package/dist/lib/tag/{infra → adapters/secondary}/tag-version-resolver.adapter.mjs +10 -8
- package/dist/lib/tag/{infra → adapters/secondary}/typescript-tree-walk.adapter.mjs +12 -5
- package/dist/lib/tag/{presentation/resolve-tag-cli-target.presenter.mjs → application/services/tag-cli-target-path-resolver.service.mjs} +1 -1
- package/dist/lib/tag/application/services/tag-target-runner.service.mjs +21 -0
- package/dist/lib/tag/{presentation/prepare-tag.orchestrator.mjs → application/use-cases/prepare-tag-sync.use-case.mjs} +23 -23
- package/dist/lib/tag/application/use-cases/run-tag-sync.use-case.mjs +14 -31
- package/dist/lib/tag/contracts/tokens.mjs +2 -4
- package/dist/lib/tag/{infra → infrastructure}/tag-target-candidates.adapter.mjs +4 -4
- package/dist/lib/tag/presentation/present-tag-sync-result.presenter.mjs +1 -1
- package/dist/lib/tag/presentation/{tag-cli-schema.presenter.mjs → tag-cli.schema.mjs} +1 -1
- package/dist/lib/tag/presentation/tag-sync-progress-listener.presenter.mjs +243 -0
- package/dist/lib/tag/presentation/tag-sync.presenter.mjs +6 -23
- package/dist/lib/tag/tag.module.mjs +15 -13
- package/dist/program.mjs +2 -2
- package/package.json +16 -9
- package/dist/lib/arrange/application/arrange-analyze-json.format.mjs +0 -10
- package/dist/lib/arrange/application/arrange-group-json.format.mjs +0 -11
- package/dist/lib/arrange/application/arrange-sync-cli-result.mjs +0 -7
- package/dist/lib/arrange/application/arrange-sync-json.format.mjs +0 -12
- package/dist/lib/arrange/application/use-cases/group-file.use-case.mjs +0 -35
- package/dist/lib/arrange/arrange.feature.module.mjs +0 -19
- package/dist/lib/arrange/arrange.presentation.module.mjs +0 -13
- package/dist/lib/arrange/domain/errors.domain.mjs +0 -18
- package/dist/lib/arrange/infra/ensure-cn-import.adapter.mjs +0 -10
- package/dist/lib/arrange/infra/merge-cn-literal-pool-for-test.test-helper.mjs +0 -18
- package/dist/lib/arrange/presentation/arrange-cli-schema.presenter.mjs +0 -29
- package/dist/lib/arrange/presentation/formatters.presenter.mjs +0 -2
- package/dist/lib/arrange/presentation/present-analyze-cli.presenter.mjs +0 -7
- package/dist/lib/arrange/presentation/report.presenter.mjs +0 -24
- package/dist/lib/arrange/presentation/resolve-arrange-cli-target.presenter.mjs +0 -21
- package/dist/lib/config/application/use-cases/load-config.use-case.mjs +0 -17
- package/dist/lib/config/infra/loader.adapter.mjs +0 -84
- package/dist/lib/core/application/schema-parse.util.mjs +0 -17
- package/dist/lib/core/infra/composition-root.mjs +0 -21
- package/dist/lib/core/infra/infra.module.mjs +0 -23
- package/dist/lib/core/infra/path.adapter.mjs +0 -13
- package/dist/lib/core/operational/contracts/tokens.mjs +0 -7
- package/dist/lib/core/presentation/load-codefast-config.presenter.mjs +0 -18
- package/dist/lib/core/presentation/parse-cli-schema.presenter.mjs +0 -7
- package/dist/lib/infra/config-reporter.adapter.mjs +0 -11
- package/dist/lib/kernel/di/command.token.mjs +0 -5
- package/dist/lib/mirror/contracts/use-cases.contract.mjs +0 -1
- package/dist/lib/mirror/infra/mirror-sync-cli-options.adapter.mjs +0 -1
- package/dist/lib/mirror/mirror.feature.module.mjs +0 -19
- package/dist/lib/mirror/mirror.presentation.module.mjs +0 -11
- package/dist/lib/mirror/presentation/reporter.presenter.mjs +0 -111
- package/dist/lib/tag/contracts/presentation.contract.mjs +0 -1
- package/dist/lib/tag/contracts/use-cases.contract.mjs +0 -1
- package/dist/lib/tag/infra/tag-sync-cli-options.adapter.mjs +0 -1
- package/dist/lib/tag/presentation/resolve-tag-workspace-root.presenter.mjs +0 -12
- package/dist/lib/tag/tag.feature.module.mjs +0 -19
- package/dist/lib/tag/tag.presentation.module.mjs +0 -15
- /package/dist/lib/arrange/{contracts/presentation.contract.mjs → application/ports/workspace-resolver.port.mjs} +0 -0
- /package/dist/lib/arrange/contracts/{use-cases.contract.mjs → analyze-report-presenter.contract.mjs} +0 -0
- /package/dist/lib/{arrange/infra/arrange-sync-cli-options.adapter.mjs → config/application/ports/config-warning-reporter.port.mjs} +0 -0
- /package/dist/lib/core/{contracts/presentation.contract.mjs → application/ports/repo-root-resolver.port.mjs} +0 -0
- /package/dist/lib/core/{presentation/command.interface.mjs → application/ports/runtime.port.mjs} +0 -0
- /package/dist/lib/{infra/fs-contract.port.mjs → kernel/contracts/cli-command.contract.mjs} +0 -0
- /package/dist/lib/{mirror/contracts/presentation.contract.mjs → tag/contracts/tag-sync-result-presenter.contract.mjs} +0 -0
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { formatArrangeSyncJsonOutput } from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { parseWithCliSchema } from "../lib/core/presentation/parse-cli-schema.presenter.mjs";
|
|
10
|
-
import { consumeCliAppError } from "../lib/core/presentation/cli-executor.presenter.mjs";
|
|
11
|
-
import process from "node:process";
|
|
1
|
+
import { AnalyzeDirectoryUseCaseToken, GroupFilePreviewPortToken, PrepareArrangeWorkspaceUseCaseToken, RunArrangeSyncUseCaseToken, SuggestCnGroupsUseCaseToken } from "../../../contracts/tokens.mjs";
|
|
2
|
+
import { PresentAnalyzeReportPresenterToken } from "./presentation.tokens.mjs";
|
|
3
|
+
import { arrangeAnalyzeDirectoryRequestSchema, arrangeSuggestGroupsRequestSchema, arrangeSyncRunRequestSchema } from "../../../presentation/arrange-cli.schema.mjs";
|
|
4
|
+
import { exitCodeForArrangeSyncResult, formatArrangeGroupJsonOutput, formatArrangeSyncJsonOutput, presentArrangeSyncResult } from "../../../presentation/arrange-sync.presenter.mjs";
|
|
5
|
+
import { CliLoggerToken, CliRuntimeToken } from "../../../../core/contracts/tokens.mjs";
|
|
6
|
+
import { formatArrangeAnalyzeJsonOutput } from "../../../presentation/arrange-analyze.presenter.mjs";
|
|
7
|
+
import { parseWithCliSchema } from "../../../../core/presentation/cli-schema.parser.mjs";
|
|
8
|
+
import { consumeCliAppError } from "../../../../core/presentation/cli-executor.presenter.mjs";
|
|
12
9
|
import { Option } from "commander";
|
|
13
10
|
import { inject, injectable } from "@codefast/di";
|
|
14
|
-
//#region src/
|
|
11
|
+
//#region src/lib/arrange/adapters/primary/cli/arrange.command.ts
|
|
15
12
|
function toPrimitive(input, hint) {
|
|
16
13
|
if (typeof input !== "object" || input === null) return input;
|
|
17
14
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -227,30 +224,36 @@ function withClassNameOption() {
|
|
|
227
224
|
}
|
|
228
225
|
_dec = injectable([
|
|
229
226
|
inject(CliLoggerToken),
|
|
230
|
-
inject(
|
|
227
|
+
inject(CliRuntimeToken),
|
|
228
|
+
inject(PrepareArrangeWorkspaceUseCaseToken),
|
|
231
229
|
inject(AnalyzeDirectoryUseCaseToken),
|
|
232
230
|
inject(RunArrangeSyncUseCaseToken),
|
|
233
231
|
inject(SuggestCnGroupsUseCaseToken),
|
|
234
|
-
inject(PresentAnalyzeReportPresenterToken)
|
|
232
|
+
inject(PresentAnalyzeReportPresenterToken),
|
|
233
|
+
inject(GroupFilePreviewPortToken)
|
|
235
234
|
]);
|
|
236
235
|
let _ArrangeCommand;
|
|
237
236
|
(class {
|
|
238
237
|
logger;
|
|
239
|
-
|
|
238
|
+
runtime;
|
|
239
|
+
prepareWorkspace;
|
|
240
240
|
analyzeDirectory;
|
|
241
241
|
runArrangeSync;
|
|
242
242
|
suggestCnGroups;
|
|
243
243
|
presentAnalyzeReport;
|
|
244
|
+
groupFilePreview;
|
|
244
245
|
static {
|
|
245
246
|
({c: [_ArrangeCommand, _initClass]} = _apply_decs_2311(this, [_dec], []));
|
|
246
247
|
}
|
|
247
|
-
constructor(logger,
|
|
248
|
+
constructor(logger, runtime, prepareWorkspace, analyzeDirectory, runArrangeSync, suggestCnGroups, presentAnalyzeReport, groupFilePreview) {
|
|
248
249
|
this.logger = logger;
|
|
249
|
-
this.
|
|
250
|
+
this.runtime = runtime;
|
|
251
|
+
this.prepareWorkspace = prepareWorkspace;
|
|
250
252
|
this.analyzeDirectory = analyzeDirectory;
|
|
251
253
|
this.runArrangeSync = runArrangeSync;
|
|
252
254
|
this.suggestCnGroups = suggestCnGroups;
|
|
253
255
|
this.presentAnalyzeReport = presentAnalyzeReport;
|
|
256
|
+
this.groupFilePreview = groupFilePreview;
|
|
254
257
|
}
|
|
255
258
|
name = "arrange";
|
|
256
259
|
description = "Analyze and regroup Tailwind classes in cn() / tv() calls (Tailwind v4)";
|
|
@@ -262,25 +265,22 @@ let _ArrangeCommand;
|
|
|
262
265
|
arrange.command("group").description("Try grouping on a pasted class string (stdout: cn(...) or tv array with --tv)").argument("[tokens...]", "Class tokens (quote a single string if it contains spaces)").option("--tv", "Emit tv()-style array instead of cn() call", false).addOption(withClassNameOption()).option("--json", "Print one JSON object on stdout instead of plain lines", false).action((tokens, opts) => this.executeGroup(tokens, opts));
|
|
263
266
|
}
|
|
264
267
|
async executeAnalyze(target, options) {
|
|
265
|
-
const prelude = await this.
|
|
266
|
-
currentWorkingDirectory:
|
|
268
|
+
const prelude = await this.prepareWorkspace.execute({
|
|
269
|
+
currentWorkingDirectory: this.runtime.cwd(),
|
|
267
270
|
rawTarget: target
|
|
268
271
|
});
|
|
269
272
|
if (!consumeCliAppError(this.logger, prelude)) return;
|
|
270
273
|
const { resolvedTarget } = prelude.value;
|
|
271
|
-
const parsed = parseWithCliSchema(arrangeAnalyzeDirectoryRequestSchema, {
|
|
272
|
-
analyzeRootPath: resolvedTarget,
|
|
273
|
-
json: options?.json
|
|
274
|
-
});
|
|
274
|
+
const parsed = parseWithCliSchema(arrangeAnalyzeDirectoryRequestSchema, { analyzeRootPath: resolvedTarget });
|
|
275
275
|
if (!consumeCliAppError(this.logger, parsed)) return;
|
|
276
276
|
const outcome = this.analyzeDirectory.execute(parsed.value);
|
|
277
277
|
if (!consumeCliAppError(this.logger, outcome)) return;
|
|
278
|
-
if (
|
|
278
|
+
if (options?.json) this.logger.out(formatArrangeAnalyzeJsonOutput(resolvedTarget, outcome.value));
|
|
279
279
|
else this.presentAnalyzeReport.present(resolvedTarget, outcome.value);
|
|
280
280
|
}
|
|
281
281
|
async executePreviewOrApply(write, target, opts) {
|
|
282
|
-
const prelude = await this.
|
|
283
|
-
currentWorkingDirectory:
|
|
282
|
+
const prelude = await this.prepareWorkspace.execute({
|
|
283
|
+
currentWorkingDirectory: this.runtime.cwd(),
|
|
284
284
|
rawTarget: target
|
|
285
285
|
});
|
|
286
286
|
if (!consumeCliAppError(this.logger, prelude)) return;
|
|
@@ -289,7 +289,6 @@ let _ArrangeCommand;
|
|
|
289
289
|
rootDir,
|
|
290
290
|
targetPath: resolvedTarget,
|
|
291
291
|
write,
|
|
292
|
-
json: opts.json,
|
|
293
292
|
withClassName: opts.withClassName,
|
|
294
293
|
cnImport: opts.cnImport,
|
|
295
294
|
config: config.arrange ?? {}
|
|
@@ -297,21 +296,21 @@ let _ArrangeCommand;
|
|
|
297
296
|
if (!consumeCliAppError(this.logger, parsed)) return;
|
|
298
297
|
const outcome = await this.runArrangeSync.execute(parsed.value);
|
|
299
298
|
if (!consumeCliAppError(this.logger, outcome)) return;
|
|
300
|
-
if (
|
|
299
|
+
if (!write) for (const plan of outcome.value.previewPlans) this.groupFilePreview.printGroupFilePreviewFromWork(plan);
|
|
300
|
+
if (opts.json) {
|
|
301
301
|
this.logger.out(formatArrangeSyncJsonOutput(outcome.value, write));
|
|
302
|
-
|
|
303
|
-
} else
|
|
302
|
+
this.runtime.setExitCode(exitCodeForArrangeSyncResult(outcome.value));
|
|
303
|
+
} else this.runtime.setExitCode(presentArrangeSyncResult(this.logger, outcome.value, write));
|
|
304
304
|
}
|
|
305
305
|
async executeGroup(tokens, opts) {
|
|
306
306
|
const parsed = parseWithCliSchema(arrangeSuggestGroupsRequestSchema, {
|
|
307
307
|
inlineClasses: tokens.join(" ").trim(),
|
|
308
308
|
emitTvStyleArray: !!opts.tv,
|
|
309
|
-
trailingClassName: !!opts.withClassName
|
|
310
|
-
json: opts.json
|
|
309
|
+
trailingClassName: !!opts.withClassName
|
|
311
310
|
});
|
|
312
311
|
if (!consumeCliAppError(this.logger, parsed)) return;
|
|
313
312
|
const output = this.suggestCnGroups.execute(parsed.value);
|
|
314
|
-
if (
|
|
313
|
+
if (opts.json) this.logger.out(formatArrangeGroupJsonOutput(output));
|
|
315
314
|
else {
|
|
316
315
|
this.logger.out(output.primaryLine);
|
|
317
316
|
this.logger.out(output.bucketsCommentLine);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GroupFilePreviewPortToken } from "../../../contracts/tokens.mjs";
|
|
2
|
+
import { PresentAnalyzeReportPresenterToken } from "./presentation.tokens.mjs";
|
|
3
|
+
import { PresentAnalyzeReportPresenterImpl as _PresentAnalyzeReportPresenterImpl } from "../../../presentation/arrange-analyze.presenter.mjs";
|
|
4
|
+
import { GroupFilePreviewPresenterAdapter as _GroupFilePreviewPresenterAdapter } from "../../../presentation/group-file-preview.presenter.mjs";
|
|
5
|
+
import { PresentationModule } from "../../../../core/presentation/presentation.module.mjs";
|
|
6
|
+
import { Module } from "@codefast/di";
|
|
7
|
+
//#region src/lib/arrange/adapters/primary/cli/arrange.presentation.module.ts
|
|
8
|
+
const ArrangePresentationModule = Module.create("cli-arrange-presentation", (moduleBuilder) => {
|
|
9
|
+
moduleBuilder.import(PresentationModule);
|
|
10
|
+
moduleBuilder.bind(PresentAnalyzeReportPresenterToken).to(_PresentAnalyzeReportPresenterImpl).singleton();
|
|
11
|
+
moduleBuilder.bind(GroupFilePreviewPortToken).to(_GroupFilePreviewPresenterAdapter).singleton();
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ArrangePresentationModule };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CliLoggerToken } from "
|
|
2
|
-
import { messageFromCaughtUnknown } from "
|
|
3
|
-
import { parseDomainSourceFile } from "
|
|
1
|
+
import { CliLoggerToken } from "../../../core/contracts/tokens.mjs";
|
|
2
|
+
import { messageFromCaughtUnknown } from "../../../core/domain/caught-unknown-message.value-object.mjs";
|
|
3
|
+
import { parseDomainSourceFile } from "../../infrastructure/typescript-ast-translator.adapter.mjs";
|
|
4
4
|
import { inject, injectable } from "@codefast/di";
|
|
5
|
-
//#region src/lib/arrange/
|
|
5
|
+
//#region src/lib/arrange/adapters/secondary/domain-source-parser.adapter.ts
|
|
6
6
|
function toPrimitive(input, hint) {
|
|
7
7
|
if (typeof input !== "object" || input === null) return input;
|
|
8
8
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -235,8 +235,5 @@ let _DomainSourceParserAdapter;
|
|
|
235
235
|
_initClass();
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
|
-
/**
|
|
239
|
-
* Default instance without diagnostics logging (tests and legacy imports).
|
|
240
|
-
*/ const domainSourceParserAdapter = new _DomainSourceParserAdapter();
|
|
241
238
|
//#endregion
|
|
242
|
-
export { _DomainSourceParserAdapter as DomainSourceParserAdapter
|
|
239
|
+
export { _DomainSourceParserAdapter as DomainSourceParserAdapter };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CliLoggerToken } from "
|
|
2
|
-
import { messageFromCaughtUnknown } from "
|
|
3
|
-
import { walkTsxFiles } from "
|
|
1
|
+
import { CliFsToken, CliLoggerToken } from "../../../core/contracts/tokens.mjs";
|
|
2
|
+
import { messageFromCaughtUnknown } from "../../../core/domain/caught-unknown-message.value-object.mjs";
|
|
3
|
+
import { walkTsxFiles } from "../../../shared/source-code/infrastructure/typescript-source-file-walker.service.mjs";
|
|
4
4
|
import { inject, injectable } from "@codefast/di";
|
|
5
|
-
//#region src/lib/arrange/
|
|
5
|
+
//#region src/lib/arrange/adapters/secondary/file-walker.adapter.ts
|
|
6
6
|
function toPrimitive(input, hint) {
|
|
7
7
|
if (typeof input !== "object" || input === null) return input;
|
|
8
8
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -213,21 +213,23 @@ function _apply_decs_2311(targetClass, classDecs, memberDecs, classDecsHaveThis,
|
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
let _dec, _initClass;
|
|
216
|
-
_dec = injectable([inject(CliLoggerToken)]);
|
|
216
|
+
_dec = injectable([inject(CliLoggerToken), inject(CliFsToken)]);
|
|
217
217
|
let _FileWalkerAdapter;
|
|
218
218
|
(class {
|
|
219
219
|
logger;
|
|
220
|
+
fs;
|
|
220
221
|
static {
|
|
221
222
|
({c: [_FileWalkerAdapter, _initClass]} = _apply_decs_2311(this, [_dec], []));
|
|
222
223
|
}
|
|
223
|
-
constructor(logger) {
|
|
224
|
+
constructor(logger, fs) {
|
|
224
225
|
this.logger = logger;
|
|
226
|
+
this.fs = fs;
|
|
225
227
|
}
|
|
226
|
-
walkTypeScriptFiles(rootDirectoryPath
|
|
228
|
+
walkTypeScriptFiles(rootDirectoryPath) {
|
|
227
229
|
try {
|
|
228
|
-
return walkTsxFiles(rootDirectoryPath, fs);
|
|
230
|
+
return walkTsxFiles(rootDirectoryPath, this.fs);
|
|
229
231
|
} catch (caughtError) {
|
|
230
|
-
this.logger
|
|
232
|
+
this.logger.err(`[file-walker] ${messageFromCaughtUnknown(caughtError)}`);
|
|
231
233
|
throw caughtError;
|
|
232
234
|
}
|
|
233
235
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { CliFsToken } from "../../../core/contracts/tokens.mjs";
|
|
2
|
+
import { findRepoRoot } from "../../../infrastructure/workspace/repo-root-resolver.service.mjs";
|
|
3
|
+
import { inject, injectable } from "@codefast/di";
|
|
4
|
+
//#region src/lib/arrange/adapters/secondary/workspace-resolver.adapter.ts
|
|
5
|
+
function toPrimitive(input, hint) {
|
|
6
|
+
if (typeof input !== "object" || input === null) return input;
|
|
7
|
+
var prim = input[Symbol.toPrimitive];
|
|
8
|
+
if (prim !== void 0) {
|
|
9
|
+
var res = prim.call(input, hint || "default");
|
|
10
|
+
if (typeof res !== "object") return res;
|
|
11
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
12
|
+
}
|
|
13
|
+
return (hint === "string" ? String : Number)(input);
|
|
14
|
+
}
|
|
15
|
+
function toPropertyKey(arg) {
|
|
16
|
+
var key = toPrimitive(arg, "string");
|
|
17
|
+
return typeof key === "symbol" ? key : String(key);
|
|
18
|
+
}
|
|
19
|
+
function checkInRHS(value) {
|
|
20
|
+
if (Object(value) !== value) throw TypeError("right-hand side of 'in' should be an object, got " + (value !== null ? typeof value : "null"));
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function setFunctionName(fn, name, prefix) {
|
|
24
|
+
if (typeof name === "symbol") {
|
|
25
|
+
name = name.description;
|
|
26
|
+
name = name ? "[" + name + "]" : "";
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
Object.defineProperty(fn, "name", {
|
|
30
|
+
configurable: true,
|
|
31
|
+
value: prefix ? prefix + " " + name : name
|
|
32
|
+
});
|
|
33
|
+
} catch (_) {}
|
|
34
|
+
return fn;
|
|
35
|
+
}
|
|
36
|
+
function _apply_decs_2311(targetClass, classDecs, memberDecs, classDecsHaveThis, instanceBrand, parentClass) {
|
|
37
|
+
var symbolMetadata = Symbol.metadata || Symbol.for("Symbol.metadata");
|
|
38
|
+
var defineProperty = Object.defineProperty;
|
|
39
|
+
var create = Object.create;
|
|
40
|
+
var metadata;
|
|
41
|
+
var existingNonFields = [create(null), create(null)];
|
|
42
|
+
var hasClassDecs = classDecs.length;
|
|
43
|
+
var _;
|
|
44
|
+
function createRunInitializers(initializers, useStaticThis, hasValue) {
|
|
45
|
+
return function(thisArg, value) {
|
|
46
|
+
if (useStaticThis) {
|
|
47
|
+
value = thisArg;
|
|
48
|
+
thisArg = targetClass;
|
|
49
|
+
}
|
|
50
|
+
for (var i = 0; i < initializers.length; i++) value = initializers[i].apply(thisArg, hasValue ? [value] : []);
|
|
51
|
+
return hasValue ? value : thisArg;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function assertCallable(fn, hint1, hint2, throwUndefined) {
|
|
55
|
+
if (typeof fn !== "function") {
|
|
56
|
+
if (throwUndefined || fn !== void 0) throw new TypeError(hint1 + " must " + (hint2 || "be") + " a function" + (throwUndefined ? "" : " or undefined"));
|
|
57
|
+
}
|
|
58
|
+
return fn;
|
|
59
|
+
}
|
|
60
|
+
function applyDec(Class, decInfo, decoratorsHaveThis, name, kind, initializers, ret, isStatic, isPrivate, isField, hasPrivateBrand) {
|
|
61
|
+
function assertInstanceIfPrivate(target) {
|
|
62
|
+
if (!hasPrivateBrand(target)) throw new TypeError("Attempted to access private element on non-instance");
|
|
63
|
+
}
|
|
64
|
+
var decs = [].concat(decInfo[0]);
|
|
65
|
+
var decVal = decInfo[3];
|
|
66
|
+
var isClass = !ret;
|
|
67
|
+
var isAccessor = kind === 1;
|
|
68
|
+
var isGetter = kind === 3;
|
|
69
|
+
var isSetter = kind === 4;
|
|
70
|
+
var isMethod = kind === 2;
|
|
71
|
+
function bindPropCall(name, useStaticThis, before) {
|
|
72
|
+
return function(_this, value) {
|
|
73
|
+
if (useStaticThis) {
|
|
74
|
+
value = _this;
|
|
75
|
+
_this = Class;
|
|
76
|
+
}
|
|
77
|
+
if (before) before(_this);
|
|
78
|
+
return desc[name].call(_this, value);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var desc1 = {};
|
|
82
|
+
var init = [];
|
|
83
|
+
var key = isGetter ? "get" : isSetter || isAccessor ? "set" : "value";
|
|
84
|
+
if (!isClass) {
|
|
85
|
+
if (isPrivate) {
|
|
86
|
+
if (isField || isAccessor) desc1 = {
|
|
87
|
+
get: setFunctionName(function() {
|
|
88
|
+
return decVal(this);
|
|
89
|
+
}, name, "get"),
|
|
90
|
+
set: function(value) {
|
|
91
|
+
decInfo[4](this, value);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
else desc1[key] = decVal;
|
|
95
|
+
if (!isField) setFunctionName(desc1[key], name, isMethod ? "" : key);
|
|
96
|
+
} else if (!isField) desc1 = Object.getOwnPropertyDescriptor(Class, name);
|
|
97
|
+
if (!isField && !isPrivate) {
|
|
98
|
+
_ = existingNonFields[+isStatic][name];
|
|
99
|
+
if (_ && (_ ^ kind) !== 7) throw new Error("Decorating two elements with the same name (" + desc1[key].name + ") is not supported yet");
|
|
100
|
+
existingNonFields[+isStatic][name] = kind < 3 ? 1 : kind;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
var newValue = Class;
|
|
104
|
+
for (var i = decs.length - 1; i >= 0; i -= decoratorsHaveThis ? 2 : 1) {
|
|
105
|
+
var dec = assertCallable(decs[i], "A decorator", "be", true);
|
|
106
|
+
var decThis = decoratorsHaveThis ? decs[i - 1] : void 0;
|
|
107
|
+
var decoratorFinishedRef = {};
|
|
108
|
+
var ctx = {
|
|
109
|
+
kind: [
|
|
110
|
+
"field",
|
|
111
|
+
"accessor",
|
|
112
|
+
"method",
|
|
113
|
+
"getter",
|
|
114
|
+
"setter",
|
|
115
|
+
"class"
|
|
116
|
+
][kind],
|
|
117
|
+
name,
|
|
118
|
+
metadata,
|
|
119
|
+
addInitializer: (function(decoratorFinishedRef, initializer) {
|
|
120
|
+
if (decoratorFinishedRef.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
|
|
121
|
+
assertCallable(initializer, "An initializer", "be", true);
|
|
122
|
+
initializers.push(initializer);
|
|
123
|
+
}).bind(null, decoratorFinishedRef)
|
|
124
|
+
};
|
|
125
|
+
if (isClass) {
|
|
126
|
+
_ = dec.call(decThis, newValue, ctx);
|
|
127
|
+
decoratorFinishedRef.v = 1;
|
|
128
|
+
if (assertCallable(_, "class decorators", "return")) newValue = _;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
ctx.static = isStatic;
|
|
132
|
+
ctx.private = isPrivate;
|
|
133
|
+
_ = ctx.access = { has: isPrivate ? hasPrivateBrand.bind() : function(target) {
|
|
134
|
+
return name in target;
|
|
135
|
+
} };
|
|
136
|
+
if (!isSetter) _.get = isPrivate ? isMethod ? function(_this) {
|
|
137
|
+
assertInstanceIfPrivate(_this);
|
|
138
|
+
return desc1.value;
|
|
139
|
+
} : bindPropCall("get", 0, assertInstanceIfPrivate) : function(target) {
|
|
140
|
+
return target[name];
|
|
141
|
+
};
|
|
142
|
+
if (!isMethod && !isGetter) _.set = isPrivate ? bindPropCall("set", 0, assertInstanceIfPrivate) : function(target, value) {
|
|
143
|
+
target[name] = value;
|
|
144
|
+
};
|
|
145
|
+
newValue = dec.call(decThis, isAccessor ? {
|
|
146
|
+
get: desc1.get,
|
|
147
|
+
set: desc1.set
|
|
148
|
+
} : desc1[key], ctx);
|
|
149
|
+
decoratorFinishedRef.v = 1;
|
|
150
|
+
if (isAccessor) {
|
|
151
|
+
if (typeof newValue === "object" && newValue) {
|
|
152
|
+
if (_ = assertCallable(newValue.get, "accessor.get")) desc1.get = _;
|
|
153
|
+
if (_ = assertCallable(newValue.set, "accessor.set")) desc1.set = _;
|
|
154
|
+
if (_ = assertCallable(newValue.init, "accessor.init")) init.unshift(_);
|
|
155
|
+
} else if (newValue !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
|
|
156
|
+
} else if (assertCallable(newValue, (isField ? "field" : "method") + " decorators", "return")) if (isField) init.unshift(newValue);
|
|
157
|
+
else desc1[key] = newValue;
|
|
158
|
+
}
|
|
159
|
+
if (kind < 2) ret.push(createRunInitializers(init, isStatic, 1), createRunInitializers(initializers, isStatic, 0));
|
|
160
|
+
if (!isField && !isClass) if (isPrivate) if (isAccessor) ret.splice(-1, 0, bindPropCall("get", isStatic), bindPropCall("set", isStatic));
|
|
161
|
+
else ret.push(isMethod ? desc1[key] : assertCallable.call.bind(desc1[key]));
|
|
162
|
+
else defineProperty(Class, name, desc1);
|
|
163
|
+
return newValue;
|
|
164
|
+
}
|
|
165
|
+
function applyMemberDecs() {
|
|
166
|
+
var ret = [];
|
|
167
|
+
var protoInitializers;
|
|
168
|
+
var staticInitializers;
|
|
169
|
+
var pushInitializers = function(initializers) {
|
|
170
|
+
if (initializers) ret.push(createRunInitializers(initializers));
|
|
171
|
+
};
|
|
172
|
+
var applyMemberDecsOfKind = function(isStatic, isField) {
|
|
173
|
+
for (var i = 0; i < memberDecs.length; i++) {
|
|
174
|
+
var decInfo = memberDecs[i];
|
|
175
|
+
var kind = decInfo[1];
|
|
176
|
+
var kindOnly = kind & 7;
|
|
177
|
+
if ((kind & 8) == isStatic && !kindOnly == isField) {
|
|
178
|
+
var name = decInfo[2];
|
|
179
|
+
var isPrivate = !!decInfo[3];
|
|
180
|
+
var decoratorsHaveThis = kind & 16;
|
|
181
|
+
applyDec(isStatic ? targetClass : targetClass.prototype, decInfo, decoratorsHaveThis, isPrivate ? "#" + name : toPropertyKey(name), kindOnly, kindOnly < 2 ? [] : isStatic ? staticInitializers = staticInitializers || [] : protoInitializers = protoInitializers || [], ret, !!isStatic, isPrivate, isField, isStatic && isPrivate ? function(_) {
|
|
182
|
+
return checkInRHS(_) === targetClass;
|
|
183
|
+
} : instanceBrand);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
applyMemberDecsOfKind(8, 0);
|
|
188
|
+
applyMemberDecsOfKind(0, 0);
|
|
189
|
+
applyMemberDecsOfKind(8, 1);
|
|
190
|
+
applyMemberDecsOfKind(0, 1);
|
|
191
|
+
pushInitializers(protoInitializers);
|
|
192
|
+
pushInitializers(staticInitializers);
|
|
193
|
+
return ret;
|
|
194
|
+
}
|
|
195
|
+
function defineMetadata(Class) {
|
|
196
|
+
return defineProperty(Class, symbolMetadata, {
|
|
197
|
+
configurable: true,
|
|
198
|
+
enumerable: true,
|
|
199
|
+
value: metadata
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (parentClass !== void 0) metadata = parentClass[symbolMetadata];
|
|
203
|
+
metadata = create(metadata == null ? null : metadata);
|
|
204
|
+
_ = applyMemberDecs();
|
|
205
|
+
if (!hasClassDecs) defineMetadata(targetClass);
|
|
206
|
+
return {
|
|
207
|
+
e: _,
|
|
208
|
+
get c() {
|
|
209
|
+
var initializers = [];
|
|
210
|
+
return hasClassDecs && [defineMetadata(targetClass = applyDec(targetClass, [classDecs], classDecsHaveThis, targetClass.name, 5, initializers)), createRunInitializers(initializers, 1)];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
let _dec, _initClass;
|
|
215
|
+
_dec = injectable([inject(CliFsToken)]);
|
|
216
|
+
let _WorkspaceResolverAdapter;
|
|
217
|
+
(class {
|
|
218
|
+
fs;
|
|
219
|
+
static {
|
|
220
|
+
({c: [_WorkspaceResolverAdapter, _initClass]} = _apply_decs_2311(this, [_dec], []));
|
|
221
|
+
}
|
|
222
|
+
constructor(fs) {
|
|
223
|
+
this.fs = fs;
|
|
224
|
+
}
|
|
225
|
+
findRepoRoot(fromDirectory) {
|
|
226
|
+
return findRepoRoot(this.fs, fromDirectory);
|
|
227
|
+
}
|
|
228
|
+
static {
|
|
229
|
+
_initClass();
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
//#endregion
|
|
233
|
+
export { _WorkspaceResolverAdapter as WorkspaceResolverAdapter };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DomainSourceParserPortToken
|
|
2
|
-
import { CliFsToken } from "../../../core/
|
|
3
|
-
import {
|
|
1
|
+
import { DomainSourceParserPortToken } from "../../contracts/tokens.mjs";
|
|
2
|
+
import { CliFsToken } from "../../../core/contracts/tokens.mjs";
|
|
3
|
+
import { buildGroupFileUnwrapState, countPersistedGroupFileEdits, groupFileDryRunNoEdits, groupFileEditsTouchJsxCn, groupFilePreviewTotals, groupFileWorkHasNothingToReport, mergeGroupFileBodyText, tryBuildGroupFileWorkPlan } from "../../domain/arrange-grouping.service.mjs";
|
|
4
|
+
import { ensureCnImport } from "../../domain/imports.domain.mjs";
|
|
4
5
|
import { inject, injectable } from "@codefast/di";
|
|
5
6
|
//#region src/lib/arrange/application/services/arrange-file-processor.service.ts
|
|
6
7
|
function toPrimitive(input, hint) {
|
|
@@ -213,26 +214,50 @@ function _apply_decs_2311(targetClass, classDecs, memberDecs, classDecsHaveThis,
|
|
|
213
214
|
};
|
|
214
215
|
}
|
|
215
216
|
let _dec, _initClass;
|
|
216
|
-
_dec = injectable([
|
|
217
|
-
inject(CliFsToken),
|
|
218
|
-
inject(DomainSourceParserPortToken),
|
|
219
|
-
inject(GroupFilePreviewPortToken)
|
|
220
|
-
]);
|
|
217
|
+
_dec = injectable([inject(CliFsToken), inject(DomainSourceParserPortToken)]);
|
|
221
218
|
let _ArrangeFileProcessorServiceImpl;
|
|
222
219
|
(class {
|
|
223
220
|
fs;
|
|
224
221
|
domainSourceParser;
|
|
225
|
-
groupFilePreview;
|
|
226
222
|
static {
|
|
227
223
|
({c: [_ArrangeFileProcessorServiceImpl, _initClass]} = _apply_decs_2311(this, [_dec], []));
|
|
228
224
|
}
|
|
229
|
-
constructor(fs, domainSourceParser
|
|
225
|
+
constructor(fs, domainSourceParser) {
|
|
230
226
|
this.fs = fs;
|
|
231
227
|
this.domainSourceParser = domainSourceParser;
|
|
232
|
-
this.groupFilePreview = groupFilePreview;
|
|
233
228
|
}
|
|
234
229
|
processFile(args) {
|
|
235
|
-
|
|
230
|
+
const { filePath, options } = args;
|
|
231
|
+
const sourceText = this.fs.readFileSync(filePath, "utf8");
|
|
232
|
+
const domainSfInitial = this.domainSourceParser.parseDomainSourceFile(filePath, sourceText);
|
|
233
|
+
const unwrap = buildGroupFileUnwrapState(domainSfInitial, sourceText);
|
|
234
|
+
const work = tryBuildGroupFileWorkPlan({
|
|
235
|
+
filePath,
|
|
236
|
+
sourceText,
|
|
237
|
+
domainSfInitial,
|
|
238
|
+
domainSfGrouped: this.domainSourceParser.parseDomainSourceFile(filePath, unwrap.textAfterUnwrap),
|
|
239
|
+
withClassName: options.withClassName,
|
|
240
|
+
unwrap
|
|
241
|
+
});
|
|
242
|
+
if (work === null) return groupFileDryRunNoEdits(filePath);
|
|
243
|
+
if (!options.write) {
|
|
244
|
+
if (groupFileWorkHasNothingToReport(work)) return groupFileDryRunNoEdits(filePath);
|
|
245
|
+
return {
|
|
246
|
+
...groupFilePreviewTotals(work),
|
|
247
|
+
workPlan: work
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const persistedEditCount = countPersistedGroupFileEdits(work);
|
|
251
|
+
let newText = mergeGroupFileBodyText(work);
|
|
252
|
+
if (persistedEditCount > 0) {
|
|
253
|
+
if (groupFileEditsTouchJsxCn(work)) newText = ensureCnImport(this.domainSourceParser.parseDomainSourceFile(filePath, newText), options.cnImport);
|
|
254
|
+
this.fs.writeFileSync(filePath, newText, "utf8");
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
filePath,
|
|
258
|
+
totalFound: persistedEditCount + work.cnInTvNoReplacement,
|
|
259
|
+
changed: persistedEditCount
|
|
260
|
+
};
|
|
236
261
|
}
|
|
237
262
|
static {
|
|
238
263
|
_initClass();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
//#region src/lib/arrange/application/services/arrange-target-path-resolver.service.ts
|
|
3
|
+
const PACKAGE_JSON_FILE = "package.json";
|
|
4
|
+
function findNearestPackageDirectory(currentWorkingDirectory, fs) {
|
|
5
|
+
let currentDir = path.resolve(currentWorkingDirectory);
|
|
6
|
+
while (true) {
|
|
7
|
+
const packageJsonPath = path.join(currentDir, PACKAGE_JSON_FILE);
|
|
8
|
+
if (fs.existsSync(packageJsonPath)) return currentDir;
|
|
9
|
+
const parentDirectory = path.dirname(currentDir);
|
|
10
|
+
if (parentDirectory === currentDir) return;
|
|
11
|
+
currentDir = parentDirectory;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function resolveArrangeTargetPath(args) {
|
|
15
|
+
const explicitTargetPath = args.rawTarget ? path.isAbsolute(args.rawTarget) ? path.resolve(args.rawTarget) : path.resolve(args.currentWorkingDirectory, args.rawTarget) : void 0;
|
|
16
|
+
if (explicitTargetPath) return args.fs.canonicalPathSync(explicitTargetPath);
|
|
17
|
+
const resolvedDefaultTarget = findNearestPackageDirectory(args.currentWorkingDirectory, args.fs) ?? args.currentWorkingDirectory;
|
|
18
|
+
return args.fs.canonicalPathSync(resolvedDefaultTarget);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { resolveArrangeTargetPath };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileWalkerPortToken } from "../../contracts/tokens.mjs";
|
|
2
|
-
import { CliPathToken } from "../../../core/
|
|
2
|
+
import { CliFsToken, CliPathToken } from "../../../core/contracts/tokens.mjs";
|
|
3
3
|
import { inject, injectable } from "@codefast/di";
|
|
4
4
|
//#region src/lib/arrange/application/services/arrange-target-scanner.service.ts
|
|
5
5
|
function toPrimitive(input, hint) {
|
|
@@ -212,21 +212,27 @@ function _apply_decs_2311(targetClass, classDecs, memberDecs, classDecsHaveThis,
|
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
214
|
let _dec, _initClass;
|
|
215
|
-
_dec = injectable([
|
|
215
|
+
_dec = injectable([
|
|
216
|
+
inject(FileWalkerPortToken),
|
|
217
|
+
inject(CliPathToken),
|
|
218
|
+
inject(CliFsToken)
|
|
219
|
+
]);
|
|
216
220
|
let _ArrangeTargetScannerServiceImpl;
|
|
217
221
|
(class {
|
|
218
222
|
fileWalker;
|
|
219
223
|
path;
|
|
224
|
+
fs;
|
|
220
225
|
static {
|
|
221
226
|
({c: [_ArrangeTargetScannerServiceImpl, _initClass]} = _apply_decs_2311(this, [_dec], []));
|
|
222
227
|
}
|
|
223
|
-
constructor(fileWalker, path) {
|
|
228
|
+
constructor(fileWalker, path, fs) {
|
|
224
229
|
this.fileWalker = fileWalker;
|
|
225
230
|
this.path = path;
|
|
231
|
+
this.fs = fs;
|
|
226
232
|
}
|
|
227
233
|
scanTarget(args) {
|
|
228
234
|
const resolvedTargetPath = this.path.resolve(args.targetPath);
|
|
229
|
-
if (
|
|
235
|
+
if (this.fs.statSync(resolvedTargetPath).isDirectory()) return this.fileWalker.walkTypeScriptFiles(resolvedTargetPath);
|
|
230
236
|
return [resolvedTargetPath];
|
|
231
237
|
}
|
|
232
238
|
static {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CliFsToken } from "../../../core/
|
|
3
|
-
import {
|
|
1
|
+
import { ArrangeTargetScannerServiceToken, DomainSourceParserPortToken } from "../../contracts/tokens.mjs";
|
|
2
|
+
import { CliFsToken } from "../../../core/contracts/tokens.mjs";
|
|
3
|
+
import { AppError } from "../../../core/domain/errors.domain.mjs";
|
|
4
4
|
import { err, ok } from "../../../core/domain/result.model.mjs";
|
|
5
|
-
import { messageFromCaughtUnknown } from "../../../core/
|
|
5
|
+
import { messageFromCaughtUnknown } from "../../../core/domain/caught-unknown-message.value-object.mjs";
|
|
6
6
|
import { accumulateAnalyzeReportForSourceFile, createEmptyAnalyzeReport } from "../../domain/arrange-analyze.service.mjs";
|
|
7
7
|
import { inject, injectable } from "@codefast/di";
|
|
8
8
|
//#region src/lib/arrange/application/use-cases/analyze-directory.use-case.ts
|
|
@@ -218,7 +218,7 @@ function _apply_decs_2311(targetClass, classDecs, memberDecs, classDecsHaveThis,
|
|
|
218
218
|
let _dec, _initClass;
|
|
219
219
|
_dec = injectable([
|
|
220
220
|
inject(CliFsToken),
|
|
221
|
-
inject(
|
|
221
|
+
inject(ArrangeTargetScannerServiceToken),
|
|
222
222
|
inject(DomainSourceParserPortToken)
|
|
223
223
|
]);
|
|
224
224
|
let _AnalyzeDirectoryUseCaseImpl;
|
|
@@ -237,17 +237,14 @@ let _AnalyzeDirectoryUseCaseImpl;
|
|
|
237
237
|
execute(request) {
|
|
238
238
|
const report = createEmptyAnalyzeReport();
|
|
239
239
|
try {
|
|
240
|
-
const files = this.targetScanner.scanTarget({
|
|
241
|
-
targetPath: request.analyzeRootPath,
|
|
242
|
-
fs: this.fs
|
|
243
|
-
});
|
|
240
|
+
const files = this.targetScanner.scanTarget({ targetPath: request.analyzeRootPath });
|
|
244
241
|
for (const filePath of files) {
|
|
245
242
|
const sourceText = this.fs.readFileSync(filePath, "utf8");
|
|
246
243
|
accumulateAnalyzeReportForSourceFile(report, this.domainSourceParser.parseDomainSourceFile(filePath, sourceText), sourceText, filePath);
|
|
247
244
|
}
|
|
248
245
|
return ok(report);
|
|
249
246
|
} catch (caughtError) {
|
|
250
|
-
return err(
|
|
247
|
+
return err(new AppError("INFRA_FAILURE", messageFromCaughtUnknown(caughtError), caughtError));
|
|
251
248
|
}
|
|
252
249
|
}
|
|
253
250
|
static {
|