Skip to content

Commit

Permalink
feat(nx-plugin): add create-package plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Mar 31, 2023
1 parent 64b44d3 commit 4d0bb6f
Show file tree
Hide file tree
Showing 28 changed files with 633 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ jobs:
- rust/install
- run:
name: Run E2E Tests for macOS
# FIXME: remove --exclude=e2e-detox once we have a fix for the detox tests
command: |
npx nx run-many -t e2e-macos --parallel=1 --exclude=e2e-detox
npx nx run-many -t e2e-macos --parallel=1
no_output_timeout: 45m

# -------------------------
Expand Down
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -5448,6 +5448,14 @@
"isExternal": false,
"disableCollapsible": false
},
{
"id": "create-package",
"path": "/packages/nx-plugin/generators/create-package",
"name": "create-package",
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "e2e-project",
"path": "/packages/nx-plugin/generators/e2e-project",
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,15 @@
"path": "/packages/nx-plugin/generators/plugin",
"type": "generator"
},
"/packages/nx-plugin/generators/create-package": {
"description": "Create a framework package that uses Nx CLI",
"file": "generated/packages/nx-plugin/generators/create-package.json",
"hidden": false,
"name": "create-package",
"originalFilePath": "/packages/nx-plugin/src/generators/create-package/schema.json",
"path": "/packages/nx-plugin/generators/create-package",
"type": "generator"
},
"/packages/nx-plugin/generators/e2e-project": {
"description": "Create a E2E application for a Nx Plugin.",
"file": "generated/packages/nx-plugin/generators/e2e-project.json",
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,15 @@
"path": "nx-plugin/generators/plugin",
"type": "generator"
},
{
"description": "Create a framework package that uses Nx CLI",
"file": "generated/packages/nx-plugin/generators/create-package.json",
"hidden": false,
"name": "create-package",
"originalFilePath": "/packages/nx-plugin/src/generators/create-package/schema.json",
"path": "nx-plugin/generators/create-package",
"type": "generator"
},
{
"description": "Create a E2E application for a Nx Plugin.",
"file": "generated/packages/nx-plugin/generators/e2e-project.json",
Expand Down
84 changes: 84 additions & 0 deletions docs/generated/packages/nx-plugin/generators/create-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "create-package",
"factory": "./src/generators/create-package/create-package",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "NxPluginCreatePackage",
"title": "Create a framework package",
"description": "Create a framework package that uses Nx CLI.",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The package name, like `create-framework-app`. Note this must be a valid NPM name to be published.",
"$default": { "$source": "argv", "index": 0 },
"x-priority": "important"
},
"project": {
"type": "string",
"description": "The name of the generator project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for the generator?",
"x-priority": "important"
},
"unitTestRunner": {
"type": "string",
"enum": ["jest", "none"],
"description": "Test runner to use for unit tests.",
"default": "jest"
},
"directory": {
"type": "string",
"description": "A directory where the app is placed."
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"default": "eslint"
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"alias": "t"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"skipTsConfig": {
"type": "boolean",
"default": false,
"description": "Do not update tsconfig.json for development experience.",
"x-priority": "internal"
},
"setParserOptionsProject": {
"type": "boolean",
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"compiler": {
"type": "string",
"enum": ["tsc", "swc"],
"default": "tsc",
"description": "The compiler used by the build and test targets."
},
"importPath": {
"type": "string",
"description": "How the plugin will be published, like `create-framework-app`. Note this must be a valid NPM name. Will use name if not provided."
}
},
"required": ["name", "project"],
"presets": []
},
"description": "Create a framework package that uses Nx CLI",
"implementation": "/packages/nx-plugin/src/generators/create-package/create-package.ts",
"aliases": [],
"hidden": false,
"path": "/packages/nx-plugin/src/generators/create-package/schema.json",
"type": "generator"
}
1 change: 1 addition & 0 deletions docs/generated/packages/workspace/generators/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"default": false
}
},
"required": ["preset", "name"],
"presets": []
},
"description": "Create application in an empty workspace.",
Expand Down
16 changes: 0 additions & 16 deletions e2e/detox/src/detox.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
checkFilesExist,
isOSX,
newProject,
runCLI,
runCLIAsync,
uniq,
killPorts,
cleanupProject,
} from '@nrwl/e2e/utils';

Expand Down Expand Up @@ -46,18 +44,4 @@ describe('Detox', () => {
const lintResults = await runCLIAsync(`lint ${expoAppName}-e2e`);
expect(lintResults.combinedOutput).toContain('All files pass linting');
});

describe('React Native Detox MACOS-Tests', () => {
if (isOSX()) {
it('should test ios MACOS-Tests', async () => {
expect(
runCLI(
`test-ios ${appName}-e2e --prod --debugSynchronization=true --loglevel=trace`
)
).toContain('Successfully ran target test-ios');

await killPorts(8081); // kill the port for the serve command
}, 3000000);
}
});
});
21 changes: 18 additions & 3 deletions e2e/nx-plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ProjectConfiguration } from '@nrwl/devkit';
import {
checkFilesExist,
expectTestsPass,
isNotWindows,
killPorts,
newProject,
readJson,
Expand All @@ -12,8 +11,6 @@ import {
uniq,
updateFile,
createFile,
readFile,
removeFile,
cleanupProject,
runCommand,
getPackageManagerCommand,
Expand Down Expand Up @@ -411,4 +408,22 @@ describe('Nx Plugin', () => {
expect(pluginProject.tags).toEqual(['e2etag', 'e2ePackage']);
}, 90000);
});

it('should be able to generate a create-package plugin ', async () => {
const plugin = uniq('plugin');
const createAppName = `create-${plugin}-app`;
runCLI(`generate @nrwl/nx-plugin:plugin ${plugin}`);
runCLI(
`generate @nrwl/nx-plugin:create-package ${createAppName} --project=${plugin}`
);

const buildResults = runCLI(`build ${createAppName}`);
expect(buildResults).toContain('Done compiling TypeScript files');

checkFilesExist(
`libs/${plugin}/src/generators/preset`,
`libs/${createAppName}`,
`dist/libs/${createAppName}/bin/index.js`
);
});
});
1 change: 1 addition & 0 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ async function normalizeArgsMiddleware(
} else if (monorepoStyle === 'node-standalone') {
preset = Preset.NodeStandalone;
} else {
// when choose integrated monorepo, further prompt for preset
preset = await determinePreset(argv);
}
} else if (argv.preset === 'react') {
Expand Down
1 change: 1 addition & 0 deletions packages/create-nx-workspace/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './src/create-workspace';
export * from './src/create-workspace-options';
2 changes: 0 additions & 2 deletions packages/create-nx-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
},
"main": "./index.js",
"typings": "./index.d.ts",
"homepage": "https://nx.dev",
"dependencies": {
"chalk": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-nx-workspace/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build-base": {
"executor": "@nrwl/js:tsc",
"options": {
"main": "packages/create-nx-workspace/bin/create-nx-workspace.ts",
"main": "packages/create-nx-workspace/index.ts",
"assets": [
{
"input": "packages/create-nx-workspace",
Expand Down
4 changes: 3 additions & 1 deletion packages/create-nx-workspace/src/create-empty-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
tmpDir: string,
name: string,
packageManager: PackageManager,
options: T
options: T,
preset: string
): Promise<string> {
// Ensure to use packageManager for args
// if it's not already passed in from previous process
Expand All @@ -33,6 +34,7 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
}

const args = unparse({
preset,
...options,
}).join(' ');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PackageManager } from './utils/package-manager';
import { CI } from './utils/ci/ci-list';

export interface CreateWorkspaceOptions {
name: string; // Workspace name (e.g. org name)
Expand Down
5 changes: 3 additions & 2 deletions packages/create-nx-workspace/src/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(
tmpDir,
name,
packageManager,
options
options,
preset
);

// If the preset is a third-party preset, we need to call createPreset to install it
Expand All @@ -63,7 +64,7 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(
nxCloud && nxCloudInstallRes?.code === 0
);
}
if (!skipGit) {
if (!skipGit && commit) {
try {
await initializeGitRepo(directory, { defaultBase, commit });
} catch (e) {
Expand Down
10 changes: 10 additions & 0 deletions packages/nx-plugin/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"schema": "./src/generators/plugin/schema.json",
"description": "Create a Nx Plugin."
},
"create-package": {
"factory": "./src/generators/create-package/create-package",
"schema": "./src/generators/create-package/schema.json",
"description": "Create a framework package that uses Nx CLI"
},
"e2e-project": {
"factory": "./src/generators/e2e-project/e2e",
"schema": "./src/generators/e2e-project/schema.json",
Expand Down Expand Up @@ -41,6 +46,11 @@
"schema": "./src/generators/plugin/schema.json",
"description": "Create a Nx Plugin."
},
"create-package": {
"factory": "./src/generators/create-package/create-package#createPackageSchematic",
"schema": "./src/generators/create-package/schema.json",
"description": "Create a framework package that uses Nx CLI"
},
"e2e-project": {
"factory": "./src/generators/e2e-project/e2e#e2eProjectSchematic",
"schema": "./src/generators/e2e-project/schema.json",
Expand Down
1 change: 1 addition & 0 deletions packages/nx-plugin/generators.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './src/generators/create-package/create-package';
export * from './src/generators/e2e-project/e2e';
export * from './src/generators/executor/executor';
export * from './src/generators/generator/generator';
Expand Down
Loading

0 comments on commit 4d0bb6f

Please sign in to comment.