Skip to content

Commit

Permalink
feat(workspace-plugin): scaffold split-library-in-two generator (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell authored Apr 10, 2024
1 parent 10f7b0e commit 73b1090
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
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"]
}

0 comments on commit 73b1090

Please sign in to comment.