Skip to content

Instantly share code, notes, and snippets.

@yahyaerturan
Created January 26, 2021 12:39
Show Gist options
  • Save yahyaerturan/d943026e0eaedd7c99175e219bb16283 to your computer and use it in GitHub Desktop.
Save yahyaerturan/d943026e0eaedd7c99175e219bb16283 to your computer and use it in GitHub Desktop.
grunt.js
const nodeSass = require('node-sass');
module.exports = function(grunt) {
const webPageScripts = {
'./assets_web/build/js/web.min.js': './assets_web/js/web.js'
};
const appScriptsRunBabel = {
'./assets_app/build/babel/vayes.wtk.js': './assets_app/vendor/vayes/wtk.js/vayes.wtk.js',
'./assets_app/build/babel/grid.vayes.js': './assets_app/js/components/grid.vayes.js',
'./assets_app/build/babel/prime.js': './assets_app/js/prime.js',
'./assets_app/build/babel/login.js': './assets_app/js/login.js',
};
const appPrimePageScripts = {
'./assets_app/build/js/login.min.js': './assets_app/build/babel/login.js',
'./assets_app/build/js/com.grid.vayes.min.js': [
// './assets_app/vendor/underscore.js/underscore-min.js', /** @shared **/
'./assets_app/vendor/lodash/lodash.custom.min.js',
'./assets_app/theme/vendors/select2/js/select2.full.min.js',
'./assets_app/theme/vendors/select2/js/i18n/tr.js',
'./assets_app/theme/vendors/select2/js/i18n/zh-CN.js',
'./assets_app/build/babel/grid.vayes.js',
'./assets_app/vendor/jscroll/dist.js',
]
};
let appThemeCSS = [
'./assets_app/theme/vendors/select2/css/select2.css',
'./assets_app/build/css/theme.css',
],
appPrimeCSS = [
'./node_modules/flag-icon-css/css/flag-icon.css',
'./assets_app/vendor/matter/matter.css',
'./assets_app/build/css/prime.css'
],
appThemeVendorJS = [
'./assets_app/theme/vendors/jquery/jquery.min.js',
'./assets_app/theme/vendors/popper.js/popper.min.js',
'./assets_app/theme/vendors/bootstrap/js/bootstrap.min.js',
'./assets_app/theme/vendors/jquery-scrollbar/jquery.scrollbar.min.js',
'./assets_app/theme/vendors/jquery-scrollLock/jquery-scrollLock.min.js',
'./assets_app/theme/vendors/autosize/autosize.min.js',
],
appThemeRunJS = [
'./assets_app/theme/js/inc/functions/vendors.js',
'./assets_app/theme/js/inc/functions/app.js',
'./assets_app/theme/js/inc/actions.js',
],
appPrimeVendorJS = [
'./node_modules/es6-shim/es6-shim.min.js',
'./assets_app/vendor/holder.js/holder.min.js',
'./assets_app/build/babel/mdl.min.js',
'./assets_app/vendor/jquery.animatecss/jquery.animatecss.min.js',
'./assets_app/defs/animate.definitions.js',
'./assets_app/vendor/mdtoast/mdtoast.min.js',
'./assets_app/vendor/jquery.inview/index.js',
'./assets_app/vendor/sortable/sortable.min.js',
'./assets_app/build/babel/vayes.wtk.js',
'./assets_app/build/babel/prime.js',
],
materialDesignLite = [
'./assets_app/vendor/mdl/mdlComponentHandler.js',
'./assets_app/vendor/mdl/requestAnimationFrame.js',
'./assets_app/vendor/mdl/button/button.js',
'./assets_app/vendor/mdl/checkbox/checkbox.js',
'./assets_app/vendor/mdl/progress/progress.js',
'./assets_app/vendor/mdl/radio/radio.js',
'./assets_app/vendor/mdl/spinner/spinner.js',
'./assets_app/vendor/mdl/switch/switch.js',
'./assets_app/vendor/mdl/tabs/tabs.js',
'./assets_app/vendor/mdl/ripple/ripple.js',
],
appPrimeDevToolsJS = [
"./assets_app/vendor/verge.js/verge.min.js",
"./assets_app/vendor/vayes/bs4.viewport/bs4.viewport.js",
],
webCSS = [
"./assets_web/build/css/web.css"
],
webVendorJS = [
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'./node_modules/holderjs/holder.min.js',
'./assets_app/vendor/mdtoast/mdtoast.min.js',
'./assets_app/build/babel/vayes.wtk.js',
],
fontsFolder = 'fonts/**/*',
imagesFolder = 'img/**/*',
buildAppCSSFiles = "./assets_app/build/css/**/**/*.css",
buildWebCSSFiles = "./assets_web/build/css/**/**/*.css"
;
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Compile sass files to css
sass: {
options: {
implementation: nodeSass,
sourceMap: true
},
appScss: {
files: {
"./assets_app/build/css/theme.css": "./assets_app/theme/scss/app.scss",
"./assets_app/build/css/prime.css": "./assets_app/scss/prime.scss",
"./assets_app/build/css/mdl.min.css": "./assets_app/scss/mdl.scss",
}
},
webScss: {
files: {
"./assets_web/build/css/web.css": "./assets_web/scss/web.scss"
}
}
},
// Minify css files
cssmin: {
appCSS: {
options: {
keepSpecialComments: 0,
},
files: {
'./assets_app/build/css/app.min.css': appThemeCSS,
'./assets_app/build/css/prime.min.css': appPrimeCSS
}
},
webCSS: {
options: {
keepSpecialComments: 0,
},
files: {
'./assets_web/build/css/web.min.css': webCSS
}
}
},
// Clean files
clean: {
options: {
force: true
},
// idea: '**/.idea',
ds: '**/.DS_Store',
thumbs_db: '**/Thumbs.db',
// App Folders
appBuildFolder: './assets_app/build',
appDistCSSFolder: './public/app/dist/css',
appDistJSFolder: './public/app/dist/js',
appDistImgFolder: './public/app/dist/img',
appDistFontFolder: './public/app/dist/fonts',
appDistFlagFolder: './public/app/dist/flags',
// Web Folders
webBuildFolder: './assets_web/build',
webDistCSSFolder: './public/web/dist/css',
webDistJSFolder: './public/web/dist/js',
webDistImgFolder: './public/web/dist/img',
webDistFontFolder: './public/web/dist/fonts',
webDistFlagFolder: './public/web/dist/flags',
},
postcss: {
options: {
map: {
inline: false, // save all sourcemaps as separate files...
annotation: './assets_app/build/css/' // ...to the specified directory
},
processors: [
require('pixrem')(), // add fallbacks for rem units
require('autoprefixer')(), // add vendor prefixes
require('cssnano')() // minify the result
]
},
appCSS: {
src: buildAppCSSFiles
},
webCSS: {
src: buildWebCSSFiles
}
},
babel: {
options: {
sourceMap: true
},
appBabel: {
files: appScriptsRunBabel
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
ie8: true,
output: {
max_line_len: 5000
}
},
appJS: {
files: {
'./assets_app/build/js/app.vendor.min.js': appThemeVendorJS,
'./assets_app/build/js/app.min.js': appThemeRunJS,
'./assets_app/build/js/prime.vendor.min.js': appPrimeVendorJS,
'./assets_app/build/js/mdl.min.js': materialDesignLite,
'./assets_app/build/js/prime.devtools.min.js': appPrimeDevToolsJS,
}
},
appPagesJS: {
files: appPrimePageScripts
},
webJS: {
files: {
'./assets_web/build/js/web.vendor.min.js': webVendorJS
}
},
webPagesJS: {
files: webPageScripts
},
},
copy: {
appThemeFonts: {
expand: true,
cwd: './assets_app/theme',
src: fontsFolder,
dest: './public/app/dist'
},
appPrimeFonts: {
expand: true,
cwd: './assets_app',
src: fontsFolder,
dest: './public/app/dist'
},
appThemeImages: {
expand: true,
cwd: './assets_app/theme',
src: imagesFolder,
dest: './public/app/dist'
},
appPrimeImages: {
expand: true,
cwd: './assets_app',
src: imagesFolder,
dest: './public/app/dist'
},
appMdlImages: {
expand: true,
cwd: './assets_app/vendor/mdl',
src: imagesFolder,
dest: './public/app/dist'
},
appMaterialDesignIconicFonts: {
expand: true,
cwd: './assets_app/theme/vendors/material-design-iconic-font',
src: fontsFolder,
dest: './public/app/dist'
},
appFlagIcons: {
expand: true,
cwd: './node_modules/flag-icon-css',
src: 'flags/**/**/*',
dest: './public/app/dist',
},
appCopyJS2Dist: {
expand: true,
cwd: './assets_app/build',
src: 'js/**/**/*',
dest: './public/app/dist'
},
appCopyCSS2Dist: {
expand: true,
cwd: './assets_app/build',
src: 'css/**/**/*',
dest: './public/app/dist'
},
webFonts: {
expand: true,
cwd: './assets_web',
src: fontsFolder,
dest: './public/web/dist'
},
webImages: {
expand: true,
cwd: './assets_web',
src: imagesFolder,
dest: './public/web/dist'
},
webMaterialDesignIconicFonts: {
expand: true,
cwd: './assets_app/theme/vendors/material-design-iconic-font',
src: fontsFolder,
dest: './public/web/dist'
},
webFlagIcons: {
expand: true,
cwd: './node_modules/flag-icon-css',
src: 'flags/**/**/*',
dest: './public/web/dist',
},
webCopyJS2Dist: {
expand: true,
cwd: './assets_web/build',
src: 'js/**/**/*',
dest: './public/web/dist'
},
webCopyCSS2Dist: {
expand: true,
cwd: './assets_web/build',
src: 'css/**/**/*',
dest: './public/web/dist'
}
},
watch: {
// App Watch Tasks
appCSS: {
files: [
'./assets_app/scss/**/**/*.scss',
'./assets_app/theme/scss/**/**/*.scss',
'./assets_app/vendor/**/**/*.scss',
'./assets_app/vendor/**/**/*.css',
],
tasks: ['sass:appScss', 'postcss:appCSS', 'cssmin:appCSS', 'copy:appCopyCSS2Dist']
},
appJS: {
files: [
'./assets_app/def/**/**/*.js',
'./assets_app/theme/js/**/**/*.js',
'./assets_app/vendor/**/**/*.js',
'./assets_app/vendor/**/**/*.min.js'
],
tasks: ['babel:appBabel', 'uglify:appJS', 'uglify:appPagesJS', 'copy:appCopyJS2Dist']
},
appPagesJS: {
files: [
'./assets_app/js/**/**/*.js',
],
tasks: ['babel:appBabel', 'uglify:appPagesJS', 'copy:appCopyJS2Dist']
},
appFonts: {
files: ['./assets_app/fonts/**/**/*', './assets_app/theme/fonts/**/**/*'],
tasks: ['copy:appPrimeFonts', 'copy:appThemeFonts']
},
appImages: {
files: [
'./assets_app/img/**/**/*',
'./assets_app/theme/img/**/**/*',
'./assets_app/vendor/mdl/images/**/**/*'
],
tasks: ['copy:appPrimeImages', 'copy:appThemeImages', 'copy:appMdlImages']
},
// Web Watch Tasks
webCSS: {
files: ['./assets_web/scss/**/**/*.scss'],
tasks: ['sass:webScss', 'postcss:webCSS', 'cssmin:webCSS', 'copy:webCopyCSS2Dist']
},
webJS: {
files: [
'./assets_web/js/**/**/*.js',
],
tasks: ['uglify:webJS', 'copy:webCopyJS2Dist']
},
webPagesJS: {
files: [
'./assets_web/js/**/**/*.js',
],
tasks: ['uglify:webPagesJS', 'copy:webCopyJS2Dist']
},
webFonts: {
files: ['./assets_web/fonts/**/**/*'],
tasks: ['copy:webFonts']
},
webImages: {
files: ['./assets_web/img/**/**/*'],
tasks: ['copy:webImages']
},
}
});
// Load plugins
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-postcss');
// App task(s).
grunt.registerTask('app:full', [
'clean:ds',
'clean:thumbs_db',
'clean:appBuildFolder',
'clean:appDistCSSFolder',
'clean:appDistJSFolder',
'clean:appDistImgFolder',
'clean:appDistFontFolder',
'clean:appDistFlagFolder',
'sass:appScss',
'postcss:appCSS',
'cssmin:appCSS',
'babel:appBabel',
'uglify:appJS',
'uglify:appPagesJS',
'copy:appCopyJS2Dist',
'copy:appCopyCSS2Dist',
'copy:appThemeFonts',
'copy:appPrimeFonts',
'copy:appThemeImages',
'copy:appPrimeImages',
'copy:appMdlImages',
'copy:appMaterialDesignIconicFonts',
'copy:appFlagIcons'
]);
grunt.registerTask('app:lite', [
'clean:appBuildFolder',
'clean:appDistCSSFolder',
'clean:appDistJSFolder',
'sass:appScss',
'postcss:appCSS',
'cssmin:appCSS',
'babel:appBabel',
'uglify:appJS',
'uglify:appPagesJS',
'copy:appCopyJS2Dist',
'copy:appCopyCSS2Dist'
]);
grunt.registerTask('app:static', [
'clean:appDistImgFolder',
'clean:appDistFontFolder',
'clean:appDistFlagFolder',
'copy:appThemeFonts',
'copy:appPrimeFonts',
'copy:appThemeImages',
'copy:appPrimeImages',
'copy:appMaterialDesignIconicFonts',
'copy:appFlagIcons'
]);
grunt.registerTask('app:js', ['babel:appBabel', 'uglify:appJS', 'uglify:appPagesJS', 'copy:appCopyJS2Dist']);
grunt.registerTask('app:css', ['sass:appScss', 'postcss:appCSS', 'cssmin:appCSS', 'copy:appCopyCSS2Dist']);
grunt.registerTask('app:flags', ['copy:appFlagIcons']);
// Web task(s)
grunt.registerTask('web:full', [
'clean:ds',
'clean:thumbs_db',
'clean:webBuildFolder',
'clean:webDistCSSFolder',
'clean:webDistJSFolder',
'clean:webDistImgFolder',
'clean:webDistFontFolder',
'clean:webDistFlagFolder',
'sass:webScss',
'postcss:webCSS',
'cssmin:webCSS',
'app:js',
'uglify:webJS',
'uglify:webPagesJS',
'copy:webCopyJS2Dist',
'copy:webCopyCSS2Dist',
'copy:webFonts',
'copy:webImages',
'copy:webImages',
'copy:webMaterialDesignIconicFonts',
'copy:webFlagIcons'
]);
grunt.registerTask('web:lite', [
'clean:webBuildFolder',
'clean:webDistCSSFolder',
'clean:webDistJSFolder',
'sass:webScss',
'postcss:webCSS',
'cssmin:webCSS',
'app:js',
'uglify:webJS',
'uglify:webPagesJS',
'copy:webCopyJS2Dist',
'copy:webCopyCSS2Dist'
]);
grunt.registerTask('web:static', [
'clean:webDistImgFolder',
'clean:webDistFontFolder',
'clean:webDistFlagFolder',
'copy:webFonts',
'copy:webImages',
'copy:webMaterialDesignIconicFonts',
'copy:webFlagIcons'
]);
grunt.registerTask('web:js', ['app:js', 'uglify:webJS', 'uglify:webPagesJS', 'copy:webCopyJS2Dist']);
grunt.registerTask('web:css', ['sass:webScss', 'postcss:webCSS', 'cssmin:webCSS', 'copy:webCopyCSS2Dist']);
grunt.registerTask('web:flags', ['copy:webFlagIcons']);
};
{
"name": "vayes-prime-cmf",
"author": "Yahya Erturan <[email protected]>",
"license": "proprietary",
"description": "Installed via npm install grunt grunt-contrib-jshint grunt-contrib-nodeunit gruntjs/grunt-contrib-uglify#harmony grunt-contrib-watch grunt-contrib-copy grunt-sass grunt-contrib-cssmin grunt-postcss grunt-contrib-clean grunt-contrib-connect autoprefixer cssnano grunt-newer pixrem --save-dev",
"private": true,
"version": "1.0.0",
"dependencies": {
"bootstrap4-fs-modal": "^0.1.5",
"es6-shim": "^0.35.5",
"flag-icon-css": "^3.4.5",
"holderjs": "^2.9.6",
"jquery": "^3.4.1",
"jquery-custom-select": "^1.6.4",
"node-snackbar": "^0.1.16",
"popper.js": "^1.16.1",
"sortablejs": "^1.10.2"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-throw-expressions": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"autoprefixer": "^9.7.4",
"clean-css": "^4.2.3",
"cssnano": "^4.1.10",
"grunt": "^1.1.0",
"grunt-babel": "^8.0.0",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^3.0.0",
"grunt-contrib-jshint": "^2.1.0",
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-contrib-uglify-es": "github:gruntjs/grunt-contrib-uglify#harmony",
"grunt-contrib-watch": "^1.1.0",
"grunt-newer": "^1.3.0",
"grunt-postcss": "^0.9.0",
"grunt-sass": "^3.1.0",
"node-sass": "^4.13.1",
"pixrem": "^5.0.0"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"Firefox ESR",
"not dead"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment