@teleporthq/teleport-postprocessor-prettier-js
Advanced tools
Comparing version
@@ -6,4 +6,4 @@ import { PostProcessor, PrettierFormatOptions } from '@teleporthq/teleport-types'; | ||
} | ||
export declare const createPostProcessor: (options?: PostProcessorFactoryOptions) => PostProcessor; | ||
export declare const createPrettierJSPostProcessor: (options?: PostProcessorFactoryOptions) => PostProcessor; | ||
declare const _default: PostProcessor; | ||
export default _default; |
@@ -19,17 +19,12 @@ "use strict"; | ||
var parser_babylon_1 = __importDefault(require("prettier/parser-babylon")); | ||
var parser_postcss_1 = __importDefault(require("prettier/parser-postcss")); | ||
var parser_typescript_1 = __importDefault(require("prettier/parser-typescript")); | ||
var teleport_shared_1 = require("@teleporthq/teleport-shared"); | ||
var teleport_types_1 = require("@teleporthq/teleport-types"); | ||
exports.createPostProcessor = function (options) { | ||
exports.createPrettierJSPostProcessor = function (options) { | ||
if (options === void 0) { options = {}; } | ||
var fileType = options.fileType || teleport_types_1.FileType.JS; | ||
var formatOptions = __assign({}, teleport_shared_1.Constants.PRETTIER_CONFIG, options.formatOptions); | ||
var jsParser = fileType === teleport_types_1.FileType.TS ? parser_typescript_1.default : parser_babylon_1.default; | ||
var plugins = [jsParser, parser_postcss_1.default]; | ||
var parser = fileType === teleport_types_1.FileType.TS ? 'typescript' : 'babel'; | ||
var plugins = [parser_babylon_1.default]; | ||
var processor = function (codeChunks) { | ||
if (codeChunks[fileType]) { | ||
codeChunks[fileType] = standalone_1.format(codeChunks[fileType], __assign({}, formatOptions, { plugins: plugins, | ||
parser: parser })); | ||
codeChunks[fileType] = standalone_1.format(codeChunks[fileType], __assign({}, formatOptions, { plugins: plugins, parser: 'babel' })); | ||
} | ||
@@ -43,3 +38,3 @@ else { | ||
}; | ||
exports.default = exports.createPostProcessor(); | ||
exports.default = exports.createPrettierJSPostProcessor(); | ||
//# sourceMappingURL=index.js.map |
@@ -6,4 +6,4 @@ import { PostProcessor, PrettierFormatOptions } from '@teleporthq/teleport-types'; | ||
} | ||
export declare const createPostProcessor: (options?: PostProcessorFactoryOptions) => PostProcessor; | ||
export declare const createPrettierJSPostProcessor: (options?: PostProcessorFactoryOptions) => PostProcessor; | ||
declare const _default: PostProcessor; | ||
export default _default; |
import { format } from 'prettier/standalone'; | ||
import parserBabylon from 'prettier/parser-babylon'; | ||
import parserPostCSS from 'prettier/parser-postcss'; | ||
import parserTypescript from 'prettier/parser-typescript'; | ||
import { Constants } from '@teleporthq/teleport-shared'; | ||
import { FileType } from '@teleporthq/teleport-types'; | ||
export const createPostProcessor = (options = {}) => { | ||
export const createPrettierJSPostProcessor = (options = {}) => { | ||
const fileType = options.fileType || FileType.JS; | ||
const formatOptions = { ...Constants.PRETTIER_CONFIG, ...options.formatOptions }; | ||
const jsParser = fileType === FileType.TS ? parserTypescript : parserBabylon; | ||
const plugins = [jsParser, parserPostCSS]; | ||
const parser = fileType === FileType.TS ? 'typescript' : 'babel'; | ||
const plugins = [parserBabylon]; | ||
const processor = (codeChunks) => { | ||
@@ -18,3 +14,3 @@ if (codeChunks[fileType]) { | ||
plugins, | ||
parser, | ||
parser: 'babel', | ||
}); | ||
@@ -29,3 +25,3 @@ } | ||
}; | ||
export default createPostProcessor(); | ||
export default createPrettierJSPostProcessor(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@teleporthq/teleport-postprocessor-prettier-js", | ||
"version": "0.10.0-alpha.1", | ||
"description": "A post-processing function that formats js code chunks using prettier and the prettier-js plugin", | ||
"version": "0.10.0-alpha.2", | ||
"description": "A post-processing function that formats js code chunks using prettier and the babylon parser", | ||
"author": "teleportHQ", | ||
@@ -11,2 +11,3 @@ "license": "MIT", | ||
"module": "dist/esm/index.js", | ||
"sideEffects": false, | ||
"repository": { | ||
@@ -29,7 +30,7 @@ "type": "git", | ||
"dependencies": { | ||
"@teleporthq/teleport-shared": "^0.10.0-alpha.1", | ||
"@teleporthq/teleport-types": "^0.10.0-alpha.1", | ||
"@teleporthq/teleport-shared": "^0.10.0-alpha.2", | ||
"@teleporthq/teleport-types": "^0.10.0-alpha.2", | ||
"prettier": "^1.18.2" | ||
}, | ||
"gitHead": "d4c96887909af2dd6b68054751aa7eca8a48a4d0" | ||
"gitHead": "b185c3fdb7dc94ff8c7eed63f7edba055fffa8d0" | ||
} |
# teleport-postprocessor-prettier-js | ||
A post-processing function that formats js code chunks using prettier and the prettier-js plugin. | ||
A post-processing function that formats js code chunks using prettier and the babylon parser. | ||
@@ -5,0 +5,0 @@ > This package is part of the [teleport ecosystem](https://github.com/teleporthq/teleport-code-generators). For a complete guide, check out the [official documentation](https://docs.teleporthq.io/). |
import { format } from 'prettier/standalone' | ||
import parserBabylon from 'prettier/parser-babylon' | ||
import parserPostCSS from 'prettier/parser-postcss' | ||
import parserTypescript from 'prettier/parser-typescript' | ||
@@ -15,9 +13,7 @@ import { Constants } from '@teleporthq/teleport-shared' | ||
export const createPostProcessor = (options: PostProcessorFactoryOptions = {}) => { | ||
export const createPrettierJSPostProcessor = (options: PostProcessorFactoryOptions = {}) => { | ||
const fileType = options.fileType || FileType.JS | ||
const formatOptions = { ...Constants.PRETTIER_CONFIG, ...options.formatOptions } | ||
const jsParser = fileType === FileType.TS ? parserTypescript : parserBabylon | ||
const plugins = [jsParser, parserPostCSS] | ||
const parser = fileType === FileType.TS ? 'typescript' : 'babel' | ||
const plugins = [parserBabylon] | ||
@@ -29,3 +25,3 @@ const processor: PostProcessor = (codeChunks) => { | ||
plugins, | ||
parser, | ||
parser: 'babel', | ||
}) | ||
@@ -42,2 +38,2 @@ } else { | ||
export default createPostProcessor() | ||
export default createPrettierJSPostProcessor() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
287278
-2.41%148
-8.07%