From 6d65dfb058d2fda2c20f786fefe1b97214481540 Mon Sep 17 00:00:00 2001 From: mattstypa Date: Fri, 15 Mar 2019 09:15:16 -0500 Subject: [PATCH] Removed no-comments option from init command --- __tests__/cli.utils.test.js | 53 --------------------------------- __tests__/fixtures/cli-utils.js | 29 ------------------ package.json | 3 +- src/cli/commands/init.js | 10 +------ src/cli/utils.js | 15 ---------- yarn.lock | 43 -------------------------- 6 files changed, 2 insertions(+), 151 deletions(-) delete mode 100644 __tests__/fixtures/cli-utils.js diff --git a/__tests__/cli.utils.test.js b/__tests__/cli.utils.test.js index 594b86e6e..2d9082d5c 100644 --- a/__tests__/cli.utils.test.js +++ b/__tests__/cli.utils.test.js @@ -1,10 +1,6 @@ -import path from 'path' - import * as utils from '../src/cli/utils' describe('cli utils', () => { - const fixture = utils.readFile(path.resolve(__dirname, 'fixtures/cli-utils.js')) - describe('parseCliParams', () => { it('parses CLI parameters', () => { const result = utils.parseCliParams(['a', 'b', '-c', 'd']) @@ -60,53 +56,4 @@ describe('cli utils', () => { expect(result).toEqual({ test: ['c', 'd', 'h'] }) }) }) - - describe('stripBlockComments', () => { - it('does not strip code', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).toEqual(expect.stringContaining('__code_no_comment__')) - expect(result).toEqual(expect.stringContaining('__code_comment_line__')) - expect(result).toEqual(expect.stringContaining('__code_comment_block__')) - expect(result).toEqual(expect.stringContaining('__code_comment_line_important__')) - expect(result).toEqual(expect.stringContaining('__code_comment_block_important__')) - }) - - it('strips block comments', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).not.toEqual(expect.stringContaining('__comment_block__')) - expect(result).not.toEqual(expect.stringContaining('__comment_block_multiline__')) - expect(result).not.toEqual(expect.stringContaining('__comment_block_code__')) - }) - - it('strips docblock comments', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).not.toEqual(expect.stringContaining('__comment_docblock__')) - }) - - it('does not strip line comments', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).toEqual(expect.stringContaining('__comment_line__')) - expect(result).toEqual(expect.stringContaining('__comment_line_important__')) - expect(result).toEqual(expect.stringContaining('__comment_line_code__')) - expect(result).toEqual(expect.stringContaining('__comment_line_important_code__')) - }) - - it('does not strip important block comments', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).toEqual(expect.stringContaining('__comment_block_important__')) - expect(result).toEqual(expect.stringContaining('__comment_block_multiline_important__')) - expect(result).toEqual(expect.stringContaining('__comment_block_important_code__')) - }) - - it('does not strip important docblock comments', () => { - const result = utils.stripBlockComments(fixture) - - expect(result).toEqual(expect.stringContaining('__comment_docblock_important__')) - }) - }) }) diff --git a/__tests__/fixtures/cli-utils.js b/__tests__/fixtures/cli-utils.js deleted file mode 100644 index 2b6500897..000000000 --- a/__tests__/fixtures/cli-utils.js +++ /dev/null @@ -1,29 +0,0 @@ -// __comment_line__ - -//! __comment_line_important__ - -/* __comment_block__ */ - -/*! __comment_block_important__ */ - -/* - __comment_block_multiline__ -*/ - -/*! - __comment_block_multiline_important__ -*/ - -/** - __comment_docblock__ -*/ - -/**! - __comment_docblock_important__ -*/ - -const __code_no_comment__ = 'test' -const __code_comment_line__ = 'test' // __comment_line_code__ -const __code_comment_block__ = 'test' /* __comment_block_code__ */ -const __code_comment_line_important__ = 'test' //! __comment_line_important_code__ -const __code_comment_block_important__ = 'test' /*! __comment_block_important_code__ */ diff --git a/package.json b/package.json index ed4f6896b..1555aa87b 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,7 @@ "postcss-js": "^2.0.0", "postcss-nested": "^4.1.1", "postcss-selector-parser": "^6.0.0", - "pretty-hrtime": "^1.0.3", - "strip-comments": "^1.0.2" + "pretty-hrtime": "^1.0.3" }, "browserslist": [ "> 1%" diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index 6b8daf4a3..0b3b34584 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -13,15 +13,10 @@ export const options = [ usage: '--full', description: 'Generate complete configuration file.', }, - { - usage: '--no-comments', - description: 'Omit comments from the config file.', - }, ] export const optionMap = { full: ['full'], - noComments: ['no-comments'], } /** @@ -36,15 +31,12 @@ export function run(cliParams, cliOptions) { utils.header() const full = cliOptions.full - const noComments = cliOptions.noComments const file = cliParams[0] || constants.defaultConfigFile utils.exists(file) && utils.die(chalk.bold.magenta(file), 'already exists.') const stubFile = full ? constants.defaultConfigStubFile : constants.simpleConfigStubFile - let stub = utils.readFile(stubFile) - - noComments && (stub = utils.stripBlockComments(stub)) + const stub = utils.readFile(stubFile) utils.writeFile(file, stub) diff --git a/src/cli/utils.js b/src/cli/utils.js index ff9eec491..ac138b854 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -1,7 +1,6 @@ import chalk from 'chalk' import { ensureFileSync, existsSync, outputFileSync, readFileSync } from 'fs-extra' import { findKey, mapValues, trimStart } from 'lodash' -import stripComments from 'strip-comments' import * as emoji from './emoji' import packageJson from '../../package.json' @@ -122,17 +121,3 @@ export function writeFile(path, content) { return outputFileSync(path, content) } - -/** - * Strips block comments from input string. Consolidates multiple line breaks. - * - * @param {string} input - * @return {string} - */ -export function stripBlockComments(input) { - return stripComments - .block(input, { keepProtected: true }) - .replace(/\n\s*\n\s*\n/g, '\n\n') // Strip unnecessary line breaks - .trim() - .concat('\n') -} diff --git a/yarn.lock b/yarn.lock index aea495654..a3bd92c4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -945,12 +945,6 @@ aws4@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" -babel-extract-comments@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz#0a2aedf81417ed391b85e18b4614e693a0351a21" - dependencies: - babylon "^6.18.0" - babel-jest@^24.3.1, babel-jest@^24.5.0: version "24.5.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-24.5.0.tgz#0ea042789810c2bec9065f7c8ab4dc18e1d28559" @@ -977,17 +971,6 @@ babel-plugin-jest-hoist@^24.3.0: dependencies: "@types/babel__traverse" "^7.0.6" -babel-plugin-syntax-object-rest-spread@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" - -babel-plugin-transform-object-rest-spread@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06" - dependencies: - babel-plugin-syntax-object-rest-spread "^6.8.0" - babel-runtime "^6.26.0" - babel-preset-jest@^24.3.0: version "24.3.0" resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-24.3.0.tgz#db88497e18869f15b24d9c0e547d8e0ab950796d" @@ -995,17 +978,6 @@ babel-preset-jest@^24.3.0: "@babel/plugin-syntax-object-rest-spread" "^7.0.0" babel-plugin-jest-hoist "^24.3.0" -babel-runtime@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.11.0" - -babylon@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" - balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -1288,10 +1260,6 @@ copy-descriptor@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" -core-js@^2.4.0: - version "2.5.6" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.6.tgz#0fe6d45bf3cac3ac364a9d72de7576f4eb221b9d" - core-js@^2.5.7: version "2.6.5" resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895" @@ -3645,10 +3613,6 @@ regenerate@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" -regenerator-runtime@^0.11.0: - version "0.11.1" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" - regenerator-runtime@^0.12.0: version "0.12.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de" @@ -4099,13 +4063,6 @@ strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" -strip-comments@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/strip-comments/-/strip-comments-1.0.2.tgz#82b9c45e7f05873bee53f37168af930aa368679d" - dependencies: - babel-extract-comments "^1.0.0" - babel-plugin-transform-object-rest-spread "^6.26.0" - strip-eof@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"