Skip to content

Commit

Permalink
chore(repo): move add-nx into main nx repo
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Mar 17, 2022
1 parent 6c064e6 commit 70c6353
Show file tree
Hide file tree
Showing 47 changed files with 1,633 additions and 23 deletions.
28 changes: 25 additions & 3 deletions e2e/add-nx-to-monorepo/src/add-nx-to-monorepo.test.ts
@@ -1,12 +1,13 @@
import {
createNonNxProjectDirectory,
runCLI,
runCommand,
tmpProjPath,
updateFile,
} from '@nrwl/e2e/utils';
import { Workspaces } from 'nx/src/shared/workspace';

describe('add-nx-to-monorepo', () => {
describe.each(['npx', 'pnpx'])('%s add-nx-to-monorepo', (command) => {
it('should not throw', () => {
// Arrange
createNonNxProjectDirectory();
Expand All @@ -24,12 +25,33 @@ describe('add-nx-to-monorepo', () => {
);

// Act
const output = runCommand('npx add-nx-to-monorepo');
const output = runCommand(`${command} add-nx-to-monorepo --nx-cloud false`);
console.log(output)
// Assert
expect(output).toBeTruthy();
expect(output).toContain('🎉 Done!');
expect(readWorkspaceConfig().projects['package-a']).toBeTruthy();
expect(readWorkspaceConfig().projects['package-b']).toBeTruthy();
});

it('should build', () => {
// Arrange
createNonNxProjectDirectory();
updateFile(
'packages/package-a/package.json',
JSON.stringify({
name: 'package-a',
scripts: {
build: 'echo "build successful"',
},
})
);

// Act
runCommand(`${command} add-nx-to-monorepo --nx-cloud false`);
const output = runCLI('build package-a');
// Assert
expect(output).toContain('build successful');
});
});

const readWorkspaceConfig = () =>
Expand Down
6 changes: 4 additions & 2 deletions e2e/utils/index.ts
Expand Up @@ -5,7 +5,7 @@ import {
WorkspaceJsonConfiguration,
} from '@nrwl/devkit';
import { angularCliVersion } from '@nrwl/workspace/src/utils/versions';
import { ChildProcess, exec, execSync } from 'child_process';
import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process';
import {
copySync,
createFileSync,
Expand Down Expand Up @@ -503,7 +503,7 @@ export function expectTestsPass(v: { stdout: string; stderr: string }) {
expect(v.stderr).not.toContain('fail');
}

export function runCommand(command: string): string {
export function runCommand(command: string, options?: Partial<ExecSyncOptions>): string {
try {
const r = execSync(command, {
cwd: tmpProjPath(),
Expand All @@ -514,12 +514,14 @@ export function runCommand(command: string): string {
NX_INVOKED_BY_RUNNER: undefined,
},
encoding: 'utf-8',
...options
}).toString();
if (process.env.NX_VERBOSE_LOGGING) {
console.log(r);
}
return r;
} catch (e) {
console.log('ERROR CAUGHT', e)
// this is intentional
// npm ls fails if package is not found
return e.stdout?.toString() + e.stderr?.toString();
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -275,6 +275,7 @@
"@tailwindcss/typography": "^0.5.0",
"classnames": "^2.3.1",
"core-js": "^3.6.5",
"enquirer": "~2.3.6",
"fast-glob": "^3.2.7",
"framer-motion": "^4.1.17",
"glob": "7.1.4",
Expand Down
5 changes: 5 additions & 0 deletions packages/add-nx-to-monorepo/.eslintrc.json
@@ -0,0 +1,5 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"rules": {}
}
22 changes: 22 additions & 0 deletions packages/add-nx-to-monorepo/LICENSE
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2017-2021 Narwhal Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 20 additions & 0 deletions packages/add-nx-to-monorepo/README.md
@@ -0,0 +1,20 @@
# `> npx add-nx-to-monorepo`

<p align="center"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600"></p>

<div align="center">

[![License](https://img.shields.io/npm/l/@nrwl/workspace.svg?style=flat-square)]()
[![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nrwl/workspace)
[![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join us @nrwl/community on slack](https://img.shields.io/badge/slack-%40nrwl%2Fcommunity-brightgreen)](https://join.slack.com/t/nrwlcommunity/shared_invite/enQtNzU5MTE4OTQwOTk0LTgxY2E0ZWYzMWE0YzA5ZDA2MWM1NDVhNmI2ZWMyYmZhNWJiODk3MjkxZjY3MzU5ZjRmM2NmNWU1OTgyZmE4Mzc)

</div>

An easy way to add Nx computation caching to any monorepo (Yarn Workspaces, PNPM, Lerna, etc).

Simply run: `npx add-nx-to-monorepo` in your monorepo.

## Learn More

- See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) to learn more about Nx.
14 changes: 14 additions & 0 deletions packages/add-nx-to-monorepo/jest.config.js
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'add-nx-to-monorepo',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/projects/add-nx-to-monorepo',
};
33 changes: 33 additions & 0 deletions packages/add-nx-to-monorepo/package.json
@@ -0,0 +1,33 @@
{
"name": "add-nx-to-monorepo",
"version": "0.0.1",
"description": "Make any monorepo faster by adding Nx to it",
"repository": {
"type": "git",
"url": "git+https://github.com/nrwl/add-nx.git"
},
"keywords": [
"Monorepo",
"React",
"Web",
"Node",
"Nest",
"Lerna",
"Yarn",
"CLI"
],
"bin": {
"add-nx-to-monorepo": "./src/add-nx-to-monorepo.js"
},
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/add-nx/issues"
},
"homepage": "https://nx.dev",
"dependencies": {
"strip-json-comments": "3.1.1",
"ignore": "^5.0.4",
"@nrwl/workspace": "*"
}
}
72 changes: 72 additions & 0 deletions packages/add-nx-to-monorepo/project.json
@@ -0,0 +1,72 @@
{
"root": "packages/add-nx-to-monorepo",
"sourceRoot": "packages/add-nx-to-monorepo/src",
"projectType": "library",
"targets": {
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"packages/add-nx-to-monorepo/**/*.ts"
]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": [
"coverage/packages/add-nx-to-monorepo"
],
"options": {
"jestConfig": "packages/add-nx-to-monorepo/jest.config.js",
"passWithNoTests": true
}
},
"build-base": {
"executor": "@nrwl/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "build/packages/add-nx-to-monorepo",
"tsConfig": "packages/add-nx-to-monorepo/tsconfig.lib.json",
"packageJson": "packages/add-nx-to-monorepo/package.json",
"main": "packages/add-nx-to-monorepo/src/index.ts",
"assets": [
"packages/add-nx-to-monorepo/LICENSE",
"packages/add-nx-to-monorepo/*.md"
]
}
},
"build": {
"executor": "@nrwl/workspace:run-commands",
"outputs": ["build/packages/add-nx-to-monorepo"],
"options": {
"commands": [
{
"command": "node ./scripts/chmod build/packages/add-nx-to-monorepo/src/add-nx-to-monorepo.js"
},
{
"command": "node ./scripts/copy-readme.js add-nx-to-monorepo"
}
],
"parallel": false
}
},
"test-against-repo": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "nx build add-nx-to-monorepo",
"forwardAllArgs": false
},
{
"command": "export JS_SCRIPT=$PWD/dist/packages/add-nx-to-monorepo/src/add-nx-to-monorepo.js && cd {args.repo} && echo $PWD && node $JS_SCRIPT",
"forwardAllArgs": false
}
],
"parallel": false
}
}
}
}
15 changes: 15 additions & 0 deletions packages/add-nx-to-monorepo/publish.sh
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
echo "Publishing add-nx-to-monorepo@$1"

nx build add-nx-to-monorepo
cd dist/projects/add-nx-to-monorepo

if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|REPLACE|$1|g" package.json
else
sed -i "s|REPLACE|$1|g" package.json
fi

npm adduser
npm publish --access public --tag latest

0 comments on commit 70c6353

Please sign in to comment.