Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/prettier (css, html, js, json, less, md, scss, yaml) #11

Merged
merged 7 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FROM php:7.4-apache

COPY .docker/web/vhost.conf /etc/apache2/sites-available/000-default.conf

WORKDIR /srv/app

RUN mkdir -p /srv/app/storage/code
RUN chmod -R ug+rwx /srv/app/storage/code && chown -R www-data:www-data /srv/app && a2enmod rewrite

# Packages for formatting C and C++ code
RUN apt-get update -y && \
apt-get install -y clang-format
Expand All @@ -8,9 +15,7 @@ RUN apt-get update -y && \
RUN apt-get update -y && \
apt-get install -y golang

COPY .docker/web/vhost.conf /etc/apache2/sites-available/000-default.conf

WORKDIR /srv/app

RUN mkdir -p /srv/app/storage/code
RUN chmod -R ug+rwx /srv/app/storage/code && chown -R www-data:www-data /srv/app && a2enmod rewrite
# Packages for formatting code using Prettier (JS, CSS, etc)
RUN apt-get update -y && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs && npm install
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
vendor
.idea
.vscode
node_modules
87 changes: 87 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Specification: http://json.schemastore.org/prettierrc
# Documentation: https://prettier.io/docs/en/index.html

# General settings
useTabs: false
tabWidth: 4
printWidth: 120
singleQuote: false
trailingComma: none
endOfLine: lf
semi: false
proseWrap: preserve

# Language specific settings
overrides:

- files: "*.css"
options:
parser: css
bracketSpacing: true
singleQuote: false
htmlWhitespaceSensitivity: css
semi: true

- files:
- "*.htm"
- "*.html"
- "*.html5"
options:
parser: html
singleQuote: false
htmlWhitespaceSensitivity: ignore

- files:
- "*.js"
- "*.javascript"
options:
parser: babel
trailingComma: es5
semi: true

- files:
- "*.json"
options:
parser: json
semi: false
trailingComma: none
singleQuote: false
quoteProps: consistent
tabWidth: 2

- files:
- "*.less"
options:
parser: less
bracketSpacing: true
singleQuote: false
htmlWhitespaceSensitivity: css
semi: true

- files:
- "*.md"
- "*.MD"
- "*.markdown"
options:
parser: markdown
proseWrap: preserve
htmlWhitespaceSensitivity: strict
quoteProps: preserve


- files: "*.scss"
options:
parser: scss
bracketSpacing: true
singleQuote: false
htmlWhitespaceSensitivity: css
semi: true

- files:
- "*.yaml"
- "*.yml"
options:
parser: yaml
singleQuote: false
tabWidth: 2
trailingComma: none
21 changes: 13 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

FROM php:7.4-apache

# Packages for formatting C and C++ code
RUN apt-get update -y && \
apt-get install -y clang-format

# Packages for formatting Go code
RUN apt-get update -y && \
apt-get install -y golang

COPY vhost.conf /etc/apache2/sites-available/000-default.conf
COPY . /srv/app

Expand All @@ -20,4 +12,17 @@ RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN mkdir -p /srv/app/storage/code
RUN chmod -R ug+rwx /srv/app/storage/code && chown -R www-data:www-data /srv/app && a2enmod rewrite

# Packages for formatting C and C++ code
RUN apt-get update -y && \
apt-get install -y clang-format

# Packages for formatting Go code
RUN apt-get update -y && \
apt-get install -y golang

# Packages for formatting code using Prettier (JS, CSS, etc)
RUN apt-get update -y && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs && npm install

EXPOSE 8080
1 change: 1 addition & 0 deletions app/CodeFormatter/CodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract class CodeFormatter
protected static $code_formatters = [
ClangCodeFormatter::class,
GoCodeFormatter::class,
PrettierCodeFormatter::class,
];

/**
Expand Down
38 changes: 38 additions & 0 deletions app/CodeFormatter/PrettierCodeFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace DevCommunityDE\CodeFormatter\CodeFormatter;

/**
* Class ClangCodeFormatter
wookiefriseur marked this conversation as resolved.
Show resolved Hide resolved
*
* @package DevCommunityDE\CodeFormatter\CodeFormatter
*/
class PrettierCodeFormatter extends CodeFormatter
{

/**
* @var array
*/
protected static $supported_languages = [
'css',
'html',
'javascript',
'json',
'less',
'markdown',
'scss',
'yaml',
];

/**
* Config is taken automatically from <code>.prettierrc</code> file
* @param string $file
* {@internal <code>--loglevel silent</code> does not override exit codes}
* @return string
*/
protected function getShellCommand(string $file) : string
{
return __DIR__ . '/../../node_modules/.bin/prettier --loglevel silent --write \'' . $file . '\'';
}

}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "code-formatter",
"description": "Manage JS dependencies to be used with the Code Formatter",
"version": "0.1.0",
"dependencies": {
"prettier": "^2.0.5"
}
}