-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common-cli): add
common-cli
to share code among our create-*
…
… CLI packages
- Loading branch information
Showing
27 changed files
with
482 additions
and
581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# common-cli | ||
|
||
Common library to share code among the `create-*` packages. | ||
|
||
## Building | ||
|
||
Run `nx build common-cli` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test common-cli` to execute the unit tests via [Jest](https://jestjs.io). | ||
|
||
## License | ||
|
||
Copyright (c) 2023-present Tine Kondo. Licensed under the MIT License (MIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'common-cli', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/packages/common-cli', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@nxrocks/common-cli", | ||
"description": "Common library to share code among the `create-*` packages.", | ||
"version": "0.0.0-development", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "src/index.js", | ||
"license": "MIT", | ||
"author": "Tine Kondo ", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tinesoft/nxrocks.git", | ||
"directory": "packages/common-cli" | ||
}, | ||
"homepage": "https://github.com/tinesoft/nxrocks/blob/master/packages/common-cli#readme", | ||
"bugs": { | ||
"url": "https://github.com/tinesoft/nxrocks/issues" | ||
}, | ||
"keywords": [ | ||
"create-nx-flutter", | ||
"create-nx-spring-boot", | ||
"create-nx-quarkus", | ||
"create-nx-micronaut", | ||
"create-nx-ktor" | ||
], | ||
"dependencies": { | ||
"create-nx-workspace": "16.9.0", | ||
"@clack/prompts": "^0.7.0", | ||
"yargs": "^17.7.2", | ||
"tslib": "^2.6.1", | ||
"@nx/devkit": "16.9.0", | ||
"fs-extra": "^10.1.0", | ||
"terminal-link": "^2.1.1" | ||
}, | ||
"typings": "./src/index.d.ts", | ||
"peerDependencies": { | ||
}, | ||
"devDependencies": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "common-cli", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/common-cli/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/common-cli", | ||
"main": "packages/common-cli/src/index.ts", | ||
"tsConfig": "packages/common-cli/tsconfig.lib.json", | ||
"assets": ["packages/common-cli/*.md"] | ||
} | ||
}, | ||
"publish": { | ||
"command": "node tools/scripts/publish.mjs common-cli {args.ver} {args.tag}", | ||
"dependsOn": ["build"] | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/common-cli/**/*.ts", | ||
"packages/common-cli/package.json" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/common-cli/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './lib/utils'; | ||
export * from './lib/models'; | ||
export * from './lib/main'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { intro, text, confirm, spinner, note, outro } from '@clack/prompts'; | ||
import { createWorkspace } from 'create-nx-workspace'; | ||
import * as yargs from 'yargs'; | ||
import * as terminalLink from 'terminal-link'; | ||
|
||
import { CLIArguments } from './models'; | ||
import { createWorkspaceWithNxWrapper, getNxCommand } from './utils'; | ||
|
||
export async function mainCLI(pkgName: string, stackName: string) { | ||
|
||
const pkgFolderName = pkgName.replace('@nxrocks/', '') | ||
const createPkgName = `create-${pkgFolderName}`; | ||
|
||
intro(createPkgName); | ||
|
||
const options = (yargs | ||
.parserConfiguration({ | ||
'strip-dashed': true, | ||
}) | ||
.command( | ||
'$0 [name]', | ||
`Create a new Nx workspace with ${stackName} support`, | ||
(yargs) => yargs.option('name', | ||
{ | ||
describe: 'Workspace name (e.g. org name)', | ||
type: 'string', | ||
}). | ||
option('useNxWrapper', | ||
{ | ||
describe: 'Let Nx manages its own installation and updates', | ||
type: 'boolean', | ||
}). | ||
option('useNxCloud', | ||
{ | ||
describe: "Enable distributed caching to make your CI faster", | ||
type: 'boolean', | ||
}). | ||
option('verbose', | ||
{ | ||
describe: "Enable more logging information", | ||
type: 'boolean', | ||
default: process.env['NX_VERBOSE_LOGGING'] === 'true', | ||
}) | ||
) | ||
.help('help', 'Show help') as yargs.Argv<CLIArguments>).parseSync(); | ||
|
||
let { name, useNxWrapper, useNxCloud } = options; | ||
const { _, $0, name: ignoredName, verbose, ...restArgs } = options; | ||
|
||
name ||= await text({ | ||
message: 'What is the name of your workspace (e.g. org name)?', | ||
initialValue: 'myorg', | ||
validate: (value) => (value?.length === 0) ? 'You need to provide one' : void 0, | ||
}) as string; | ||
|
||
useNxWrapper ??= await confirm({ | ||
message: `Would you like to use Nx Wrapper? [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ]`, | ||
initialValue: true | ||
}) as boolean; | ||
|
||
useNxCloud ??= await confirm({ | ||
message: `Would you like to use Nx Cloud? [ ${linkify('Nx Cloud', 'https://nx.app/?utm_source=' + createPkgName)} ]`, | ||
initialValue: false | ||
}) as boolean; | ||
|
||
const presetVersion = 'latest'; | ||
|
||
let directory: string; | ||
|
||
const notes = [ | ||
`- Go to [ ${linkify(pkgName, 'https://github.com/tinesoft/nxrocks/tree/develop/packages/' + pkgFolderName)} ] to get started with Nx and ${stackName} plugin.`, | ||
`- Run [ ${getNxCommand(useNxWrapper)} g ${pkgName}:project ] to add more projects.` | ||
]; | ||
|
||
if (useNxWrapper) { | ||
notes.push(`- Go to [ ${linkify('Nx Wrapper', 'https://nx.dev/concepts/more-concepts/nx-and-the-wrapper#and-the-nx-wrapper')} ] to get started with Nx Wrapper.`); | ||
|
||
const allArgs = Object.entries(restArgs).map(([key, value]) => `--${key}=${value}`).join(' '); | ||
|
||
const s = spinner(); | ||
s.start('Initializing your workspace'); | ||
|
||
directory = createWorkspaceWithNxWrapper(name, pkgName, allArgs, useNxCloud, presetVersion, !verbose); | ||
|
||
s.stop(`Successfully created the workspace: ${name}`); | ||
} | ||
else { | ||
directory = (await createWorkspace( | ||
`${pkgName}@${presetVersion}`, | ||
{ | ||
...restArgs, | ||
name: name, | ||
nxCloud: useNxCloud, | ||
packageManager: 'npm' | ||
} | ||
))?.directory; | ||
} | ||
|
||
notes.push(`- Go to [ ${linkify('Nx.dev', 'https://nx.dev')} ] to get started with Nx.`); | ||
|
||
note(notes.join('\n'), "Next steps"); | ||
|
||
outro(`Your workspace in ${directory} is all set 🎉. Let's goooooo! 🚀`); | ||
} | ||
|
||
function linkify(text: string, url: string, fallback = (text: string, url: string) => url) { | ||
return terminalLink(text, url, { fallback }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CreateWorkspaceOptions } from 'create-nx-workspace'; | ||
|
||
|
||
export interface CLIArguments extends CreateWorkspaceOptions { | ||
name: string; | ||
useNxWrapper?: boolean; | ||
useNxCloud?: boolean; | ||
interactive: boolean; | ||
verbose: boolean; | ||
$0?: string; | ||
_?: string[] | ||
} | ||
|
Oops, something went wrong.