fix(misc): cleanup migration to workspace-plugin

This commit is contained in:
AgentEnder 2023-04-21 12:26:35 -04:00 committed by Craigory Coppola
parent 06a885aca2
commit be768ca19d
7 changed files with 41 additions and 15 deletions

View File

@ -87,6 +87,11 @@
"enum": ["tsc", "swc"], "enum": ["tsc", "swc"],
"default": "tsc", "default": "tsc",
"description": "The compiler used by the build and test targets." "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"], "required": ["name"],

View File

@ -83,7 +83,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
...schema, ...schema,
config: 'project', config: 'project',
bundler: options.bundler, bundler: options.bundler,
publishable: true, publishable: options.publishable,
importPath: options.npmPackageName, importPath: options.npmPackageName,
skipFormat: true, skipFormat: true,
}) })

View File

@ -14,4 +14,5 @@ export interface Schema {
setParserOptionsProject?: boolean; setParserOptionsProject?: boolean;
compiler: 'swc' | 'tsc'; compiler: 'swc' | 'tsc';
rootProject?: boolean; rootProject?: boolean;
publishable?: boolean;
} }

View File

@ -87,6 +87,11 @@
"enum": ["tsc", "swc"], "enum": ["tsc", "swc"],
"default": "tsc", "default": "tsc",
"description": "The compiler used by the build and test targets." "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"] "required": ["name"]

View File

@ -18,6 +18,7 @@ export interface NormalizedSchema extends Schema {
npmScope: string; npmScope: string;
npmPackageName: string; npmPackageName: string;
bundler: 'swc' | 'tsc'; bundler: 'swc' | 'tsc';
publishable: boolean;
} }
export function normalizeOptions( export function normalizeOptions(
host: Tree, host: Tree,
@ -58,5 +59,6 @@ export function normalizeOptions(
projectDirectory: fullProjectDirectory, projectDirectory: fullProjectDirectory,
parsedTags, parsedTags,
npmPackageName, npmPackageName,
publishable: options.publishable ?? false,
}; };
} }

View File

@ -26,6 +26,7 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) {
importPath: options.pluginName, importPath: options.pluginName,
rootProject: true, rootProject: true,
e2eTestRunner: 'jest', e2eTestRunner: 'jest',
publishable: true,
}); });
tasks.push(pluginTask); tasks.push(pluginTask);

View File

@ -28,11 +28,24 @@ const PROJECT_NAME = 'workspace-plugin';
const DESTINATION = `tools/${PROJECT_NAME}`; const DESTINATION = `tools/${PROJECT_NAME}`;
export default async function (tree: Tree) { export default async function (tree: Tree) {
const tasks = []; if (!tree.exists('tools/generators')) {
if (!tree.children('tools/generators').length) {
return; 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); let project = getProjects(tree).get(PROJECT_NAME);
if (!project) { if (!project) {
await createNewPlugin(tree); await createNewPlugin(tree);
@ -48,21 +61,19 @@ export default async function (tree: Tree) {
project = readProjectConfiguration(tree, PROJECT_NAME); project = readProjectConfiguration(tree, PROJECT_NAME);
} }
await updateExistingPlugin(tree, project); await updateExistingPlugin(tree, project);
removeToolsGeneratorsIfEmpty(tree); return tasks;
await formatFiles(tree); }
return () => {
for (const task of tasks) { function hasWorkspaceGenerators(tree: Tree) {
task(); const children = tree.children('tools/generators');
} return (
}; children.length > 0 &&
!(children.length === 1 && children[0] === '.gitkeep')
);
} }
function removeToolsGeneratorsIfEmpty(tree: Tree) { function removeToolsGeneratorsIfEmpty(tree: Tree) {
const children = tree.children('tools/generators'); if (!hasWorkspaceGenerators(tree)) {
if (
children.length === 0 ||
(children.length === 1 && children[0] === '.gitkeep')
) {
tree.delete('tools/generators'); tree.delete('tools/generators');
} }
} }
@ -174,6 +185,7 @@ async function createNewPlugin(tree: Tree) {
skipLintChecks: false, skipLintChecks: false,
unitTestRunner: 'jest', unitTestRunner: 'jest',
e2eTestRunner: 'none', e2eTestRunner: 'none',
publishable: false,
}); });
getCreateGeneratorsJson()( getCreateGeneratorsJson()(
tree, tree,