-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: asynchronously retrieve all collection info (schematics, genera…
…tors, builders and executors) (#1160)
- Loading branch information
Showing
23 changed files
with
622 additions
and
809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export * from './lib/abstract-tree-provider'; | ||
export * from './lib/extensions'; | ||
export * from './lib/stores'; | ||
export * from './lib/select-generator'; | ||
export * from './lib/telemetry'; | ||
export * from './lib/utils/output-channel'; | ||
export * from './lib/utils/read-projects'; | ||
export * from './lib/utils/read-generator-collections'; | ||
export * from './lib/utils/get-generators'; | ||
export * from './lib/utils/get-executors'; | ||
export * from './lib/utils/read-collections'; | ||
export { | ||
fileExistsSync, | ||
readAndParseJson, | ||
readAndCacheJsonFile, | ||
normalizeSchema, | ||
cacheJson, | ||
clearJsonCache, | ||
toWorkspaceFormat, | ||
listOfUnnestedNpmPackages, | ||
} from './lib/utils/utils'; | ||
export { watchFile } from './lib/utils/watch-file'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CollectionInfo } from '@nx-console/schema'; | ||
import { readCollectionsFromNodeModules } from './read-collections'; | ||
|
||
export async function getExecutors( | ||
workspaceJsonPath: string, | ||
clearPackageJsonCache: boolean | ||
): Promise<CollectionInfo[]> { | ||
return ( | ||
await readCollectionsFromNodeModules( | ||
workspaceJsonPath, | ||
clearPackageJsonCache | ||
) | ||
).filter((collection) => collection.type === 'executor'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { CollectionInfo, GeneratorType } from '@nx-console/schema'; | ||
import { basename, join } from 'path'; | ||
|
||
import { | ||
directoryExists, | ||
fileExistsSync, | ||
listFiles, | ||
normalizeSchema, | ||
readAndCacheJsonFile, | ||
} from './utils'; | ||
import { | ||
getCollectionInfo, | ||
readCollectionsFromNodeModules, | ||
} from './read-collections'; | ||
|
||
export async function getGenerators( | ||
workspaceJsonPath: string | ||
): Promise<CollectionInfo[]> { | ||
const basedir = join(workspaceJsonPath, '..'); | ||
const collections = await readCollectionsFromNodeModules( | ||
workspaceJsonPath, | ||
false | ||
); | ||
let generatorCollections = collections.filter( | ||
(collection) => collection.type === 'generator' | ||
); | ||
|
||
generatorCollections = [ | ||
...generatorCollections, | ||
...(await checkAndReadWorkspaceGenerators( | ||
basedir, | ||
join('tools', 'schematics') | ||
)), | ||
...(await checkAndReadWorkspaceGenerators( | ||
basedir, | ||
join('tools', 'generators') | ||
)), | ||
]; | ||
return generatorCollections.filter( | ||
(collection): collection is CollectionInfo => !!collection.data | ||
); | ||
} | ||
|
||
async function checkAndReadWorkspaceGenerators( | ||
basedir: string, | ||
workspaceGeneratorsPath: string | ||
) { | ||
if (await directoryExists(join(basedir, workspaceGeneratorsPath))) { | ||
const collection = await readWorkspaceGeneratorsCollection( | ||
basedir, | ||
workspaceGeneratorsPath | ||
); | ||
return collection; | ||
} | ||
return Promise.resolve([]); | ||
} | ||
|
||
async function readWorkspaceGeneratorsCollection( | ||
basedir: string, | ||
workspaceGeneratorsPath: string | ||
): Promise<CollectionInfo[]> { | ||
const collectionDir = join(basedir, workspaceGeneratorsPath); | ||
const collectionName = 'workspace-generator'; | ||
const collectionPath = join(collectionDir, 'collection.json'); | ||
if (fileExistsSync(collectionPath)) { | ||
const collection = await readAndCacheJsonFile( | ||
'collection.json', | ||
collectionDir | ||
); | ||
|
||
return getCollectionInfo( | ||
collectionName, | ||
collectionPath, | ||
collectionDir, | ||
{}, | ||
collection.json | ||
); | ||
} else { | ||
return await Promise.all( | ||
listFiles(collectionDir) | ||
.filter((f) => basename(f) === 'schema.json') | ||
.map(async (f) => { | ||
const schemaJson = await readAndCacheJsonFile(f, ''); | ||
const name = schemaJson.json.id || schemaJson.json.$id; | ||
const type: GeneratorType = | ||
schemaJson.json['x-type'] ?? GeneratorType.Other; | ||
return { | ||
name: collectionName, | ||
type: 'generator', | ||
path: collectionDir, | ||
data: { | ||
name, | ||
collection: collectionName, | ||
options: await normalizeSchema(schemaJson.json), | ||
description: '', | ||
type, | ||
}, | ||
} as CollectionInfo; | ||
}) | ||
); | ||
} | ||
} |
Oops, something went wrong.