Skip to content

Commit 384f95e

Browse files
committed
feat(plugin): add aux generator
1 parent 3299231 commit 384f95e

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

libs/plugin/generators.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"factory": "./src/generators/gltf/gltf",
1010
"schema": "./src/generators/gltf/schema.json",
1111
"description": "gltf generator"
12+
},
13+
"aux": {
14+
"factory": "./src/generators/aux/aux",
15+
"schema": "./src/generators/aux/schema.json",
16+
"description": "aux generator"
1217
}
1318
},
1419
"schematics": {
@@ -21,6 +26,11 @@
2126
"factory": "./src/generators/gltf/compat",
2227
"schema": "./src/generators/gltf/schema.json",
2328
"description": "gltf generator"
29+
},
30+
"aux": {
31+
"factory": "./src/generators/aux/compat",
32+
"schema": "./src/generators/aux/schema.json",
33+
"description": "aux generator"
2434
}
2535
}
2636
}

libs/plugin/src/generators/aux/aux.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { addDependenciesToPackageJson, formatFiles, installPackagesTask, logger, readJson, Tree } from '@nx/devkit';
2+
import { prompt } from 'enquirer';
3+
import { PEER_DEPENDENCIES } from '../../versions';
4+
5+
export async function auxGenerator(tree: Tree) {
6+
logger.info('[NGT] Initialize auxiliary packages');
7+
8+
const packageJson = readJson(tree, 'package.json');
9+
if (!packageJson) {
10+
logger.warn(`[NGT] PackageJson not found in: ${tree.root}`);
11+
return;
12+
}
13+
14+
const ngtVersion =
15+
packageJson['dependencies']?.['angular-three'] || packageJson['devDependencies']?.['angular-three'];
16+
17+
if (!ngtVersion) {
18+
logger.warn(`[NGT] angular-three is not installed.`);
19+
return;
20+
}
21+
22+
const { packages } = await prompt<{ packages: string[] }>({
23+
type: 'multiselect',
24+
name: 'packages',
25+
message: 'Which packages to add?',
26+
choices: ['angular-three-soba', 'angular-three-rapier', 'angular-three-postprocessing', 'angular-three-cannon'],
27+
});
28+
29+
const packagesToAdd = {};
30+
31+
for (const pkg of packages) {
32+
const exist = packageJson['dependencies']?.[pkg] || packageJson['devDependencies']?.[pkg];
33+
if (exist) {
34+
logger.warn(`[NGT] ${pkg} is already installed. Skipping`);
35+
continue;
36+
}
37+
38+
packagesToAdd[pkg] = ngtVersion;
39+
40+
if (PEER_DEPENDENCIES[pkg]) {
41+
for (const depName in PEER_DEPENDENCIES[pkg]) {
42+
packagesToAdd[depName] = PEER_DEPENDENCIES[pkg][depName];
43+
}
44+
}
45+
}
46+
47+
if (Object.keys(packagesToAdd).length === 0) {
48+
console.warn(`[NGT] No packages to add`);
49+
return;
50+
}
51+
52+
addDependenciesToPackageJson(tree, packagesToAdd, {});
53+
54+
await formatFiles(tree);
55+
56+
return () => {
57+
installPackagesTask(tree);
58+
};
59+
}
60+
61+
export default auxGenerator;
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 auxGenerator from './aux';
3+
4+
export default convertNxGenerator(auxGenerator);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cli": "nx",
3+
"$id": "Init",
4+
"title": "Init aux package",
5+
"type": "object",
6+
"properties": {}
7+
}

libs/plugin/src/versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const THREE_VERSION = '^0.173.0';
33
export const THREE_TYPE_VERSION = '^0.173.0';
44
export const NGXTENSION_VERSION = '^4.0.0';
55

6-
export const PEER_DEPENDENCIES = {
6+
export const PEER_DEPENDENCIES: Record<string, Record<string, string>> = {
77
'angular-three-soba': {
88
'three-stdlib': '^2.0.0',
99
'@pmndrs/vanilla': '^1.20.0',

0 commit comments

Comments
 (0)