Skip to content

Commit baa9cd0

Browse files
committed
wip
1 parent 5492653 commit baa9cd0

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

libs/plugin/generators.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"description": "aux generator"
1717
},
1818
"migrate-tweakpane": {
19-
"factory": "./src/migrations/migrate-tweakpane/migrate-tweakpane",
19+
"factory": "./src/generators/migrate-tweakpane/migrate-tweakpane",
20+
"schema": "./src/generators/migrate-tweakpane/schema.json",
2021
"description": "Migration tweakpane"
2122
}
2223
},
@@ -37,7 +38,8 @@
3738
"description": "aux generator"
3839
},
3940
"migrate-tweakpane": {
40-
"factory": "./src/migrations/migrate-tweakpane/compat",
41+
"factory": "./src/generators/migrate-tweakpane/compat",
42+
"schema": "./src/generators/migrate-tweakpane/schema.json",
4143
"description": "Migration tweakpane"
4244
}
4345
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { convertNxGenerator } from '@nx/devkit';
2+
import migrateTweakpane from './migrate-tweakpane';
3+
4+
export default convertNxGenerator(migrateTweakpane);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { formatFiles, getProjects, readProjectConfiguration, Tree, visitNotIgnoredFiles } from '@nx/devkit';
2+
3+
export interface MigrateTweakpaneGeneratorSchema {
4+
project?: string;
5+
}
6+
7+
export async function migrateTweakpane(tree: Tree, options: MigrateTweakpaneGeneratorSchema) {
8+
if (options.project) {
9+
const project = readProjectConfiguration(tree, options.project);
10+
migrateByPath(tree, project.root);
11+
} else {
12+
const projects = getProjects(tree);
13+
14+
for (const projectName of projects.keys()) {
15+
const projectConfig = projects.get(projectName);
16+
if (!projectConfig) continue;
17+
18+
migrateByPath(tree, projectConfig.root);
19+
}
20+
}
21+
22+
await formatFiles(tree);
23+
}
24+
25+
function migrateByPath(tree: Tree, root: string) {
26+
visitNotIgnoredFiles(tree, root, (path) => {
27+
const fileContent = tree.read(path, 'utf-8');
28+
if (fileContent) {
29+
const updatedContent = fileContent
30+
.replaceAll('ngt-tweak', 'tweakpane')
31+
.replace(/NgtTweak([A-Za-z]*)/g, 'Tweakpane$1');
32+
if (fileContent !== updatedContent) {
33+
tree.write(path, updatedContent);
34+
}
35+
}
36+
});
37+
}
38+
39+
export default migrateTweakpane;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"cli": "nx",
3+
"$id": "MigrateTweakpane",
4+
"title": "Migrate angular-three-tweakpane selectors and symbols",
5+
"type": "object",
6+
"properties": {
7+
"project": {
8+
"type": "string",
9+
"description": "The project to run migration for.",
10+
"x-prompt": "Which project to run 'migrate-tweakpane'?",
11+
"x-dropdown": "projects"
12+
}
13+
}
14+
}
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
import { formatFiles, getProjects, Tree, visitNotIgnoredFiles } from '@nx/devkit';
1+
import { Tree } from '@nx/devkit';
2+
import migrateTweakpane from '../../generators/migrate-tweakpane/migrate-tweakpane';
23

34
export default async function update(host: Tree) {
4-
const projects = getProjects(host);
5-
6-
for (const projectName of projects.keys()) {
7-
const projectConfig = projects.get(projectName);
8-
if (!projectConfig) continue;
9-
10-
visitNotIgnoredFiles(host, projectConfig.root, (path) => {
11-
const fileContent = host.read(path, 'utf-8');
12-
if (fileContent) {
13-
const updatedContent = fileContent
14-
.replaceAll('ngt-tweak', 'tweakpane')
15-
.replace(/NgtTweak([A-Za-z]*)/g, 'Tweakpane$1');
16-
if (fileContent !== updatedContent) {
17-
host.write(path, updatedContent);
18-
}
19-
}
20-
});
21-
}
22-
23-
await formatFiles(host);
5+
await migrateTweakpane(host, {});
246
}

0 commit comments

Comments
 (0)