Skip to content

Commit 68d0fbf

Browse files
author
Rafael Grigorian
committed
Fixed GH-87
1 parent 694ff19 commit 68d0fbf

File tree

7 files changed

+692
-1222
lines changed

7 files changed

+692
-1222
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
# Magento - Cloudflare
1+
# Magento Cloudflare
22
> Interact with popular Cloudflare features though Magento's backend portal
33
4-
![MIT License](https://img.shields.io/badge/License-MIT-orange.svg?style=for-the-badge)
5-
![Version 1.0.2](https://img.shields.io/badge/Version-1.0.2-orange.svg?style=for-the-badge)
6-
![Stability Beta](https://img.shields.io/badge/Stability-Beta-orange.svg?style=for-the-badge)
7-
![Magento](https://img.shields.io/badge/Magento-1-orange.svg?style=for-the-badge)
4+
![](https://img.shields.io/badge/License-MIT-orange.svg?style=for-the-badge)
5+
![](https://img.shields.io/badge/Version-1.0.2-orange.svg?style=for-the-badge)
6+
![](https://img.shields.io/badge/Stability-Stable-orange.svg?style=for-the-badge)
7+
![](https://img.shields.io/badge/Magento-1-orange.svg?style=for-the-badge)
88

99
<p align="center" >
1010
<img src="docs/images/preview.png" width="100%" />
1111
</p>
1212

1313
## Documentation
14-
15-
A user guide can be found in the [docs](docs) folder. The information there goes over all the features that the extension offers. It also takes you through the installation and configuration process of setting this extension up.
14+
The user guide can be found in the [docs](docs) folder. The user guide goes through the installation process as well as explains all the features that comes with this plugin. For furthur support, please email [development@jetrails.com](mailto://development@jetrails.com).
1615

1716
## Build System
18-
19-
This extension uses __GULP__ for it's build system. Gulp is a package that can be easily downloaded using __NPM__. Once this repository is cloned, run `npm install gulp -g` followed by `npm install` to install Gulp and all Gulp plugins used within this build system. Please refer to the following table for a description of some useful gulp build commands. A typical gulp command takes the following form: `gulp <task>`.
20-
21-
| Task | Description |
22-
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
23-
| `watch` | Automatically compiles, combines, and minifies JS and SCSS before deploying the code into the staging environment. |
24-
| `package` | Packages extension into _TGZ_ archive inside _dist_ folder. | |
17+
This extension uses __Gulp__ as it's build system. Gulp is a package that can be easily downloaded using __NPM__ or __Yarn__. Once this repository is cloned, run `npm install gulp -g` followed by `npm install` or `yarn install` to install Gulp and all Gulp modules used within this build system. Please refer to the following table for a description of some useful Gulp commands. A typical Gulp command takes the following form: `gulp <command>`.
18+
19+
| Command | Description |
20+
|-----------|-----------------------------------------------------------------------------------------|
21+
| `init` | Creates build, staging, and distribution directories |
22+
| `clean` | Deletes build and distribution directories |
23+
| `bump` | Bumps version number in source files to reflect version found in package.json |
24+
| `build` | Builds and copies files from source directory to the build directory |
25+
| `deploy` | Copies files from build directory to the staging directory |
26+
| `watch` | Watches files in source directory and executes `deploy` on file change |
27+
| `package` | Updates package.xml with file hashes and packages extension into distribution directory |
2528

2629
## Docker Environment
27-
28-
This project comes with a [docker-compose.yml](docker-compose.yml) file, which can be used to spin up a Magento CE 1.x environment. In order to use docker, please make sure you have **Docker** and **Docker Compose** installed. For information about configuring this docker environment, please refer to it's Github repository which can be found [here](https://github.com/jetrails/docker-magento).
30+
This project comes with a [docker-compose.yml](docker-compose.yml) and a [docker-sync.yml](docker-sync.yml) file, which can be used to spin up a Magento 1 development environment. In order to use docker, please make sure you have **Docker**, **Docker Compose**, and **Docker Sync** installed. For information about configuring this docker environment, please refer to it's Github repository which can be found [here](https://github.com/jetrails/docker-magento-alpine).

conf/package.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<name>JetRails_Cloudflare</name>
4+
<version></version>
5+
<date></date>
6+
<time></time>
7+
<stability>stable</stability>
8+
<license uri="https://opensource.org/licenses/MIT">MIT License (MIT)</license>
9+
<channel>community</channel>
10+
<extends/>
11+
<summary>Interact with popular Cloudflare features though Magento's backend portal.</summary>
12+
<description></description>
13+
<notes></notes>
14+
<authors>
15+
<author>
16+
<name>Rafael Grigorian</name>
17+
<user>jetrails</user>
18+
<email>development@jetrails.com</email>
19+
</author>
20+
</authors>
21+
<compatible/>
22+
<dependencies>
23+
<required>
24+
<php>
25+
<min>5.1.0</min>
26+
<max>5.6.0</max>
27+
</php>
28+
</required>
29+
</dependencies>
30+
<contents></contents>
31+
</package>

gulpfile.js

Lines changed: 79 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,114 @@
1-
const concat = require ("gulp-concat")
2-
const fs = require ("fs")
31
const gulp = require ("gulp")
2+
const concat = require ("gulp-concat")
43
const gzip = require ("gulp-gzip")
5-
const path = require ("path")
6-
const config = require ( path.join ( __dirname, "package.json" ) )
74
const magepack = require ("gulp-magepack")
85
const minify = require ("gulp-minify-css")
96
const minifyJs = require ("gulp-minify")
7+
const replace = require ("gulp-replace")
108
const sass = require ("gulp-sass")
11-
const uglify = require ("gulp-uglify")
9+
const tar = require ("gulp-tar")
10+
const fs = require ("fs")
11+
const fse = require ("fs-extra")
12+
const path = require ("path")
1213
const webpack = require ("webpack")
1314
const webpackStream = require ("webpack-stream")
14-
const gulpIgnore = require ("gulp-ignore")
15-
const webpackConfig = require ( path.join ( __dirname, "webpack.config.js" ) )
16-
const tar = require ("gulp-tar")
1715

18-
const EXTENSION_NAMESPACE = "JetRails_Cloudflare"
19-
const EXTENSION_VERSION = config.version
16+
const PACKAGE_NAMESPACE = require ("./package.json").namespace
17+
const PACKAGE_VERSION = require ("./package.json").version
18+
const PACKAGE_SHORTNAME = PACKAGE_NAMESPACE.split ("_") [1].toLowerCase ()
2019

21-
const MODULE_SHORT_NAME = config.name.replace ( /^.*-/, "" )
2220
const SOURCE_DIR = "src"
2321
const BUILD_DIR = "build"
2422
const STAGING_DIR = "public_html"
25-
const SOURCE_PATH = path.join ( __dirname, SOURCE_DIR )
26-
const BUILD_PATH = path.join ( __dirname, BUILD_DIR )
27-
const STAGING_PATH = path.join ( __dirname, STAGING_DIR )
28-
const MAGENTO_SKIN_CSS = path.join ( "skin", "adminhtml", "base", "default", "css" )
29-
const MAGENTO_SKIN_SCSS = path.join ( "skin", "adminhtml", "base", "default", "scss" )
30-
const MAGENTO_SKIN_JS = path.join ( "skin", "adminhtml", "base", "default", "js" )
31-
32-
gulp.task ( "default", [ "build-styles", "build-scripts" ] );
33-
gulp.task ( "deploy", [ "deploy-staging" ] );
23+
const PACKAGE_DIR = "dist"
3424

3525
gulp.task ( "init", [], ( callback ) => {
36-
if ( !fs.existsSync ( SOURCE_PATH ) ) fs.mkdirSync ( SOURCE_PATH )
37-
if ( !fs.existsSync ( BUILD_PATH ) ) fs.mkdirSync ( BUILD_PATH )
38-
if ( !fs.existsSync ( STAGING_PATH ) ) fs.mkdirSync ( STAGING_PATH )
26+
let mkdirNotExists = ( name ) => {
27+
if ( !fs.existsSync ( name ) ) {
28+
fs.mkdirSync ( name )
29+
}
30+
}
31+
mkdirNotExists ( BUILD_DIR )
32+
mkdirNotExists ( PACKAGE_DIR )
33+
mkdirNotExists ( STAGING_DIR )
3934
callback ()
4035
})
4136

42-
gulp.task ( "build-styles", [ "init" ], ( callback ) => {
43-
gulp.src ( path.join ( SOURCE_PATH, MAGENTO_SKIN_SCSS, MODULE_SHORT_NAME, "index.scss" ) )
44-
.pipe ( sass ({ includePaths: path.join ( SOURCE_PATH, MAGENTO_SKIN_SCSS ) }) )
37+
gulp.task ( "clean", [], ( callback ) => {
38+
let unlinkExists = ( name ) => {
39+
if ( fs.existsSync ( name ) ) {
40+
fse.removeSync ( name )
41+
}
42+
}
43+
unlinkExists ( BUILD_DIR )
44+
unlinkExists ( PACKAGE_DIR )
45+
callback ()
46+
})
47+
48+
gulp.task ( "bump", [], ( callback ) => {
49+
return gulp.src (`${SOURCE_DIR}/**/*`)
50+
.pipe ( replace ( /(^.*\*\s+@version\s+)(.+$)/gm, "$1" + PACKAGE_VERSION ) )
51+
.pipe ( gulp.dest ( SOURCE_DIR ) )
52+
.on ( "done", callback )
53+
})
54+
55+
gulp.task ( "build-styles", ["init"], ( callback ) => {
56+
return gulp.src (`${SOURCE_DIR}/skin/adminhtml/base/default/scss/${PACKAGE_SHORTNAME}/index.scss`)
57+
.pipe ( sass ({ includePaths: `${SOURCE_DIR}/skin/adminhtml/base/default/scss` }) )
4558
.pipe ( minify () )
4659
.pipe ( concat ("bundle.min.css") )
47-
.pipe ( gulp.dest ( path.join ( BUILD_PATH, MAGENTO_SKIN_CSS, MODULE_SHORT_NAME ) ) )
48-
.on ( "end", callback )
60+
.pipe ( gulp.dest (`${BUILD_DIR}/skin/adminhtml/base/default/css/${PACKAGE_SHORTNAME}`) )
61+
.on ( "done", callback )
4962
})
5063

51-
gulp.task ( "build-scripts", [ "init" ], ( callback ) => {
52-
gulp.src ( path.join ( SOURCE_PATH, MAGENTO_SKIN_JS, MODULE_SHORT_NAME, "index.js" ) )
53-
.pipe ( webpackStream ( webpackConfig ), webpack )
64+
gulp.task ( "build-scripts", ["init"], ( callback ) => {
65+
return gulp.src (`${SOURCE_DIR}/skin/adminhtml/base/default/js/${PACKAGE_SHORTNAME}/index.js`)
66+
.pipe ( webpackStream ( require ("./webpack.config.js") ), webpack )
5467
.pipe ( minifyJs ({ ext: { min: ".min.js" } }) )
55-
.pipe ( gulp.dest ( path.join ( BUILD_PATH, MAGENTO_SKIN_JS, MODULE_SHORT_NAME ) ) )
68+
.pipe ( gulp.dest (`${BUILD_DIR}/skin/adminhtml/base/default/js/${PACKAGE_SHORTNAME}`) )
69+
.on ( "done", callback )
70+
})
71+
72+
gulp.task ( "build", [ "build-styles", "build-scripts" ], ( callback ) => {
73+
let ignoreJs = [
74+
`!${SOURCE_DIR}/skin/adminhtml/base/default/js`,
75+
`!${SOURCE_DIR}/skin/adminhtml/base/default/js/**/*`
76+
]
77+
let ignoreCss = [
78+
`!${SOURCE_DIR}/skin/adminhtml/base/default/scss`,
79+
`!${SOURCE_DIR}/skin/adminhtml/base/default/scss/**/*`,
80+
`${SOURCE_DIR}/skin/adminhtml/base/default/scss/${PACKAGE_SHORTNAME}/fonts/**/*`
81+
]
82+
return gulp.src ( [`${SOURCE_DIR}/**`].concat ( ignoreJs ).concat ( ignoreCss ) )
83+
.pipe ( gulp.dest ( BUILD_DIR ) )
5684
.on ( "end", () => {
57-
fs.unlinkSync ( path.join ( BUILD_PATH, MAGENTO_SKIN_JS, MODULE_SHORT_NAME, "bundle.js" ) )
58-
callback ()
85+
fse.copySync (
86+
`${SOURCE_DIR}/skin/adminhtml/base/default/scss/${PACKAGE_SHORTNAME}/fonts`,
87+
`${BUILD_DIR}/skin/adminhtml/base/default/css/${PACKAGE_SHORTNAME}/fonts`
88+
)
5989
})
90+
.on ( "done", callback )
6091
})
6192

62-
gulp.task ( "deploy-source", [ "build-styles", "build-scripts" ], function ( callback ) {
63-
var sourceFiles = path.join ( SOURCE_PATH, "**", "*" )
64-
var notStyle = "!" + path.join ( SOURCE_PATH, "**", "js", "**/" )
65-
var notScript = "!" + path.join ( SOURCE_PATH, "**", "scss", "**/" )
66-
var notScriptFolder = "!" + path.join ( SOURCE_PATH, "**", "scss" )
67-
gulp.src ([ path.join ( SOURCE_PATH, MAGENTO_SKIN_SCSS, MODULE_SHORT_NAME, "fonts", "**", "*" ) ])
68-
.pipe ( gulp.dest ( path.join ( BUILD_PATH, MAGENTO_SKIN_CSS, MODULE_SHORT_NAME, "fonts" ) ) )
69-
gulp.src ([ sourceFiles, notStyle, notScript, notScriptFolder ])
70-
.pipe ( gulp.dest ( path.join ( BUILD_PATH ) ) )
71-
.on ( "end", callback )
72-
});
73-
74-
gulp.task ( "deploy-staging", [ "deploy-source", ], function ( callback ) {
75-
gulp.src ( path.join ( BUILD_PATH, "**", "*" ) )
76-
.pipe ( gulp.dest ( path.join ( STAGING_PATH ) ) )
77-
.on ( "end", callback )
78-
});
93+
gulp.task ( "deploy", ["build"], ( callback ) => {
94+
return gulp.src (`${BUILD_DIR}/**/*`)
95+
.pipe ( gulp.dest ( STAGING_DIR ) )
96+
.on ( "done", callback )
97+
})
7998

80-
gulp.task ( "watch", [ "deploy-staging" ], () => {
81-
gulp.watch ( path.join ( SOURCE_PATH, "**", "*" ), [ "deploy-staging" ] );
82-
gulp.watch ( path.join ( SOURCE_PATH, "**", "*.scss" ), [ "deploy-staging" ] );
83-
gulp.watch ( path.join ( SOURCE_PATH, "**", "*.js" ), [ "deploy-staging" ] );
99+
gulp.task ( "watch", ["deploy"], () => {
100+
return gulp.watch ( `${SOURCE_DIR}/**/*`, ["deploy"] )
84101
})
85102

86-
gulp.task ( "package", () => {
103+
gulp.task ( "package", [ "clean", "bump", "build" ], ( callback ) => {
87104
let options = {
88-
"template": "package.xml",
89-
"output": "package.xml",
90-
"version": EXTENSION_VERSION
105+
"template": "conf/package.xml",
106+
"version": PACKAGE_VERSION
91107
}
92-
gulp.src ([ path.join ( BUILD_PATH, "**", "*" ) ])
108+
gulp.src (`${BUILD_DIR}/**/*`)
93109
.pipe ( magepack ( options ) )
94-
.pipe ( gulpIgnore.exclude ("package.xml") )
95-
.pipe ( tar (`${EXTENSION_NAMESPACE}-${EXTENSION_VERSION}`) )
110+
.pipe ( tar (`${PACKAGE_NAMESPACE}-${PACKAGE_VERSION}`) )
96111
.pipe ( gzip ({ extension: "tgz" }) )
97-
.pipe ( gulp.dest ("dist") )
112+
.pipe ( gulp.dest ( PACKAGE_DIR ) )
113+
.on ( "done", callback )
98114
})

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
"author": "Rafael Grigorian",
66
"company": "JetRails®",
77
"license": "MIT",
8+
"namespace": "JetRails_Cloudflare",
89
"repository": {
910
"type": "git",
1011
"url": "https://github.com/jetrails/magento-cloudflare.git"
1112
},
1213
"devDependencies": {
1314
"extract-text-webpack-plugin": "^3.0.2",
15+
"fs-extra": "^7.0.0",
1416
"gulp": "^3.9.1",
1517
"gulp-concat": "^2.6.1",
1618
"gulp-gzip": "^1.4.2",
17-
"gulp-ignore": "^2.0.2",
1819
"gulp-magepack": "^1.0.3",
1920
"gulp-minify": "^2.1.0",
2021
"gulp-minify-css": "^1.2.4",
22+
"gulp-replace": "^1.0.0",
2123
"gulp-sass": "^3.2.1",
2224
"gulp-tar": "^2.1.0",
2325
"gulp-uglify": "^3.0.0",
@@ -27,8 +29,5 @@
2729
"dependencies": {
2830
"jquery": "^3.2.1",
2931
"jquery-ui": "^1.12.1"
30-
},
31-
"scripts": {
32-
"watch": "node_modules/.bin/gulp watch"
3332
}
3433
}

0 commit comments

Comments
 (0)