Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workspace-plugin): scaffold split-library-in-two generator #30994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/workspace-plugin/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
"factory": "./src/generators/bundle-size-configuration/generator",
"schema": "./src/generators/bundle-size-configuration/schema.json",
"description": "bundle-size-configuration generator"
},
"split-library-in-two": {
"factory": "./src/generators/split-library-in-two/generator",
"schema": "./src/generators/split-library-in-two/schema.json",
"description": "split-library-in-two generator"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const variable = "<%= name %>";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { splitLibraryInTwoGenerator } from './generator';
import { SplitLibraryInTwoGeneratorSchema } from './schema';

describe('split-library-in-two generator', () => {
let tree: Tree;
const options: SplitLibraryInTwoGeneratorSchema = { name: 'test' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should run successfully', async () => {
await splitLibraryInTwoGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { addProjectConfiguration, formatFiles, generateFiles, Tree } from '@nx/devkit';
import * as path from 'path';
import { SplitLibraryInTwoGeneratorSchema } from './schema';

export async function splitLibraryInTwoGenerator(tree: Tree, options: SplitLibraryInTwoGeneratorSchema) {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {
root: projectRoot,
projectType: 'library',
sourceRoot: `${projectRoot}/src`,
targets: {},
});
generateFiles(tree, path.join(__dirname, 'files'), projectRoot, options);
await formatFiles(tree);
}

export default splitLibraryInTwoGenerator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface SplitLibraryInTwoGeneratorSchema {
name: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json-schema.org/schema",
"$id": "SplitLibraryInTwo",
"title": "",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
}
},
"required": ["name"]
}
Loading