diff --git a/.circleci/config.yml b/.circleci/config.yml index 8eb26be..b61b03f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,65 +1,40 @@ ---- version: 2 jobs: - node-latest: &test + build_and_test: + working_directory: ~/mern-starter + # The primary container is an instance of the first image listed. The job's commands run in this container. docker: - - image: node:latest - working_directory: ~/cli + - image: circleci/node:latest + # The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost. steps: - checkout - - restore_cache: &restore_cache - keys: - - v1-npm-{{checksum ".circleci/config.yml"}}-{{ checksum "package-lock.json"}} - - v1-npm-{{checksum ".circleci/config.yml"}} - run: - name: Install dependencies - command: .circleci/greenkeeper - - run: ./bin/run --version - - run: ./bin/run --help + name: Update npm + command: 'sudo npm install -g npm@latest' + - restore_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} - run: - name: Testing - command: npm test - - run: - name: Submitting code coverage to codecov - command: | - ./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov - curl -s https://codecov.io/bash | bash - node-8: - <<: *test - docker: - - image: node:8 - release: - <<: *test - steps: - - add_ssh_keys - - checkout - - restore_cache: *restore_cache - - run: - name: Install dependencies - command: | - npm install -g @oclif/semantic-release@3 semantic-release@15 - npm install - - run: - name: Cutting release - command: | - semantic-release -e @oclif/semantic-release + name: Install npm dependencies + command: npm install - save_cache: - key: v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "package-lock.json"}} + key: dependency-cache-{{ checksum "package-lock.json" }} paths: - - ~/cli/node_modules - - ~/.npm - - /usr/local/lib/node_modules + - node_modules + - run: + name: Test + command: npm test + - run: + name: Generate code coverage + command: './node_modules/.bin/nyc report --reporter=text-lcov' + - store_artifacts: + path: test-results.xml + prefix: tests + - store_artifacts: + path: coverage + prefix: coverage workflows: version: 2 - "cdt": + build_and_test: jobs: - - node-latest - - node-8 - - release: - context: org-global - filters: - branches: {only: master} - requires: - - node-latest - - node-8 + - build_and_test diff --git a/.circleci/config_2jobs.yml b/.circleci/config_2jobs.yml new file mode 100644 index 0000000..dd2878a --- /dev/null +++ b/.circleci/config_2jobs.yml @@ -0,0 +1,61 @@ +version: 2 +jobs: + build: + working_directory: ~/mern-starter + # The primary container is an instance of the first image listed. The job's commands run in this container. + docker: + - image: circleci/node:latest + # The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost. + steps: + - checkout + - run: + name: Update npm + command: 'sudo npm install -g npm@latest' + - restore_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + - run: + name: Install npm dependencies + command: npm install + - save_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + paths: + - node_modules + test: + docker: + - image: circleci/node:latest + steps: + - checkout + # needed to add here also as both install and test are different docker instances and need to do same thing again in different instance + - run: + name: Update npm + command: 'sudo npm install -g npm@latest' + - restore_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + - run: + name: Install npm dependencies + command: npm install + - save_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + paths: + - node_modules + - run: + name: Test + command: npm test + - run: + name: Generate code coverage + command: './node_modules/.bin/nyc report --reporter=text-lcov' + - store_artifacts: + path: test-results.xml + prefix: tests + - store_artifacts: + path: coverage + prefix: coverage + +workflows: + version: 2 + build_and_test: + jobs: + - build + - test: + requires: + - build diff --git a/.circleci/config_tmp.yml b/.circleci/config_tmp.yml new file mode 100644 index 0000000..266a5e6 --- /dev/null +++ b/.circleci/config_tmp.yml @@ -0,0 +1,64 @@ +version: 2 +jobs: + node-latest: &test + docker: + - image: node:latest + working_directory: ~/cli + steps: + - checkout + - restore_cache: &restore_cache + keys: + - v1-npm-{{checksum ".circleci/config_tmp.yml"}}-{{ checksum "package-lock.json"}} + - v1-npm-{{checksum ".circleci/config_tmp.yml"}} + - run: + name: Install dependencies + command: .circleci/greenkeeper + - run: ./bin/run --version + - run: ./bin/run --help + - run: + name: Testing + command: npm test + - run: + name: Submitting code coverage to codecov + command: | + ./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov + curl -s https://codecov.io/bash | bash + node-8: + <<: *test + docker: + - image: node:8 + release: + <<: *test + steps: + - add_ssh_keys + - checkout + - restore_cache: *restore_cache + - run: + name: Install dependencies + command: | + npm install -g @oclif/semantic-release@3 semantic-release@15 + npm install + - run: + name: Cutting release + command: | + semantic-release -e @oclif/semantic-release + - save_cache: + key: v1-npm-{{checksum ".circleci/config_tmp.yml"}}-{{checksum "package-lock.json"}} + paths: + - ~/cli/node_modules + - ~/.npm + - /usr/local/lib/node_modules + +workflows: + version: 2 + "cdt": + jobs: + - node-latest + - node-8 + - release: + context: org-global + filters: + branches: {only: master} + requires: + - node-latest + - node-8 diff --git a/package.json b/package.json index 199de0e..2b2fbdc 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "@oclif/config": "^1.13.3", "@oclif/plugin-help": "^2.2.1", "jshashes": "^1.0.7", - "tslib": "^1.10.0" + "tslib": "^1.10.0", + "nyc": "^13.3.0" }, "devDependencies": { "@oclif/dev-cli": "^1.22.2", @@ -24,7 +25,6 @@ "chai": "^4.2.0", "globby": "^10.0.1", "mocha": "^5.2.0", - "nyc": "^13.3.0", "ts-node": "^8.4.1", "tslint": "^5.20.0", "typescript": "^3.6.4" @@ -56,7 +56,7 @@ "postpack": "rm -f oclif.manifest.json", "posttest": "tslint -p test -t stylish", "prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme", - "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"", + "test": "./node_modules/.bin/nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif-dev readme && git add README.md" }, "types": "lib/index.d.ts" diff --git a/src/commands/hash.ts b/src/commands/hash.ts index 11e58b4..b411b5d 100644 --- a/src/commands/hash.ts +++ b/src/commands/hash.ts @@ -33,7 +33,6 @@ export default class Hash extends Command { } else str = args.string - this.log(str) this.calculateHash(type, str) } @@ -61,7 +60,7 @@ export default class Hash extends Command { if (hash) { let hashed: string = hash.hex(str) - this.log(`[HASH]: ${hashed}`) + this.log(`[${type.toUpperCase()}]: ${hashed}`) } else { this.log('[ERROR]: invalid hash type') } diff --git a/src/commands/hello.ts b/src/commands/hello.ts deleted file mode 100644 index 562bb81..0000000 --- a/src/commands/hello.ts +++ /dev/null @@ -1,31 +0,0 @@ -import {Command, flags} from '@oclif/command' - -export default class Hello extends Command { - static description = 'describe the command here' - - static examples = [ - `$ cdt hello -hello world from ./src/hello.ts! -`, - ] - - static flags = { - help: flags.help({char: 'h'}), - // flag with a value (-n, --name=VALUE) - name: flags.string({char: 'n', description: 'name to print'}), - // flag with no value (-f, --force) - force: flags.boolean({char: 'f'}), - } - - static args = [{name: 'file'}] - - async run() { - const {args, flags} = this.parse(Hello) - - const name = flags.name || 'world' - this.log(`hello ${name} from ./src/commands/hello.ts`) - if (args.file && flags.force) { - this.log(`you input --force and --file: ${args.file}`) - } - } -} diff --git a/test/commands/hello.test.ts b/test/commands/hello.test.ts deleted file mode 100644 index 651a421..0000000 --- a/test/commands/hello.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {expect, test} from '@oclif/test' - -describe('hello', () => { - test - .stdout() - .command(['hello']) - .it('runs hello', ctx => { - expect(ctx.stdout).to.contain('hello world') - }) - - test - .stdout() - .command(['hello', '--name', 'jeff']) - .it('runs hello --name jeff', ctx => { - expect(ctx.stdout).to.contain('hello jeff') - }) -})