@apitree.cz/cli 0.3.0 → 0.3.1
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/package.json +5 -4
- package/src/cli.ts +13 -0
- package/src/commands/index.ts +1 -0
- package/src/commands/sync-project-references/action.ts +35 -0
- package/src/commands/sync-project-references/command.ts +13 -0
- package/src/commands/sync-project-references/config-schema.ts +19 -0
- package/src/commands/sync-project-references/default-config.ts +13 -0
- package/src/commands/sync-project-references/get-config.ts +68 -0
- package/src/commands/sync-project-references/get-existing-ts-config-path.ts +21 -0
- package/src/commands/sync-project-references/get-references.ts +49 -0
- package/src/commands/sync-project-references/get-target-build-configs.ts +24 -0
- package/src/commands/sync-project-references/get-workspace-dependencies.ts +34 -0
- package/src/commands/sync-project-references/get-workspaces.ts +9 -0
- package/src/commands/sync-project-references/index.ts +1 -0
- package/src/commands/sync-project-references/normalize-path.ts +4 -0
- package/src/commands/sync-project-references/options.ts +3 -0
- package/src/commands/sync-project-references/run-hooks.ts +10 -0
- package/src/commands/sync-project-references/types.ts +40 -0
- package/src/commands/sync-project-references/update-ts-configs.ts +56 -0
- package/src/index.ts +1 -0
- package/src/utils.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apitree.cz/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Command line interface for ApiTree projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@commander-js/extra-typings": "^13.1.0",
|
|
@@ -25,12 +26,12 @@
|
|
|
25
26
|
"path-exists": "^5.0.0",
|
|
26
27
|
"ts-toolbelt": "^9.6.0",
|
|
27
28
|
"zod": "^3.24.1",
|
|
28
|
-
"@apitree.cz/ts-utils": "0.1.
|
|
29
|
+
"@apitree.cz/ts-utils": "0.1.6"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"typedoc": "^0.27.6",
|
|
32
33
|
"typescript": "^5.7.3",
|
|
33
|
-
"@apitree.cz/typedoc-config": "0.1.
|
|
34
|
+
"@apitree.cz/typedoc-config": "0.1.8"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
37
|
"prebuild": "del dist tsconfig.build.tsbuildinfo",
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
|
|
3
|
+
const cli = async () => {
|
|
4
|
+
const program = new Command();
|
|
5
|
+
program.name('apitree-cli');
|
|
6
|
+
const commands = await import('./commands/index.js');
|
|
7
|
+
for (const command of Object.values(commands)) {
|
|
8
|
+
program.addCommand(command);
|
|
9
|
+
}
|
|
10
|
+
return program.parseAsync(process.argv);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
await cli();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { syncProjectReferences } from './sync-project-references/index.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { logger } from '../../utils.js';
|
|
4
|
+
|
|
5
|
+
import type { GetConfigProps } from './get-config.js';
|
|
6
|
+
import { getConfig } from './get-config.js';
|
|
7
|
+
import { getReferences } from './get-references.js';
|
|
8
|
+
import { getWorkspaces } from './get-workspaces.js';
|
|
9
|
+
import { runHooks } from './run-hooks.js';
|
|
10
|
+
import { updateTsConfigs } from './update-ts-configs.js';
|
|
11
|
+
|
|
12
|
+
export type ActionProps = Pick<GetConfigProps, 'config'>;
|
|
13
|
+
|
|
14
|
+
export const action = async ({ config }: ActionProps) => {
|
|
15
|
+
const { workspaces, rootDir } = await getWorkspaces();
|
|
16
|
+
const { hooks, tsConfigs } = await getConfig({ config, rootDir });
|
|
17
|
+
const sync = workspaces.flatMap(async (workspacePackage) => {
|
|
18
|
+
logger.info(`Syncing project references for ./${path.relative(rootDir, workspacePackage.dir)}`);
|
|
19
|
+
return updateTsConfigs({
|
|
20
|
+
references: await getReferences({
|
|
21
|
+
tsConfigs,
|
|
22
|
+
workspacePackage,
|
|
23
|
+
workspaces,
|
|
24
|
+
}),
|
|
25
|
+
tsConfigs,
|
|
26
|
+
workspacePackage,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
if (sync.length === 0) {
|
|
30
|
+
logger.warn('No project references to sync.');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const paths = await Promise.all(sync);
|
|
34
|
+
await runHooks(hooks, paths.flat());
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
|
|
3
|
+
import { run } from '../../utils.js';
|
|
4
|
+
|
|
5
|
+
import { config } from './options.js';
|
|
6
|
+
|
|
7
|
+
export const command = new Command('sync-project-references')
|
|
8
|
+
.description('sync TS project references in monorepo')
|
|
9
|
+
.addOption(config)
|
|
10
|
+
.action(async ({ config }) => {
|
|
11
|
+
const { action } = await import('./action.js');
|
|
12
|
+
await run(action({ config }));
|
|
13
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { SyncProjectReferencesConfig } from './types.js';
|
|
4
|
+
|
|
5
|
+
export const configSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
hooks: z
|
|
8
|
+
.object({
|
|
9
|
+
afterSync: z.array(z.string()).optional(),
|
|
10
|
+
})
|
|
11
|
+
.optional(),
|
|
12
|
+
tsConfigs: z
|
|
13
|
+
.object({
|
|
14
|
+
build: z.string().optional(),
|
|
15
|
+
default: z.string().optional(),
|
|
16
|
+
})
|
|
17
|
+
.optional(),
|
|
18
|
+
})
|
|
19
|
+
.strict() satisfies z.ZodType<SyncProjectReferencesConfig>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SyncProjectReferencesConfig } from './types.js';
|
|
2
|
+
|
|
3
|
+
const defaultConfig = {
|
|
4
|
+
tsConfigs: {
|
|
5
|
+
default: 'tsconfig.json',
|
|
6
|
+
build: 'tsconfig.build.json',
|
|
7
|
+
},
|
|
8
|
+
hooks: {
|
|
9
|
+
afterSync: ['prettier --write'],
|
|
10
|
+
},
|
|
11
|
+
} satisfies SyncProjectReferencesConfig;
|
|
12
|
+
|
|
13
|
+
export default defaultConfig;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { isNil } from '@apitree.cz/ts-utils';
|
|
4
|
+
import deepmerge from 'deepmerge';
|
|
5
|
+
import { pathExists } from 'path-exists';
|
|
6
|
+
import { ZodError } from 'zod';
|
|
7
|
+
|
|
8
|
+
import { configSchema } from './config-schema.js';
|
|
9
|
+
import * as defaultConfig from './default-config.js';
|
|
10
|
+
|
|
11
|
+
export interface GetConfigProps {
|
|
12
|
+
/**
|
|
13
|
+
* Path to config file (e.g. `./sync-project-references.config.js`).
|
|
14
|
+
*/
|
|
15
|
+
config?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Root directory to search for the config file.
|
|
18
|
+
*/
|
|
19
|
+
rootDir: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getPath = async ({ config, rootDir }: GetConfigProps) => {
|
|
23
|
+
if (config) {
|
|
24
|
+
const configPath = path.isAbsolute(config) ? config : path.join(rootDir, config);
|
|
25
|
+
if (await pathExists(configPath)) {
|
|
26
|
+
return configPath;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Config '${configPath}' does not exist.`);
|
|
29
|
+
}
|
|
30
|
+
const fallback = path.join(rootDir, 'sync-project-references.config.js');
|
|
31
|
+
if (await pathExists(fallback)) {
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const validate = async (config: unknown, path: string) => {
|
|
37
|
+
try {
|
|
38
|
+
await configSchema.parseAsync(config);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof ZodError) {
|
|
41
|
+
throw new TypeError(
|
|
42
|
+
`Config '${path}' is invalid:\n${error.errors
|
|
43
|
+
.map((error) => `- ${error.path.join('.')}: ${error.message}`)
|
|
44
|
+
.join('\n')}`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns config object from a provided path.
|
|
53
|
+
* If the config file does not exist, returns default config.
|
|
54
|
+
*/
|
|
55
|
+
export const getConfig = async (props: GetConfigProps) => {
|
|
56
|
+
const configPath = await getPath(props);
|
|
57
|
+
if (configPath) {
|
|
58
|
+
const config = (await import(configPath)) as typeof defaultConfig;
|
|
59
|
+
if (isNil(config.default)) {
|
|
60
|
+
throw new Error(`Config '${configPath}' does not have a default export.`);
|
|
61
|
+
}
|
|
62
|
+
await validate(config.default, configPath);
|
|
63
|
+
return deepmerge(defaultConfig.default, config.default, {
|
|
64
|
+
arrayMerge: (_, source: unknown[]) => source,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return defaultConfig.default;
|
|
68
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { pathExists } from 'path-exists';
|
|
4
|
+
|
|
5
|
+
import type { WorkspacePackageProps } from './types.js';
|
|
6
|
+
|
|
7
|
+
export interface GetExistingTsConfigPathProps extends WorkspacePackageProps {
|
|
8
|
+
/**
|
|
9
|
+
* TS config file name (e.g. `tsconfig.json`).
|
|
10
|
+
*/
|
|
11
|
+
tsConfig: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns path to TS config file of a provided name if it exists.
|
|
16
|
+
*/
|
|
17
|
+
export const getExistingTsConfigPath = async ({ tsConfig, workspacePackage }: GetExistingTsConfigPathProps) => {
|
|
18
|
+
const configPath = path.join(workspacePackage.dir, tsConfig);
|
|
19
|
+
const exists = await pathExists(configPath);
|
|
20
|
+
return exists ? configPath : undefined;
|
|
21
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { notNil } from '@apitree.cz/ts-utils';
|
|
4
|
+
import type { Package } from '@manypkg/get-packages';
|
|
5
|
+
|
|
6
|
+
import type { GetTargetBuildConfigProps } from './get-target-build-configs.js';
|
|
7
|
+
import { getTargetBuildConfigs } from './get-target-build-configs.js';
|
|
8
|
+
import { getWorkspaceDependencies } from './get-workspace-dependencies.js';
|
|
9
|
+
import { normalizePath } from './normalize-path.js';
|
|
10
|
+
|
|
11
|
+
export interface GetReferencesProps extends Pick<GetTargetBuildConfigProps, 'tsConfigs'> {
|
|
12
|
+
/**
|
|
13
|
+
* Workspace package to check and update references for.
|
|
14
|
+
*/
|
|
15
|
+
workspacePackage: Package;
|
|
16
|
+
/**
|
|
17
|
+
* List of workspaces to search for package references.
|
|
18
|
+
*/
|
|
19
|
+
workspaces: Package[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns list of package references to be added to its TS config.
|
|
24
|
+
*/
|
|
25
|
+
export const getReferences = async ({ tsConfigs, workspacePackage, workspaces }: GetReferencesProps) => {
|
|
26
|
+
const { dependencies } = await getWorkspaceDependencies({ workspacePackage, workspaces });
|
|
27
|
+
const references = await Promise.all(
|
|
28
|
+
dependencies.map(async (dependency) => {
|
|
29
|
+
const workspace = workspaces.find(({ packageJson }) => packageJson.name === dependency);
|
|
30
|
+
if (workspace) {
|
|
31
|
+
const { default: defaultConfig, build: buildConfig } = await getTargetBuildConfigs({
|
|
32
|
+
tsConfigs,
|
|
33
|
+
workspacePackage: workspace,
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
default: {
|
|
37
|
+
path: normalizePath(
|
|
38
|
+
path.join(path.relative(workspacePackage.dir, workspace.dir), buildConfig ?? defaultConfig),
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
build: buildConfig
|
|
42
|
+
? { path: normalizePath(path.join(path.relative(workspacePackage.dir, workspace.dir), buildConfig)) }
|
|
43
|
+
: undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
return references.filter(notNil).sort((a, b) => a.default.path.localeCompare(b.default.path));
|
|
49
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { pathExists } from 'path-exists';
|
|
4
|
+
import type { Object } from 'ts-toolbelt';
|
|
5
|
+
|
|
6
|
+
import type { SyncProjectReferencesTsConfigs, WorkspacePackageProps } from './types.js';
|
|
7
|
+
|
|
8
|
+
export interface GetTargetBuildConfigProps extends WorkspacePackageProps {
|
|
9
|
+
/**
|
|
10
|
+
* Configured package TS config names.
|
|
11
|
+
*/
|
|
12
|
+
tsConfigs: Object.NonNullable<Required<SyncProjectReferencesTsConfigs>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns target TS build config path relative to workspace root.
|
|
17
|
+
*/
|
|
18
|
+
export const getTargetBuildConfigs = async ({ tsConfigs, workspacePackage: { dir } }: GetTargetBuildConfigProps) => {
|
|
19
|
+
const buildPath = path.join(dir, tsConfigs.build);
|
|
20
|
+
return {
|
|
21
|
+
default: tsConfigs.default,
|
|
22
|
+
build: (await pathExists(buildPath)) ? tsConfigs.build : undefined,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import type { Package } from '@manypkg/get-packages';
|
|
5
|
+
|
|
6
|
+
import type { WorkspacePackageProps } from './types.js';
|
|
7
|
+
|
|
8
|
+
export interface GetPackageDependenciesProps extends WorkspacePackageProps {
|
|
9
|
+
/**
|
|
10
|
+
* List of workspaces to search for package dependencies.
|
|
11
|
+
*/
|
|
12
|
+
workspaces: Package[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns object containing package type and list of its internal (scoped) dependencies.
|
|
17
|
+
*/
|
|
18
|
+
export const getWorkspaceDependencies = async ({ workspacePackage, workspaces }: GetPackageDependenciesProps) => {
|
|
19
|
+
const {
|
|
20
|
+
dependencies = {},
|
|
21
|
+
devDependencies = {},
|
|
22
|
+
type = 'module',
|
|
23
|
+
} = JSON.parse(await readFile(path.join(workspacePackage.dir, 'package.json'), 'utf8')) as {
|
|
24
|
+
dependencies?: Record<string, string>;
|
|
25
|
+
devDependencies?: Record<string, string>;
|
|
26
|
+
type?: string;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
type,
|
|
30
|
+
dependencies: [...Object.keys(dependencies), ...Object.keys(devDependencies)].filter((dependency) =>
|
|
31
|
+
workspaces.some(({ packageJson }) => packageJson.name === dependency),
|
|
32
|
+
),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getPackages } from '@manypkg/get-packages';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns list of workspaces and their root directory.
|
|
5
|
+
*/
|
|
6
|
+
export const getWorkspaces = async () => {
|
|
7
|
+
const { packages: workspaces, rootDir } = await getPackages(process.cwd());
|
|
8
|
+
return { workspaces, rootDir };
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { command as syncProjectReferences } from './command.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Object } from 'ts-toolbelt';
|
|
2
|
+
|
|
3
|
+
import { exec } from '../../utils.js';
|
|
4
|
+
|
|
5
|
+
import type { SyncProjectReferencesHooks } from './types.js';
|
|
6
|
+
|
|
7
|
+
export const runHooks = async (hooks: Object.NonNullable<Required<SyncProjectReferencesHooks>>, paths: string[]) => {
|
|
8
|
+
const { afterSync } = hooks;
|
|
9
|
+
await Promise.all(afterSync.map((hook) => exec(`pnpm ${hook} ${paths.join(' ')}`)));
|
|
10
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Package } from '@manypkg/get-packages';
|
|
2
|
+
|
|
3
|
+
export interface SyncProjectReferencesHooks {
|
|
4
|
+
/**
|
|
5
|
+
* Hook called after the project references are synced.
|
|
6
|
+
* @defaultValue `['prettier --write']`
|
|
7
|
+
*/
|
|
8
|
+
afterSync?: string[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SyncProjectReferencesTsConfigs {
|
|
12
|
+
/**
|
|
13
|
+
* Name of the main TS config file.
|
|
14
|
+
* @defaultValue `'tsconfig.json'`
|
|
15
|
+
*/
|
|
16
|
+
default?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Name of the TS config file for build.
|
|
19
|
+
* @defaultValue `'tsconfig.build.json'`
|
|
20
|
+
*/
|
|
21
|
+
build?: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SyncProjectReferencesConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Custom hooks to run as parts of the sync process.
|
|
27
|
+
*/
|
|
28
|
+
hooks?: SyncProjectReferencesHooks | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Custom names for TS config files.
|
|
31
|
+
*/
|
|
32
|
+
tsConfigs?: SyncProjectReferencesTsConfigs | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface WorkspacePackageProps {
|
|
36
|
+
/**
|
|
37
|
+
* Workspace package.
|
|
38
|
+
*/
|
|
39
|
+
workspacePackage: Package;
|
|
40
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
import { notNil } from '@apitree.cz/ts-utils';
|
|
4
|
+
import type { Object as ObjectType } from 'ts-toolbelt';
|
|
5
|
+
|
|
6
|
+
import { logger } from '../../utils.js';
|
|
7
|
+
|
|
8
|
+
import { getExistingTsConfigPath } from './get-existing-ts-config-path.js';
|
|
9
|
+
import type { getReferences } from './get-references.js';
|
|
10
|
+
import type { SyncProjectReferencesTsConfigs, WorkspacePackageProps } from './types.js';
|
|
11
|
+
|
|
12
|
+
export interface UpdateTsConfigsProps extends WorkspacePackageProps {
|
|
13
|
+
/**
|
|
14
|
+
* List of workspace package references.
|
|
15
|
+
*/
|
|
16
|
+
references: Awaited<ReturnType<typeof getReferences>>;
|
|
17
|
+
/**
|
|
18
|
+
* List of configured TS config names to use for updating references.
|
|
19
|
+
*/
|
|
20
|
+
tsConfigs: ObjectType.NonNullable<Required<SyncProjectReferencesTsConfigs>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Updates references in all configured TS configs. Returns list of updated TS config paths.
|
|
25
|
+
*/
|
|
26
|
+
export const updateTsConfigs = async ({ references, tsConfigs, workspacePackage }: UpdateTsConfigsProps) => {
|
|
27
|
+
const entries = Object.entries(tsConfigs) as [keyof typeof tsConfigs, string][];
|
|
28
|
+
const paths = await Promise.all(
|
|
29
|
+
entries.map(async ([configType, configFile]) => {
|
|
30
|
+
const tsConfigPath = await getExistingTsConfigPath({
|
|
31
|
+
tsConfig: configFile,
|
|
32
|
+
workspacePackage,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (tsConfigPath) {
|
|
36
|
+
let tsConfigJson = {} as { references?: { path: string }[] };
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
tsConfigJson = JSON.parse(await readFile(tsConfigPath, 'utf8')) as typeof tsConfigJson;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
logger.error(`Error reading TS config file: ${tsConfigPath}`, error);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
tsConfigJson.references = references.map(
|
|
46
|
+
(reference) => reference[configType] ?? reference.build ?? reference.default,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
await writeFile(tsConfigPath, JSON.stringify(tsConfigJson).replaceAll('\r\n', '\n'));
|
|
50
|
+
return tsConfigPath;
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return paths.filter(notNil);
|
|
56
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './commands/sync-project-references/types.js';
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import childProcess from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
|
|
4
|
+
import { program } from '@commander-js/extra-typings';
|
|
5
|
+
|
|
6
|
+
export const exec = promisify(childProcess.exec);
|
|
7
|
+
|
|
8
|
+
/* eslint-disable no-console */
|
|
9
|
+
export const logger = {
|
|
10
|
+
error: console.error,
|
|
11
|
+
info: console.info,
|
|
12
|
+
warn: console.warn,
|
|
13
|
+
};
|
|
14
|
+
/* eslint-enable no-console */
|
|
15
|
+
|
|
16
|
+
export const run = async (action: Promise<void>) => {
|
|
17
|
+
try {
|
|
18
|
+
await action;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
program.error(String(error));
|
|
21
|
+
}
|
|
22
|
+
};
|