├── src ├── index.ts └── commands │ ├── update.ts │ └── up.ts ├── bin ├── run.cmd └── run ├── .gitignore ├── .editorconfig ├── tsconfig.json ├── test └── commands │ ├── up.test.ts │ └── update.test.ts ├── package.json └── README.md /src/index.ts: -------------------------------------------------------------------------------- 1 | export {run} from '@oclif/command' 2 | -------------------------------------------------------------------------------- /bin/run.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | node "%~dp0\run" %* 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *-debug.log 2 | *-error.log 3 | /.nyc_output 4 | /dist 5 | /lib 6 | /tmp 7 | /yarn.lock 8 | node_modules 9 | -------------------------------------------------------------------------------- /bin/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('@oclif/command').run() 4 | .then(require('@oclif/command/flush')) 5 | .catch(require('@oclif/errors/handle')) 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "outDir": "lib", 7 | "rootDir": "src", 8 | "strict": true, 9 | "target": "es2017" 10 | }, 11 | "include": [ 12 | "src/**/*" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/commands/up.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | 3 | describe('up', () => { 4 | test 5 | .stdout() 6 | .command(['up']) 7 | .it('runs hello', ctx => { 8 | expect(ctx.stdout).to.contain('hello world') 9 | }) 10 | 11 | test 12 | .stdout() 13 | .command(['up', '--name', 'jeff']) 14 | .it('runs hello --name jeff', ctx => { 15 | expect(ctx.stdout).to.contain('hello jeff') 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /test/commands/update.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | 3 | describe('update', () => { 4 | test 5 | .stdout() 6 | .command(['update']) 7 | .it('runs hello', ctx => { 8 | expect(ctx.stdout).to.contain('hello world') 9 | }) 10 | 11 | test 12 | .stdout() 13 | .command(['update', '--name', 'jeff']) 14 | .it('runs hello --name jeff', ctx => { 15 | expect(ctx.stdout).to.contain('hello jeff') 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rocketcdk", 3 | "version": "0.2.0", 4 | "author": "Edwin @EdwinRad", 5 | "bin": { 6 | "rocketcdk": "./bin/run" 7 | }, 8 | "bugs": "https://github.com/EdwinRad/rocketcdk/issues", 9 | "dependencies": { 10 | "@oclif/command": "^1.8.0", 11 | "@oclif/config": "^1.17.0", 12 | "@oclif/plugin-help": "^3.2.2", 13 | "@types/inquirer": "^6.5.0", 14 | "chalk": "^4.1.0", 15 | "cli-ux": "^5.5.1", 16 | "inquirer": "^7.1.0", 17 | "tslib": "^1.14.1" 18 | }, 19 | "devDependencies": { 20 | "@oclif/dev-cli": "^1.26.0", 21 | "@oclif/test": "^1.2.8", 22 | "@types/chai": "^4.2.15", 23 | "@types/mocha": "^5.2.7", 24 | "@types/node": "^10.17.55", 25 | "chai": "^4.3.4", 26 | "eslint": "^5.16.0", 27 | "eslint-config-oclif": "^3.1.0", 28 | "eslint-config-oclif-typescript": "^0.1.0", 29 | "globby": "^10.0.2", 30 | "mocha": "^5.2.0", 31 | "nyc": "^14.1.1", 32 | "ts-node": "^8.10.2", 33 | "typescript": "^3.9.9" 34 | }, 35 | "engines": { 36 | "node": ">=8.0.0" 37 | }, 38 | "files": [ 39 | "/bin", 40 | "/lib", 41 | "/npm-shrinkwrap.json", 42 | "/oclif.manifest.json" 43 | ], 44 | "homepage": "https://github.com/EdwinRad/rocketcdk", 45 | "keywords": [ 46 | "aws-cdk" 47 | ], 48 | "license": "MIT", 49 | "main": "lib/index.js", 50 | "oclif": { 51 | "commands": "./lib/commands", 52 | "bin": "rocketcdk", 53 | "plugins": [ 54 | "@oclif/plugin-help" 55 | ] 56 | }, 57 | "repository": "EdwinRad/rocketcdk", 58 | "scripts": { 59 | "postpack": "rm -f oclif.manifest.json", 60 | "posttest": "eslint . --ext .ts --config .eslintrc", 61 | "prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme", 62 | "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"", 63 | "version": "oclif-dev readme && git add README.md" 64 | }, 65 | "types": "lib/index.d.ts" 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # RocketCDK 3 | [![Version](https://img.shields.io/npm/v/rocketcdk.svg)](https://npmjs.org/package/rocketcdk) 4 | 5 | [![Downloads/week](https://img.shields.io/npm/dw/rocketcdk.svg)](https://npmjs.org/package/rocketcdk) 6 | 7 | [![License](https://img.shields.io/npm/l/rocketcdk.svg)](https://github.com/EdwinRad/rocketcdk/blob/master/package.json) 8 | 9 | ## Update all your packages and CDK version in one step. 10 | ### Works for Typescript and Python 11 | Update to latest: 12 | ```sh-session 13 | $ npx rocketcdk up 14 | ``` 15 | Update to specific version: 16 | ```sh-session 17 | $ npx rocketcdk up -v 1.55.0 18 | ``` 19 | 20 | ## What it does: 21 | 22 | ### Typescript 23 | Reads **'package.json'**, filters for the **AWS-CDK** packages and installs them with the specified version. 24 | 25 | Also updates these packages locally to minimize the chance of a dependency error: 26 | - @types/jest 27 | - aws-cdk@'version' 28 | - @aws-cdk/assert 29 | 30 | Installs no packages globally. 31 | 32 | ### Python 33 | Python follows the example from the AWS-CDK documentation on how to work with Python modules. 34 | [AWS-CDK docs](https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-python.html#python-managemodules) 35 | 36 | Steps: 37 | - **$ pip freeze > requirements.txt** 38 | - Reads requirements.txt and filters for **AWS-CDK** packages 39 | - Change the version number on these packages 40 | - And updates with **$ pip install -r requirements.txt -U** 41 | 42 | 43 | ## Contributing 44 | If you have any wishes, tipps or best practices, just reach out. 45 | 46 | You can reach me on Twitter or Github: 47 | [Twitter](https://twitter.com/edwin4_) 48 | [Github](https://github.com/EdwinRad/RocketCDK) 49 | 50 | 51 | # Commands 52 | 53 | 54 | * [`rocketcdk help [COMMAND]`](#rocketcdk-help-command) 55 | * [`rocketcdk up`](#rocketcdk-up) 56 | * [`rocketcdk update`](#rocketcdk-update) 57 | 58 | ## `rocketcdk help [COMMAND]` 59 | 60 | display help for rocketcdk 61 | 62 | ``` 63 | USAGE 64 | $ rocketcdk help [COMMAND] 65 | 66 | ARGUMENTS 67 | COMMAND command to show help for 68 | 69 | OPTIONS 70 | --all see all commands in CLI 71 | ``` 72 | 73 | _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.1.0/src/commands/help.ts)_ 74 | 75 | ## `rocketcdk up` 76 | 77 | Updates your CDK packages to your favorite version. 78 | 79 | ``` 80 | USAGE 81 | $ rocketcdk up 82 | 83 | OPTIONS 84 | -c, --caret Set uses the Semver version of the npm packages. 85 | -v, --version=version [default: latest] input a version: RocketCDK up -v 1.50.0 86 | ``` 87 | 88 | _See code: [src/commands/up.ts](https://github.com/EdwinRad/rocketcdk/blob/v0.2.0/src/commands/up.ts)_ 89 | 90 | ## `rocketcdk update` 91 | 92 | Updates your CDK packages to your favourite version. 93 | 94 | ``` 95 | USAGE 96 | $ rocketcdk update 97 | 98 | OPTIONS 99 | -v, --version=version [default: latest] input a version: RocketCDK up -v 1.50.0 100 | ``` 101 | 102 | _See code: [src/commands/update.ts](https://github.com/EdwinRad/rocketcdk/blob/v0.2.0/src/commands/update.ts)_ 103 | 104 | -------------------------------------------------------------------------------- /src/commands/update.ts: -------------------------------------------------------------------------------- 1 | import { Command, flags } from '@oclif/command' 2 | import * as fs from 'fs' 3 | import { exec } from 'child_process' 4 | import cli from 'cli-ux' 5 | import * as chalk from 'chalk' 6 | 7 | export default class Update extends Command { 8 | static description = 'Updates your CDK packages to your favourite version.' 9 | 10 | static flags = { 11 | version: flags.string({ char: 'v', description: 'input a version: RocketCDK up -v 1.50.0', default: 'latest' }), 12 | } 13 | 14 | async run() { 15 | function update() { 16 | // Check if TS or Python 17 | if (fs.existsSync('package.json')) { 18 | //TS 19 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 20 | var packages1: any = [] 21 | fs.readFile('package.json', (err, data: any) => { 22 | if (err) throw err; 23 | let packages = JSON.parse(data); 24 | let pack = packages.dependencies 25 | for (var key in pack) { 26 | packages1.push(key); 27 | } 28 | filtercdkpackages(packages1) 29 | }); 30 | function filtercdkpackages(packages1: any) { 31 | const filterBy = (str: string) => packages1.filter( 32 | (item: string) => new RegExp('^' + str.replace(/\*/g, '.*') + '$').test(item) 33 | ); 34 | var installpackages1: any = [] 35 | var filtered = filterBy('@aws-cdk*') 36 | function installpackages() { 37 | for (var i of filtered) { 38 | installpackages1.push(i + '@' + flags.version); 39 | } 40 | } 41 | installpackages() 42 | var installpackages2 = installpackages1.join(" ") 43 | exec('npm install @types/jest aws-cdk@' + flags.version + ' @aws-cdk/assert@' + flags.version, function (error, stdout, stderr) { 44 | if (error) { 45 | throw new Error(error.message); 46 | } 47 | console.log(stdout); 48 | exec('npm install ' + installpackages2, function (error, stdout, stderr) { 49 | if (error) { 50 | throw new Error(error.message); 51 | } 52 | console.log(stdout); 53 | console.log(stderr); 54 | cli.action.stop(chalk.cyan(`LIFTOFF. We have a liftoff. Liftoff on CDK @${flags.version}.`)) 55 | }) 56 | }); 57 | 58 | }; 59 | } 60 | //Python 61 | else if (fs.existsSync('setup.py')) { 62 | //If latest: 63 | if (flags.version == 'latest') { 64 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 65 | exec('pip freeze > requirements.txt', function (error, stdout, stderr) { 66 | if (error) { 67 | throw new Error(error.message); 68 | } 69 | fs.readFile('requirements.txt', 'utf8', function read(err, data) { 70 | if (err) throw err; 71 | let regexp = /(aws-cdk.+)/g; 72 | let result: any = data.match(regexp) 73 | for (var i of result) { 74 | let datareplaced = i.split("=")[0]; 75 | data = data.replace(i, datareplaced) 76 | } 77 | fs.writeFile('requirements.txt', data, function (err) { 78 | if (err) throw err; 79 | exec('pip install -r requirements.txt -U', function (error, stdout, stderr) { 80 | if (error) { 81 | throw new Error(error.message); 82 | } 83 | console.log(stdout); 84 | cli.action.stop(chalk.cyan(`LIFTOFF. We have a liftoff. Liftoff on CDK @latest.`)) 85 | }); 86 | }); 87 | }); 88 | }) 89 | } 90 | else { 91 | //If version specified 92 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 93 | exec('pip freeze > requirements.txt', function (error, stdout, stderr) { 94 | if (error) { 95 | throw new Error(error.message); 96 | } 97 | fs.readFile('requirements.txt', 'utf8', function read(err, data) { 98 | if (err) throw err; 99 | let regexp = /(aws-cdk.+)/g; 100 | let result: any = data.match(regexp) 101 | for (var i of result) { 102 | let datareplaced = i.split("1")[0] + flags.version; 103 | data = data.replace(i, datareplaced) 104 | } 105 | fs.writeFile('requirements.txt', data, function (err) { 106 | if (err) throw err; 107 | exec('pip install -r requirements.txt -U', function (error, stdout, stderr) { 108 | if (error) { 109 | throw new Error(error.message); 110 | } 111 | console.log(stdout); 112 | cli.action.stop(chalk.cyan(`LIFTOFF. We have a liftoff. Liftoff on CDK @${flags.version}.`)) 113 | }); 114 | }); 115 | }); 116 | }) 117 | } 118 | } 119 | } 120 | 121 | const { flags } = this.parse(Update) 122 | //Input Validation 123 | var validation: any = flags.version 124 | var regex = /^\d\.\d\d\.\d$/g; 125 | if (regex.test(validation)) { 126 | update() 127 | } 128 | else if (flags.version == 'latest') { 129 | update() 130 | } 131 | //If validation fails throw error 132 | else { 133 | throw new Error('The version you provided is not in the correct format. Please specify a version: 1.50.0') 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/commands/up.ts: -------------------------------------------------------------------------------- 1 | import { Command, flags } from '@oclif/command' 2 | import * as fs from 'fs' 3 | import { exec } from 'child_process' 4 | import cli from 'cli-ux' 5 | import * as chalk from 'chalk' 6 | 7 | export default class Up extends Command { 8 | static description = 'Updates your CDK packages to your favorite version.' 9 | 10 | static flags = { 11 | version: flags.string({ char: 'v', description: 'input a version: RocketCDK up -v 1.50.0', default: 'latest' }), 12 | caret: flags.boolean({ char: 'c', description: 'Set uses the Semver version of the npm packages.' }), 13 | } 14 | 15 | async run() { 16 | function update() { 17 | // Check if TS or Python 18 | if (fs.existsSync('package.json')) { 19 | //TS 20 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 21 | //init empty array 22 | var packages1: any = [] 23 | //read package.json 24 | fs.readFile('package.json', (err, data: any) => { 25 | if (err) throw err; 26 | let packages = JSON.parse(data); 27 | let pack = packages.dependencies 28 | for (var key in pack) { 29 | packages1.push(key); 30 | } 31 | filtercdkpackages(packages1) 32 | }); 33 | //with regex select all aws-cdk packages 34 | function filtercdkpackages(packages1: any) { 35 | const filterBy = (str: string) => packages1.filter( 36 | (item: string) => new RegExp('^' + str.replace(/\*/g, '.*') + '$').test(item) 37 | ); 38 | var installpackages1: any = [] 39 | var filtered = filterBy('@aws-cdk*') 40 | function installpackages() { 41 | for (var i of filtered) { 42 | installpackages1.push(i + '@' + flags.version); 43 | } 44 | } 45 | installpackages() 46 | var installpackages2 = installpackages1.join(" ") 47 | var caret = '--save-exact' 48 | if (flags.caret) { var caret = ''} 49 | 50 | exec(`npm install ${caret} @types/jest aws-cdk@` + flags.version + ' @aws-cdk/assert@' + flags.version, function (error, stdout, stderr) { 51 | if (error) { 52 | throw new Error(error.message); 53 | } 54 | console.log(stdout); 55 | exec(`npm install ${caret} ` + installpackages2, function (error, stdout, stderr) { 56 | if (error) { 57 | throw new Error(error.message); 58 | } 59 | console.log(stdout); 60 | console.log(stderr); 61 | cli.action.stop(chalk.cyan(`Successfully updated to version ${flags.version}.`)) 62 | }) 63 | }); 64 | 65 | }; 66 | } 67 | //Python 68 | else if (fs.existsSync('setup.py')) { 69 | //If latest: 70 | if (flags.version == 'latest') { 71 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 72 | exec('pip freeze > requirements.txt', function (error, stdout, stderr) { 73 | if (error) { 74 | throw new Error(error.message); 75 | } 76 | fs.readFile('requirements.txt', 'utf8', function read(err, data) { 77 | if (err) throw err; 78 | let regexp = /(aws-cdk.+)/g; 79 | let result: any = data.match(regexp) 80 | for (var i of result) { 81 | let datareplaced = i.split("=")[0]; 82 | data = data.replace(i, datareplaced) 83 | } 84 | fs.writeFile('requirements.txt', data, function (err) { 85 | if (err) throw err; 86 | exec('pip install -r requirements.txt -U', function (error, stdout, stderr) { 87 | if (error) { 88 | throw new Error(error.message); 89 | } 90 | console.log(stdout); 91 | cli.action.stop(chalk.cyan(`Successfully updated to the latest version.`)) 92 | }); 93 | }); 94 | }); 95 | }) 96 | } 97 | else { 98 | //If version specified 99 | cli.action.start('3, 2, 1, zero. All engines running, updating CDK packages.') 100 | exec('pip freeze > requirements.txt', function (error, stdout, stderr) { 101 | if (error) { 102 | throw new Error(error.message); 103 | } 104 | fs.readFile('requirements.txt', 'utf8', function read(err, data) { 105 | if (err) throw err; 106 | let regexp = /(aws-cdk.+)/g; 107 | let result: any = data.match(regexp) 108 | for (var i of result) { 109 | let datareplaced = i.split("1")[0] + flags.version; 110 | data = data.replace(i, datareplaced) 111 | } 112 | fs.writeFile('requirements.txt', data, function (err) { 113 | if (err) throw err; 114 | exec('pip install -r requirements.txt -U', function (error, stdout, stderr) { 115 | if (error) { 116 | throw new Error(error.message); 117 | } 118 | console.log(stdout); 119 | cli.action.stop(chalk.cyan(`Successfully updated to version ${flags.version}.`)) 120 | }); 121 | }); 122 | }); 123 | }) 124 | } 125 | } 126 | } 127 | 128 | const { flags } = this.parse(Up) 129 | //Input Validation 130 | var validation: any = flags.version 131 | var regex = /^\d\.\d\d\.\d$/g; 132 | if (regex.test(validation)) { 133 | update() 134 | } 135 | else if (flags.version == 'latest') { 136 | update() 137 | } 138 | //If validation fails throw error 139 | else { 140 | throw new Error('The version you provided is not in the correct format. Please specify a version: 1.50.0') 141 | } 142 | } 143 | } 144 | --------------------------------------------------------------------------------