README.md 8.42 KB
Newer Older
Philipp Nowinski's avatar
Philipp Nowinski committed
1
[![sgalinski Internet Services](https://www.sgalinski.de/fileadmin/files/for-external-usage/logo.svg  "sgalinski")](https://www.sgalinski.de/typo3-produkte-webentwicklung/gulp-frontend-toolchain/)
Philipp Nowinski's avatar
Philipp Nowinski committed
2

Philipp Nowinski's avatar
Philipp Nowinski committed
3
# sgalinski command line interface
Philipp Nowinski's avatar
Philipp Nowinski committed
4

Philipp Nowinski's avatar
Philipp Nowinski committed
5
> **Please note:**
Philipp Nowinski's avatar
Philipp Nowinski committed
6
> The CLI is intended to be used with bash or zsh. In order for scss-lint to work, you need to have ruby installed on your machine.
Philipp Nowinski's avatar
Philipp Nowinski committed
7

Philipp Nowinski's avatar
Philipp Nowinski committed
8
## Installation
Philipp Nowinski's avatar
Philipp Nowinski committed
9

10
Move the 'sgc-core' folder inside your project root and execute the install script.
Philipp Nowinski's avatar
Philipp Nowinski committed
11 12

```bash
13 14 15 16 17 18 19 20 21
./sgc-core/install.sh
```

### Local Installation

If you don't want to install the sgc command globally (e.g. in a server environment), just pass the --local flag to the install script.

```bash
./sgc-core/install.sh --local
Philipp Nowinski's avatar
Philipp Nowinski committed
22 23
```

Philipp Nowinski's avatar
Philipp Nowinski committed
24 25 26 27 28 29 30 31 32 33 34 35
### Windows

If you want to install the SGC on a Windows machine, there are some additional preparations are required:

* All commands are to be executed in **git-bash** window, do not try to use the cmd! You'll probably already have the git-bash
installed if you are using git for Windows.
* Install NVM for Windows: https://github.com/coreybutler/nvm-windows
* You might run into an error where the SGC is not able to install the scss_lint ruby gem. This is due to an SSL error
with rubygems that occurs on Windows. In this case, you will have to install scss_lint manually. Read more about that
error here: https://gist.github.com/luislavena/f064211759ee0f806c88
* You have to open git-bash with administrator privileges to run the installation script 

Philipp Nowinski's avatar
Philipp Nowinski committed
36 37
## Configuration

38 39 40 41 42 43
To configure the frontend build process to your needs, you will have to modify the .sgc-config.json that the installer
will put into your projects root-directory.

> **Heads up**
> Prior to SGC 1.2.0, the config file was named config.json and lived inside the sgc-core/gulp folder. If this file is
> still present, sgc will use it instead of the .sgc-config.json. It is highly advised to use .sgc-config.json instead!
Philipp Nowinski's avatar
Philipp Nowinski committed
44 45 46

### directories

Philipp Nowinski's avatar
Philipp Nowinski committed
47 48 49 50
Holds the paths to the css, sass, javascript, images, sprites, sourcemaps and inline-svgs, relative to the extensions root.

* webPath: *path to your extension folder as seen from the web*
* basePath: *path to your extension folder as seen from the filesystem*
Philipp Nowinski's avatar
Philipp Nowinski committed
51

52
### abovethefold (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
53 54 55 56 57 58 59 60

Configuration for the critical path css.

* template: *path to the src template*
* dest: *path to the destination*

### js

Philipp Nowinski's avatar
Philipp Nowinski committed
61 62 63
The SGC will support you with writing next generation JavaScript and executing it in Browsers today, by transpiling it
to EcmaScript 5 compliant code. Currently EcmaScript 6 Syntax and TypeScript are supported.

64
* compiler: *es6|typescript* (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
65
* libraryPaths: *additional locations that should be searched when resolving CommonJS require statements*
Philipp Nowinski's avatar
Philipp Nowinski committed
66 67
* excludeFromQa: *glob patterns with locations that hold JavaScript that does not need to be linted (vendor stuff)

68
### images (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
69 70 71 72 73 74 75

* optimize: *locations of user uploaded images that should be optimized*

### extensions

A list of extensions that should be included in the watch task. Please note, that the very first extension in this list is expected to be your project_theme.

Philipp Nowinski's avatar
Philipp Nowinski committed
76 77 78 79 80 81 82 83
### browsersync

BrowserSync is a neat tool that will help you during the development and testing process. When you run `sgc`, it will spin
up a small webserver that proxies the URL specified in your .sgc-config.json. If you change a JavaScript or Sass file
inside an extension that is on your watch list (see the option above), BrowserSync will automatically reload the page
or inject your changes directly into the browser. You can also open several instances of the BrowserSync URL in different
browser windows and BS will take care of synchronizing all input and scroll events between them.

Philipp Nowinski's avatar
Philipp Nowinski committed
84 85
## Usage
You can run a specific task on a specific component, or start a watcher that will fire up BrowserSync and run tasks when
Philipp Nowinski's avatar
Philipp Nowinski committed
86
source files change. Extensions that will be watched are defined in your .sgc-config.json file for each project.
Philipp Nowinski's avatar
Philipp Nowinski committed
87 88 89 90

If you run a specific task, you need to specify the extension you want the task to run on with the --ext parameter.

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
91
sgc css --ext project_base
Philipp Nowinski's avatar
Philipp Nowinski committed
92 93 94 95 96 97 98
```

There are a few available tasks you need to remember:

### default/watch task

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
99
sgc
Philipp Nowinski's avatar
Philipp Nowinski committed
100 101 102 103 104 105
```
Starts a project wide watcher that will trigger the css/javascript task when you change any .scss, or .js-file and opens
the website in your browser, as a browsersync session (changed js and css will automatically get injected when recompiled).

*Hint:* If you already have a browsersync instance open in your browser, you can pass the argument -s to restart the session without opening a browser.

Philipp Nowinski's avatar
Philipp Nowinski committed
106
### sprite task (will be called by the css task automatically)
Philipp Nowinski's avatar
Philipp Nowinski committed
107 108

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
109
sgc css:sprites --ext [extension name]
Philipp Nowinski's avatar
Philipp Nowinski committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
```

Triggers sprite generation inside the given directory.

Assumptions:

* all sprite images are inside images/sprites, relative to the given path.
* all sprite images are PNGs.
* there is a sass directory, next to the images folder.

This task will generate a png inside the images folder, containing all the sprites and a .scss file inside the sass
folder, which will provide the necessary mixins. To use the sprites inside your SASS code, import the _sprite.scss file.
You can then use the following mixins:

```scss
// will output css for a sprite image 'box.png'
.element {
Philipp Nowinski's avatar
Philipp Nowinski committed
127
	@include sprite ($box);
Philipp Nowinski's avatar
Philipp Nowinski committed
128 129 130 131
}
```

The @sprite mixin already contains width and height. If you need these values for something else, use the @sprite-width
Philipp Nowinski's avatar
Philipp Nowinski committed
132
and @sprite-height functions.
Philipp Nowinski's avatar
Philipp Nowinski committed
133

Philipp Nowinski's avatar
Philipp Nowinski committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
### css:svg task (will be called by the css task automatically)
```bash
sgc css:svg --ext [extension name]
```

Triggers the generation of Sass-mixins for all SVGs inside the given directory. Each mixin will enable the usage of the
associated SVG as a css background image.

```scss
@import 'svg'; // imports the file with the generated mixins (inside your Sass-root)

.icon-globe {
    @include inline-svg($icon-globe); // inserts the file icon-globe.svg as an inlined background-image
}
```


151
### css:abovethefold (will be called by the css task automatically) (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
152 153 154 155 156 157 158 159 160 161 162 163 164
```bash
svg css:abovethefold
```

This task will read the html file you specified as abovethefold.template, read every <link> statement in it and replace
it with the css styles the referenced file contains, as an inline style tag. To make use of this feature, you should
create a separate css file in your project (abovethefold.scss -> abovethefold.css), as well as an html-template file
that references this stylesheet (note that the path needs to be relative to the template file). You can then set this
template file as your [PageRenderTemplate](https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#pagerenderertemplatefile).
All styles inside your abovethefold.css file will now be inlined directly into the HTML of your website. Note that you
should think about what to put in this file only styles that should be available directly after the render process on
_every_ page should go there.

Philipp Nowinski's avatar
Philipp Nowinski committed
165 166 167
### css task

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
168
sgc css --ext [extension name]
Philipp Nowinski's avatar
Philipp Nowinski committed
169 170 171 172 173 174 175 176 177
```

Triggers css compilation inside the given directory. Note, that this task will also run the sprite task before it starts.

Assumptions:

* all scss files are inside the sass directory, relative to the given path.
* all css files go into the stylesheets directory, relative to the given path.

178
### images task (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
179 180

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
181
sgc images --ext [extension name]
Philipp Nowinski's avatar
Philipp Nowinski committed
182 183 184 185 186 187 188 189
```

Optimizes all images for the given path.

Assumptions:

* all images are inside the image directory, relative to the given path.

190
### optimize images in fileadmin and uploads (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
191 192

```bash
Philipp Nowinski's avatar
Philipp Nowinski committed
193
sgc images:uploaded
Philipp Nowinski's avatar
Philipp Nowinski committed
194 195
```

Philipp Nowinski's avatar
Philipp Nowinski committed
196
This tasks optimizes all images (png, jpg, gif, svg) inside the folders you specified in the sgc-config.json file. You might want to
Philipp Nowinski's avatar
Philipp Nowinski committed
197 198
run this task on a regular basis to compress user uploaded media.

199
# Extending the sgc with your own modules (enterprise feature)
Philipp Nowinski's avatar
Philipp Nowinski committed
200

201
You can easily extend the sgc functionality by writing your own modules. Simply create a sgc-scripts folder next to sgc-core
Philipp Nowinski's avatar
Philipp Nowinski committed
202 203 204 205 206
and put your custom scripts in there. Right now only shell-scripts with are supported, other languages might follow in the future.

Execute your custom scripts by calling sgc <scriptName>

```
207 208
+ sgc-core
+ sgc-scripts
Philipp Nowinski's avatar
Philipp Nowinski committed
209 210 211 212 213 214 215 216 217
    - updateInstance.sh
    - updateDeployData.sh
```


```bash
sgc updateInstance
```

Philipp Nowinski's avatar
Philipp Nowinski committed
218 219
# Troubleshooting

Philipp Nowinski's avatar
Philipp Nowinski committed
220 221 222 223 224
## Timeouts of the registry while installing the toolchain

Please try to remove the npm-shrinkgwrap.json file and execute the following commands:

```bash
225
cd sgc-core
Philipp Nowinski's avatar
Philipp Nowinski committed
226 227 228 229
rm -rf node_modules
npm set registry http://registry.npmjs.org/
npm install
```