fix(misc): cleanup migration to workspace-plugin
This commit is contained in:
parent
06a885aca2
commit
be768ca19d
@ -87,6 +87,11 @@
|
||||
"enum": ["tsc", "swc"],
|
||||
"default": "tsc",
|
||||
"description": "The compiler used by the build and test targets."
|
||||
},
|
||||
"publishable": {
|
||||
"type": "boolean",
|
||||
"description": "Generates a boilerplate for publishing the plugin to npm.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
|
||||
@ -83,7 +83,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
|
||||
...schema,
|
||||
config: 'project',
|
||||
bundler: options.bundler,
|
||||
publishable: true,
|
||||
publishable: options.publishable,
|
||||
importPath: options.npmPackageName,
|
||||
skipFormat: true,
|
||||
})
|
||||
|
||||
@ -14,4 +14,5 @@ export interface Schema {
|
||||
setParserOptionsProject?: boolean;
|
||||
compiler: 'swc' | 'tsc';
|
||||
rootProject?: boolean;
|
||||
publishable?: boolean;
|
||||
}
|
||||
|
||||
@ -87,6 +87,11 @@
|
||||
"enum": ["tsc", "swc"],
|
||||
"default": "tsc",
|
||||
"description": "The compiler used by the build and test targets."
|
||||
},
|
||||
"publishable": {
|
||||
"type": "boolean",
|
||||
"description": "Generates a boilerplate for publishing the plugin to npm.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["name"]
|
||||
|
||||
@ -18,6 +18,7 @@ export interface NormalizedSchema extends Schema {
|
||||
npmScope: string;
|
||||
npmPackageName: string;
|
||||
bundler: 'swc' | 'tsc';
|
||||
publishable: boolean;
|
||||
}
|
||||
export function normalizeOptions(
|
||||
host: Tree,
|
||||
@ -58,5 +59,6 @@ export function normalizeOptions(
|
||||
projectDirectory: fullProjectDirectory,
|
||||
parsedTags,
|
||||
npmPackageName,
|
||||
publishable: options.publishable ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) {
|
||||
importPath: options.pluginName,
|
||||
rootProject: true,
|
||||
e2eTestRunner: 'jest',
|
||||
publishable: true,
|
||||
});
|
||||
tasks.push(pluginTask);
|
||||
|
||||
|
||||
@ -28,11 +28,24 @@ const PROJECT_NAME = 'workspace-plugin';
|
||||
const DESTINATION = `tools/${PROJECT_NAME}`;
|
||||
|
||||
export default async function (tree: Tree) {
|
||||
const tasks = [];
|
||||
if (!tree.children('tools/generators').length) {
|
||||
if (!tree.exists('tools/generators')) {
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (hasWorkspaceGenerators(tree)) {
|
||||
tasks.push(...(await moveWorkspaceGeneratorsToLocalPlugin(tree)));
|
||||
}
|
||||
removeToolsGeneratorsIfEmpty(tree);
|
||||
await formatFiles(tree);
|
||||
return () => {
|
||||
for (const task of tasks) {
|
||||
task();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function moveWorkspaceGeneratorsToLocalPlugin(tree: Tree) {
|
||||
const tasks = [];
|
||||
let project = getProjects(tree).get(PROJECT_NAME);
|
||||
if (!project) {
|
||||
await createNewPlugin(tree);
|
||||
@ -48,21 +61,19 @@ export default async function (tree: Tree) {
|
||||
project = readProjectConfiguration(tree, PROJECT_NAME);
|
||||
}
|
||||
await updateExistingPlugin(tree, project);
|
||||
removeToolsGeneratorsIfEmpty(tree);
|
||||
await formatFiles(tree);
|
||||
return () => {
|
||||
for (const task of tasks) {
|
||||
task();
|
||||
return tasks;
|
||||
}
|
||||
};
|
||||
|
||||
function hasWorkspaceGenerators(tree: Tree) {
|
||||
const children = tree.children('tools/generators');
|
||||
return (
|
||||
children.length > 0 &&
|
||||
!(children.length === 1 && children[0] === '.gitkeep')
|
||||
);
|
||||
}
|
||||
|
||||
function removeToolsGeneratorsIfEmpty(tree: Tree) {
|
||||
const children = tree.children('tools/generators');
|
||||
if (
|
||||
children.length === 0 ||
|
||||
(children.length === 1 && children[0] === '.gitkeep')
|
||||
) {
|
||||
if (!hasWorkspaceGenerators(tree)) {
|
||||
tree.delete('tools/generators');
|
||||
}
|
||||
}
|
||||
@ -174,6 +185,7 @@ async function createNewPlugin(tree: Tree) {
|
||||
skipLintChecks: false,
|
||||
unitTestRunner: 'jest',
|
||||
e2eTestRunner: 'none',
|
||||
publishable: false,
|
||||
});
|
||||
getCreateGeneratorsJson()(
|
||||
tree,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user