@rxap/workspace-ts-morph 0.0.2-dev.0
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/CHANGELOG.md +8 -0
- package/GETSTARTED.md +0 -0
- package/GUIDES.md +0 -0
- package/README.md +21 -0
- package/package.json +56 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +9 -0
- package/src/index.js.map +1 -0
- package/src/lib/add-dir.d.ts +10 -0
- package/src/lib/add-dir.js +69 -0
- package/src/lib/add-dir.js.map +1 -0
- package/src/lib/apply-ts-morph-project.d.ts +3 -0
- package/src/lib/apply-ts-morph-project.js +71 -0
- package/src/lib/apply-ts-morph-project.js.map +1 -0
- package/src/lib/ts-morph-transform.d.ts +26 -0
- package/src/lib/ts-morph-transform.js +81 -0
- package/src/lib/ts-morph-transform.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 0.0.2-dev.0 (2023-08-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/workspace-ts-morph
|
package/GETSTARTED.md
ADDED
|
File without changes
|
package/GUIDES.md
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @rxap/workspace-ts-morph
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rxap/workspace-ts-morph)
|
|
4
|
+
[](https://commitizen.github.io/cz-cli/)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
|
|
12
|
+
# Installation
|
|
13
|
+
|
|
14
|
+
**Add the package to your workspace:**
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @rxap/workspace-ts-morph
|
|
17
|
+
```
|
|
18
|
+
**Install peer dependencies:**
|
|
19
|
+
```bash
|
|
20
|
+
yarn add
|
|
21
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rxap/workspace-ts-morph",
|
|
3
|
+
"version": "0.0.2-dev.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"directory": "../../../dist/packages/workspace/ts-morph"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"rxap",
|
|
11
|
+
"packages",
|
|
12
|
+
"workspace",
|
|
13
|
+
"ts-morph"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https:/gitlab.com/rxap/packages/packages/workspace/ts-morph",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://gitlab.com/rxap/packages/-/issues",
|
|
18
|
+
"email": "incoming+rxap-packages-14898188-issue-@incoming.gitlab.com"
|
|
19
|
+
},
|
|
20
|
+
"license": "GPL-3.0-or-later",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://gitlab.com/rxap/packages.git",
|
|
24
|
+
"directory": "packages/workspace/ts-morph"
|
|
25
|
+
},
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Merzough Münker",
|
|
28
|
+
"email": "mmuenker@digitaix.com"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"ignore": "^5.2.4",
|
|
32
|
+
"semver": "^7.3.5",
|
|
33
|
+
"tslib": "2.6.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@rxap/utilities": "^16.0.0-dev.4",
|
|
37
|
+
"@rxap/workspace-utilities": "^0.1.0-dev.0",
|
|
38
|
+
"ts-morph": "^18.0.0",
|
|
39
|
+
"@rxap/node-utilities": "1.0.1-dev.2"
|
|
40
|
+
},
|
|
41
|
+
"nx-migrations": {
|
|
42
|
+
"packageGroup": [
|
|
43
|
+
{
|
|
44
|
+
"package": "@rxap/utilities",
|
|
45
|
+
"version": "16.0.0-dev.4"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"package": "@rxap/workspace-utilities",
|
|
49
|
+
"version": "0.1.0-dev.0"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "ed3a0788894aa734ec2a8e9e957cf73cabe033d6",
|
|
54
|
+
"main": "./src/index.js",
|
|
55
|
+
"types": "./src/index.d.ts"
|
|
56
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// region
|
|
5
|
+
tslib_1.__exportStar(require("./lib/add-dir"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/apply-ts-morph-project"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/ts-morph-transform"), exports);
|
|
8
|
+
// endregion
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/workspace/ts-morph/src/index.ts"],"names":[],"mappings":";;;AAAA,UAAU;AACV,wDAA8B;AAC9B,uEAA6C;AAC7C,mEAAyC;AACzC,YAAY"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TreeLike } from '@rxap/workspace-utilities';
|
|
2
|
+
import { Project } from 'ts-morph';
|
|
3
|
+
/**
|
|
4
|
+
* Adds all files recursively from a specify path to the project.
|
|
5
|
+
* @param tree A nx Tree instance
|
|
6
|
+
* @param directoryPath A directory path
|
|
7
|
+
* @param project A ts-morph Project instance
|
|
8
|
+
* @param filter A filter function base on the pathFragment and dirEntry
|
|
9
|
+
*/
|
|
10
|
+
export declare function AddDir(tree: TreeLike, directoryPath: string, project: Project, filter?: ((fileName: string, dirPath: string) => boolean), basePath?: string): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddDir = void 0;
|
|
4
|
+
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* Adds all files recursively from a specify path to the project.
|
|
8
|
+
* @param tree A nx Tree instance
|
|
9
|
+
* @param directoryPath A directory path
|
|
10
|
+
* @param project A ts-morph Project instance
|
|
11
|
+
* @param filter A filter function base on the pathFragment and dirEntry
|
|
12
|
+
*/
|
|
13
|
+
function AddDir(tree, directoryPath, project, filter = path => path.endsWith('.ts'), basePath = directoryPath) {
|
|
14
|
+
if ((0, workspace_utilities_1.IsSchematicTreeLike)(tree)) {
|
|
15
|
+
return SchematicAddDir(tree.getDir(directoryPath), project, '', (pathFragment, dirEntry) => filter(pathFragment, dirEntry.path));
|
|
16
|
+
}
|
|
17
|
+
if ((0, workspace_utilities_1.IsGeneratorTreeLike)(tree)) {
|
|
18
|
+
if (tree.isFile(directoryPath)) {
|
|
19
|
+
throw new Error(`The path '${directoryPath}' does not point to a dir entry`);
|
|
20
|
+
}
|
|
21
|
+
const children = tree.children(directoryPath);
|
|
22
|
+
const files = children.filter(fileOrDirectoryName => tree.isFile((0, path_1.join)(directoryPath, fileOrDirectoryName)));
|
|
23
|
+
const includeFiles = files.filter(fileName => filter(fileName, directoryPath));
|
|
24
|
+
for (const fileName of includeFiles) {
|
|
25
|
+
const filePath = (0, path_1.join)(directoryPath, fileName);
|
|
26
|
+
const projectFilePath = (0, path_1.relative)(basePath, filePath);
|
|
27
|
+
if (!project.getSourceFile(projectFilePath)) {
|
|
28
|
+
project.createSourceFile(projectFilePath, tree.read(filePath).toString('utf-8'));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const dirName of tree.children(directoryPath).filter(pf => !tree.isFile((0, path_1.join)(directoryPath, pf)))) {
|
|
32
|
+
AddDir(tree, (0, path_1.join)(directoryPath, dirName), project, filter, basePath);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
throw new Error('The tree is not a valid nx or angular schematic tree');
|
|
37
|
+
}
|
|
38
|
+
exports.AddDir = AddDir;
|
|
39
|
+
/**
|
|
40
|
+
* Adds all files recursively from a specify DirEntry to the project.
|
|
41
|
+
* @param dir A schematic DirEntry instance
|
|
42
|
+
* @param project A ts-morph Project instance
|
|
43
|
+
* @param parentPath The base dir for the sourceFiles in the ts-morph Project
|
|
44
|
+
* @param filter A filter function base on the pathFragment and dirEntry
|
|
45
|
+
*/
|
|
46
|
+
function SchematicAddDir(dir, project, parentPath = '', filter = pathFragment => !!pathFragment.match(/\.ts$/)) {
|
|
47
|
+
for (const pathFragment of dir.subfiles.filter(pf => filter(pf, dir))) {
|
|
48
|
+
const fileEntry = dir.file(pathFragment);
|
|
49
|
+
if (fileEntry) {
|
|
50
|
+
const filePath = (0, path_1.join)(parentPath, pathFragment);
|
|
51
|
+
if (!project.getSourceFile(filePath)) {
|
|
52
|
+
project.createSourceFile(filePath, fileEntry.content.toString('utf-8'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error('The path fragment does not point to a file entry');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const pathFragment of dir.subdirs) {
|
|
60
|
+
const dirEntry = dir.dir(pathFragment);
|
|
61
|
+
if (dirEntry) {
|
|
62
|
+
SchematicAddDir(dirEntry, project, (0, path_1.join)(parentPath, pathFragment), filter);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error('The path fragment does not point to a dir entry');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=add-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EAAE;gBACpC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;aACzE;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACrE;KACF;IACD,KAAK,MAAM,YAAY,IAAI,GAAG,CAAC,OAAO,EAAE;QACtC,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACvC,IAAI,QAAQ,EAAE;YACZ,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAA,WAAI,EAAC,UAAU,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;SAC5E;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACpE;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplyTsMorphProject = void 0;
|
|
4
|
+
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
function areSame(sourceFile1, sourceFile2) {
|
|
8
|
+
const leafNodes1 = getLeafNodes(sourceFile1);
|
|
9
|
+
const leafNodes2 = getLeafNodes(sourceFile2);
|
|
10
|
+
// eslint-disable-next-line no-constant-condition
|
|
11
|
+
while (true) {
|
|
12
|
+
const leaf1 = leafNodes1.next();
|
|
13
|
+
const leaf2 = leafNodes2.next();
|
|
14
|
+
if (leaf1.done && leaf2.done) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (leaf1.done || leaf2.done) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (leaf1.value.getText() !== leaf2.value.getText()) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function* getLeafNodes(sourceFile) {
|
|
25
|
+
yield* searchNode(sourceFile);
|
|
26
|
+
function* searchNode(node) {
|
|
27
|
+
const children = node.getChildren();
|
|
28
|
+
if (children.length === 0) {
|
|
29
|
+
yield node;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
for (const child of children) {
|
|
33
|
+
yield* searchNode(child);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = true, fixMissingImports = false) {
|
|
40
|
+
if (organizeImports || fixMissingImports) {
|
|
41
|
+
project
|
|
42
|
+
.getSourceFiles()
|
|
43
|
+
.forEach(sourceFile => {
|
|
44
|
+
if (fixMissingImports) {
|
|
45
|
+
sourceFile.fixMissingImports();
|
|
46
|
+
}
|
|
47
|
+
if (organizeImports) {
|
|
48
|
+
sourceFile.organizeImports();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const treeAdapter = new workspace_utilities_1.TreeAdapter(tree);
|
|
53
|
+
project
|
|
54
|
+
.getSourceFiles()
|
|
55
|
+
.forEach(sourceFile => {
|
|
56
|
+
const filePath = (0, path_1.join)(basePath, sourceFile.getFilePath());
|
|
57
|
+
if (tree.exists(filePath)) {
|
|
58
|
+
const currentContent = treeAdapter.read(filePath).toString('utf-8');
|
|
59
|
+
const tmpProject = new ts_morph_1.Project();
|
|
60
|
+
const newContent = sourceFile.getFullText();
|
|
61
|
+
if (!areSame(sourceFile, tmpProject.createSourceFile('/tmp.ts', currentContent))) {
|
|
62
|
+
treeAdapter.overwrite(filePath, newContent);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
treeAdapter.create(filePath, sourceFile.getFullText());
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.ApplyTsMorphProject = ApplyTsMorphProject;
|
|
71
|
+
//# sourceMappingURL=apply-ts-morph-project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-ts-morph-project.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/apply-ts-morph-project.ts"],"names":[],"mappings":";;;AAAA,mEAGmC;AACnC,+BAA4B;AAC5B,uCAIkB;AAElB,SAAS,OAAO,CAAC,WAAuB,EAAE,WAAuB;IAC/D,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAE7C,iDAAiD;IACjD,OAAO,IAAI,EAAE;QACX,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAEhC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE;YAC5B,OAAO,IAAI,CAAC;SACb;QACD,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE;YAC5B,OAAO,KAAK,CAAC;SACd;QACD,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE;YACnD,OAAO,KAAK,CAAC;SACd;KACF;IAED,QAAQ,CAAC,CAAC,YAAY,CAAC,UAAsB;QAC3C,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE9B,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAU;YAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBACzB,MAAM,IAAI,CAAC;aACZ;iBAAM;gBACL,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;oBAC5B,KAAK,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;iBAC1B;aACF;QACH,CA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,0 +1,26 @@
|
|
|
1
|
+
import { BuildAngularBasePathOptions, TreeLike } from '@rxap/workspace-utilities';
|
|
2
|
+
import { Project, ProjectOptions, SourceFile } from 'ts-morph';
|
|
3
|
+
export type TsMorphTransformCallback = ((project: Project, sourceFile: undefined) => void) | ((project: Project, sourceFile: SourceFile) => void) | ((project: Project, sourceFile: SourceFile[]) => void);
|
|
4
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: SourceFile[]) => void, options?: Partial<ProjectOptions>, filePath?: string[]): void;
|
|
5
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: SourceFile) => void, options?: Partial<ProjectOptions>, filePath?: string): void;
|
|
6
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: undefined) => void, options?: Partial<ProjectOptions>, filePath?: undefined): void;
|
|
7
|
+
export interface TsMorphNestProjectTransformOptions {
|
|
8
|
+
project: string;
|
|
9
|
+
feature?: string | null;
|
|
10
|
+
shared?: boolean;
|
|
11
|
+
directory?: string | null;
|
|
12
|
+
projectOptions?: Partial<ProjectOptions>;
|
|
13
|
+
}
|
|
14
|
+
export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Readonly<TsMorphNestProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile[]) => void, filePath: string[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated pass the filePath as array
|
|
17
|
+
*/
|
|
18
|
+
export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Readonly<TsMorphNestProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile) => void, filePath: string): void;
|
|
19
|
+
export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Readonly<TsMorphNestProjectTransformOptions>, cb: (project: Project, sourceFile: undefined) => void, filePath?: undefined): void;
|
|
20
|
+
export interface TsMorphAngularProjectTransformOptions extends BuildAngularBasePathOptions {
|
|
21
|
+
projectOptions?: Partial<ProjectOptions>;
|
|
22
|
+
}
|
|
23
|
+
export declare function TsMorphAngularProjectTransform(tree: TreeLike, options: Readonly<TsMorphAngularProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile[]) => void, filePath: string[]): void;
|
|
24
|
+
export declare function TsMorphAngularProjectTransform(tree: TreeLike, options: Readonly<TsMorphAngularProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile) => void, filePath: string): void;
|
|
25
|
+
export declare function TsMorphAngularProjectTransform(tree: TreeLike, options: Readonly<TsMorphAngularProjectTransformOptions>, cb: (project: Project, sourceFile: undefined) => void, filePath?: undefined): void;
|
|
26
|
+
export type TsMorphTransformFunction<Options extends TsMorphNestProjectTransformOptions | TsMorphAngularProjectTransformOptions> = ((tree: TreeLike, options: Readonly<Options>, cb: (project: Project, sourceFile: SourceFile[]) => void, filePath: string[]) => void);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TsMorphAngularProjectTransform = exports.TsMorphNestProjectTransform = exports.TsMorphTransform = void 0;
|
|
4
|
+
const utilities_1 = require("@rxap/utilities");
|
|
5
|
+
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const add_dir_1 = require("./add-dir");
|
|
9
|
+
const apply_ts_morph_project_1 = require("./apply-ts-morph-project");
|
|
10
|
+
function TsMorphTransform(tree, sourceRoot, cb, options = {}, filePathFilter) {
|
|
11
|
+
const filePath = filePathFilter ?
|
|
12
|
+
Array.isArray(filePathFilter) ?
|
|
13
|
+
filePathFilter.map(f => f.replace(/\?$/, '')) :
|
|
14
|
+
[filePathFilter.replace(/\?$/, '')] :
|
|
15
|
+
undefined;
|
|
16
|
+
const project = new ts_morph_1.Project((0, utilities_1.deepMerge)({
|
|
17
|
+
manipulationSettings: {
|
|
18
|
+
indentationText: ts_morph_1.IndentationText.TwoSpaces,
|
|
19
|
+
quoteKind: ts_morph_1.QuoteKind.Single,
|
|
20
|
+
},
|
|
21
|
+
useInMemoryFileSystem: true,
|
|
22
|
+
}, options));
|
|
23
|
+
(0, add_dir_1.AddDir)(tree, sourceRoot, project, filePath ?
|
|
24
|
+
(fileName, dirPath) => {
|
|
25
|
+
const fullPath = (0, path_1.join)(dirPath, fileName);
|
|
26
|
+
if (dirPath.endsWith(fileName)) {
|
|
27
|
+
throw new Error(`The dirPath '${dirPath}' ends with the fileName '${fileName}'`);
|
|
28
|
+
}
|
|
29
|
+
return filePath.some(f => fullPath.endsWith(f));
|
|
30
|
+
} :
|
|
31
|
+
undefined);
|
|
32
|
+
let sourceFile = undefined;
|
|
33
|
+
if (filePath) {
|
|
34
|
+
if (Array.isArray(filePath)) {
|
|
35
|
+
sourceFile = filePath.map((f, index) => {
|
|
36
|
+
var _a;
|
|
37
|
+
let sf = project.getSourceFile(f);
|
|
38
|
+
if (!sf) {
|
|
39
|
+
if (Array.isArray(filePathFilter)) {
|
|
40
|
+
if ((_a = filePathFilter[index]) === null || _a === void 0 ? void 0 : _a.endsWith('?')) {
|
|
41
|
+
sf = project.createSourceFile(f, '');
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log(project.getSourceFiles().map(f => f.getFilePath()));
|
|
45
|
+
throw new Error(`The file ${f} does not exists with the source root ${sourceRoot}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (index !== 0) {
|
|
50
|
+
throw new Error('FATAL: The filePathFilter is not an array and the index is not 0');
|
|
51
|
+
}
|
|
52
|
+
if (filePathFilter === null || filePathFilter === void 0 ? void 0 : filePathFilter.endsWith('?')) {
|
|
53
|
+
sf = project.createSourceFile(f, '');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error(`The file ${f} does not exists with the source root ${sourceRoot}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return sf;
|
|
61
|
+
});
|
|
62
|
+
if (!Array.isArray(filePathFilter)) {
|
|
63
|
+
sourceFile = sourceFile[0];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
cb(project, sourceFile);
|
|
68
|
+
(0, apply_ts_morph_project_1.ApplyTsMorphProject)(tree, project, sourceRoot, false);
|
|
69
|
+
}
|
|
70
|
+
exports.TsMorphTransform = TsMorphTransform;
|
|
71
|
+
function TsMorphNestProjectTransform(tree, options, cb, filePath) {
|
|
72
|
+
const basePath = (0, workspace_utilities_1.BuildNestBasePath)(tree, options);
|
|
73
|
+
return TsMorphTransform(tree, basePath, cb, options.projectOptions, filePath);
|
|
74
|
+
}
|
|
75
|
+
exports.TsMorphNestProjectTransform = TsMorphNestProjectTransform;
|
|
76
|
+
function TsMorphAngularProjectTransform(tree, options, cb, filePath) {
|
|
77
|
+
const basePath = (0, workspace_utilities_1.BuildAngularBasePath)(tree, options);
|
|
78
|
+
return TsMorphTransform(tree, basePath, cb, options.projectOptions, filePath);
|
|
79
|
+
}
|
|
80
|
+
exports.TsMorphAngularProjectTransform = TsMorphAngularProjectTransform;
|
|
81
|
+
//# sourceMappingURL=ts-morph-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-morph-transform.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/ts-morph-transform.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,mEAKmC;AACnC,+BAA4B;AAC5B,uCAMkB;AAClB,uCAAmC;AACnC,qEAA+D;AA2B/D,SAAgB,gBAAgB,CAC9B,IAAc,EACd,UAAkB,EAClB,EAA4B,EAC5B,UAAmC,EAAE,EACrC,cAA8C;IAE9C,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC;QAC/B,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YAC7B,cAAc,CAAC,GAAG,CAAC,CAAC,C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