init.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /* jshint node:true */
  2. module.exports = function(grunt) {
  3. 'use strict';
  4. const path = require('path');
  5. const basedir = path.dirname(grunt.file.findup('Gruntfile.js'));
  6. const theme_name = grunt.file.readJSON(path.join(basedir, 'package.json')).name;
  7. // this is weird, but we need to parse a PHP array in JS
  8. let icon_map = {};
  9. let icomoon = grunt.file.read( basedir + '/vamtam/assets/fonts/icons/list.php', { encoding: 'utf8' } ).split( "\n" );
  10. let theme_icons = grunt.file.read( basedir + '/vamtam/assets/fonts/theme-icons/list.php', { encoding: 'utf8' } ).split( "\n" );
  11. icomoon.forEach( function( line ) {
  12. line = line.split( '=>' );
  13. if ( line.length > 1 ) {
  14. let name = line[0].trim().replace( /['"]/g, '' );
  15. let code = line[1].trim().replace( ',', '' );
  16. icon_map[ 'vamtam-icomoon-' + name ] = code.replace( '0x', '\\' );
  17. }
  18. } );
  19. theme_icons.forEach( function( line ) {
  20. line = line.split( '=>' );
  21. if ( line.length > 1 ) {
  22. let name = line[0].trim().replace( /['"]/g, '' );
  23. let code = line[1].trim().replace( ',', '' );
  24. icon_map[ 'vamtam-theme-' + name ] = code.replace( '0x', '\\' );
  25. }
  26. } );
  27. return {
  28. pkg: grunt.file.readJSON('package.json'),
  29. basedir,
  30. uglify: {
  31. options: {
  32. screwIE8: true,
  33. },
  34. front: {
  35. src: '<%= pkg.jsLocation %>all.js',
  36. dest: '<%= pkg.jsLocation %>all.min.js',
  37. },
  38. sticky_header: {
  39. src: '<%= pkg.jsLocation %>build/sticky-header.js',
  40. dest: '<%= pkg.jsLocation %>build/sticky-header.min.js',
  41. },
  42. low_priority: {
  43. src: '<%= pkg.jsLocation %>build/low-priority.js',
  44. dest: '<%= pkg.jsLocation %>build/low-priority.min.js',
  45. },
  46. admin: {
  47. src: '<%= pkg.adminJsLocation %>admin-all.js',
  48. dest: '<%= pkg.adminJsLocation %>admin-all.min.js',
  49. },
  50. customizer_crow: {
  51. src: '<%= pkg.customizerLocation %>assets/js/color-row.js',
  52. dest: '<%= pkg.customizerLocation %>assets/js/color-row.min.js',
  53. },
  54. customizer_background: {
  55. src: '<%= pkg.customizerLocation %>assets/js/background.js',
  56. dest: '<%= pkg.customizerLocation %>assets/js/background.min.js',
  57. },
  58. customizer_multicheck: {
  59. src: '<%= pkg.customizerLocation %>assets/js/multicheck.js',
  60. dest: '<%= pkg.customizerLocation %>assets/js/multicheck.min.js',
  61. },
  62. customizer_typography: {
  63. src: '<%= pkg.customizerLocation %>assets/js/typography.js',
  64. dest: '<%= pkg.customizerLocation %>assets/js/typography.min.js',
  65. },
  66. customizer_button: {
  67. src: '<%= pkg.customizerLocation %>assets/js/button.js',
  68. dest: '<%= pkg.customizerLocation %>assets/js/button.min.js',
  69. },
  70. },
  71. browserify: {
  72. customizer_preview: {
  73. options: {
  74. transform: [
  75. ["babelify", {
  76. presets: [ 'es2015', 'es2016', 'es2017' ],
  77. }]
  78. ]
  79. },
  80. files: {
  81. '<%= pkg.adminJsLocation %>customizer-preview.js': ['<%= pkg.adminJsLocation %>customizer/preview.js'],
  82. }
  83. },
  84. customize_controls_conditionals: {
  85. options: {
  86. transform: [
  87. ["babelify", {
  88. presets: [ 'es2015', 'es2016', 'es2017' ],
  89. }]
  90. ]
  91. },
  92. files: {
  93. '<%= pkg.adminJsLocation %>customize-controls-conditionals.js': ['<%= pkg.adminJsLocation %>customizer/controls-conditionals.js'],
  94. }
  95. },
  96. sticky_header: {
  97. options: {
  98. transform: [
  99. ["babelify", {
  100. presets: [ 'es2015', 'es2016', 'es2017' ],
  101. }]
  102. ]
  103. },
  104. files: {
  105. '<%= pkg.jsLocation %>build/sticky-header.js': ['<%= pkg.jsLocation %>src/sticky-header.js'],
  106. }
  107. },
  108. low_priority: {
  109. options: {
  110. transform: [
  111. ["babelify", {
  112. presets: [ 'es2015', 'es2016', 'es2017' ],
  113. }]
  114. ]
  115. },
  116. files: {
  117. '<%= pkg.jsLocation %>build/low-priority.js': ['<%= pkg.jsLocation %>src/low-priority.js'],
  118. }
  119. }
  120. },
  121. jshint: {
  122. files: [
  123. '**/*.js',
  124. '!**/*.min.js',
  125. '!documentation/**',
  126. '!vamtam/plugins/*/**',
  127. '!style_switcher/**',
  128. '!vendor/**',
  129. '!vamtam/assets/js/all.js',
  130. '!vamtam/assets/js/build/**',
  131. '!vamtam/assets/js/classList.js',
  132. '!vamtam/assets/js/polyfills.js',
  133. '!vamtam/assets/js/plugins/thirdparty/**',
  134. '!vamtam/assets/cubeportfolio/**',
  135. '!vamtam/redux/extensions/advanced_customizer/**',
  136. // to be processed by babel
  137. '!vamtam/admin/assets/js/customizer/**',
  138. // generated by babel
  139. '!vamtam/admin/assets/js/customize-controls-conditionals.js',
  140. '!vamtam/admin/assets/js/customizer-preview.js',
  141. '!vamtam/admin/assets/js/customizer-preview-front.js',
  142. '!node_modules/**',
  143. '!build/**',
  144. '!dist/**',
  145. '!utils/grunt/**',
  146. ],
  147. options: {
  148. // 'curly': true,
  149. // 'quotmark': 'single',
  150. 'eqeqeq': true,
  151. 'eqnull': true,
  152. 'esversion': 5,
  153. 'expr': true,
  154. 'immed': true,
  155. 'multistr': true,
  156. 'noarg': true,
  157. 'strict': true,
  158. 'trailing': true,
  159. 'undef': true,
  160. 'unused': true,
  161. 'browser': true,
  162. 'devel': true,
  163. 'globals': {
  164. '_': false,
  165. 'ajaxurl': false,
  166. 'autosave': false,
  167. 'Backbone': false,
  168. 'colorValidate': false,
  169. 'jQuery': false,
  170. 'Modernizr': false,
  171. 'quicktags': false,
  172. 'RetinaImage': false,
  173. 'RetinaImagePath': false,
  174. 'send_to_editor': false,
  175. 'switchEditors': false,
  176. 'tinyMCE': false,
  177. 'tinymce': false,
  178. 'tinyMCEPreInit': false,
  179. 'vamtam_greensock_wait': false,
  180. 'vamtamgs': false,
  181. 'wp': false,
  182. 'wpActiveEditor': true,
  183. 'VAMTAM_ADMIN': false,
  184. 'VAMTAM_CUSTOMIZE_PREVIEW': false,
  185. 'VAMTAM_FRONT': false,
  186. 'VAMTAM_HIDDEN_WIDGETS': false,
  187. 'vamtam_yepnope': false,
  188. 'VAMTAMED_LANG': false,
  189. 'VamtamTmceShortcodes': false,
  190. 'Cookies': false,
  191. 'imagesLoaded': false,
  192. 'IntersectionObserver': false,
  193. 'FLBuilder': false,
  194. },
  195. }
  196. },
  197. concat: {
  198. options: {
  199. separator: '\n',
  200. },
  201. dist: {
  202. src: [
  203. '<%= pkg.jsLocation %>lib.js',
  204. '<%= pkg.jsLocation %>greensock-loader.js',
  205. '<%= pkg.jsLocation %>polyfills.js',
  206. '<%= pkg.jsLocation %>classList.js',
  207. '<%= pkg.jsLocation %>media.js',
  208. '<%= pkg.jsLocation %>menu.js',
  209. '<%= pkg.jsLocation %>column-progressive-animation.js',
  210. '<%= pkg.jsLocation %>column-parallax.js',
  211. '<%= pkg.jsLocation %>general.js',
  212. '<%= pkg.jsLocation %>lazyload.js',
  213. '<%= pkg.jsLocation %>cube.js',
  214. '<%= pkg.jsLocation %>woocommerce.js',
  215. ],
  216. dest: '<%= pkg.jsLocation %>all.js',
  217. nonull: true,
  218. },
  219. admin: {
  220. src: [
  221. '<%= pkg.adminJsLocation %>plugins/jquery.vamtam.colorpicker.js',
  222. '<%= pkg.adminJsLocation %>plugins/jquery.vamtam.backgroundoption.js',
  223. '<%= pkg.adminJsLocation %>upload.js',
  224. '<%= pkg.adminJsLocation %>vamtam_admin.js',
  225. '<%= pkg.adminJsLocation %>post-format-options.js',
  226. ],
  227. dest: '<%= pkg.adminJsLocation %>admin-all.js',
  228. nonull: true,
  229. },
  230. },
  231. watch: {
  232. js: {
  233. files: [
  234. '<%= concat.dist.src %>',
  235. '<%= concat.admin.src %>',
  236. '<%= uglify.customizer_crow.src %>',
  237. '<%= uglify.customizer_button.src %>',
  238. '<%= uglify.customizer_background.src %>',
  239. '<%= uglify.customizer_multicheck.src %>',
  240. '<%= uglify.customizer_typography.src %>',
  241. '<%= uglify.sticky_header.src %>',
  242. '<%= pkg.jsLocation %>src/**',
  243. '<%= pkg.adminJsLocation %>customizer/**',
  244. ],
  245. tasks: ['buildjs'],
  246. },
  247. fonts: {
  248. files: [ '<%= basedir %>/vamtam/assets/fonts/theme-icons/*.ttf' ],
  249. tasks: ['ttf2woff2']
  250. },
  251. 'less-theme': {
  252. files: [ '<%= basedir %>/vamtam/assets/css/**/*.less' ],
  253. tasks: ['less:theme']
  254. },
  255. 'less-admin': {
  256. files: [ '<%= basedir %>/vamtam/admin/assets/css/**/*.less' ],
  257. tasks: ['less:admin']
  258. },
  259. 'less-customizer': {
  260. files: [ '<%= pkg.customizerLocation %>assets/less/**/*.less' ],
  261. tasks: ['less:customizer']
  262. },
  263. },
  264. ttf2woff2: {
  265. 'theme-icons': {
  266. src: [ '<%= basedir %>/vamtam/assets/fonts/theme-icons/*.ttf' ],
  267. dest: '<%= basedir %>/vamtam/assets/fonts/theme-icons/',
  268. }
  269. },
  270. compress: {
  271. theme: {
  272. options: {
  273. archive: path.join( 'dist', theme_name + '.zip' ),
  274. mode: 'zip',
  275. pretty: true,
  276. level: 9,
  277. },
  278. files: [{
  279. expand: true,
  280. src: [
  281. '**/*',
  282. '!**/vamtam/assets/fonts/*/selection.json',
  283. '!**/vamtam/assets/fonts/*/*.svg',
  284. ],
  285. cwd: 'build/'
  286. }]
  287. }
  288. },
  289. makepot: {
  290. target: {
  291. options: {
  292. domainPath: '/languages/',
  293. exclude: [ 'vamtam/plugins/.*', 'documentation/.*', 'build/.*' ],
  294. mainFile: 'style.css',
  295. potFilename: theme_name + '.pot',
  296. type: 'wp-theme',
  297. updateTimestamp: true,
  298. }
  299. }
  300. },
  301. parallel: {
  302. dev: {
  303. options: {
  304. stream: true,
  305. grunt: true,
  306. },
  307. tasks: [ 'watch:js', 'watch:fonts', 'watch:less-theme', 'watch:less-admin', 'watch:less-customizer' ],
  308. },
  309. composer: {
  310. options: {
  311. stream: true
  312. },
  313. tasks: [{
  314. cmd: 'composer',
  315. args: ['install']
  316. }]
  317. },
  318. 'fetch-wp-devel': {
  319. options: {
  320. stream: true
  321. },
  322. tasks: [{
  323. cmd: 'svn',
  324. args: ['co', 'http://develop.svn.wordpress.org/trunk/', path.join('/tmp', 'wp-devel')]
  325. }]
  326. },
  327. },
  328. less: {
  329. options: {
  330. strictMath: true,
  331. strictUnits: true,
  332. plugins: [
  333. new ( require('less-plugin-autoprefix') )( { browsers: [ 'last 2 version', '>1%', 'not ie 10' ] } ),
  334. new ( require('less-plugin-clean-css') )( { level: 2 } )
  335. ],
  336. customFunctions: {
  337. icon: function( less, icon ) {
  338. return '"' + ( icon_map[ icon.value ] || 'missing icon' ) + '"';
  339. },
  340. },
  341. },
  342. customizer: {
  343. expand: true,
  344. cwd: '<%= pkg.customizerLocation %>assets/less/',
  345. src: [
  346. '**/*.less',
  347. ],
  348. dest: '<%= pkg.customizerLocation %>assets/css/',
  349. ext: '.css',
  350. },
  351. admin: {
  352. options: {
  353. paths: [ '<%= basedir %>/vamtam/admin/assets/css' ],
  354. },
  355. expand: true,
  356. cwd: '<%= basedir %>/vamtam/admin/assets/css',
  357. src: [
  358. 'vamtam_admin.less',
  359. 'customizer.less',
  360. ],
  361. dest: '<%= basedir %>/vamtam/admin/assets/css',
  362. ext: '.css',
  363. },
  364. theme: {
  365. options: {
  366. paths: [ '<%= basedir %>/vamtam/assets/css' ],
  367. },
  368. expand: true,
  369. cwd: './vamtam/assets/css/src/',
  370. src: [
  371. 'responsive/**/*.less',
  372. 'widgets/**/*.less',
  373. 'all.less',
  374. 'ie11.less',
  375. '!deps/**',
  376. '!**/mixins.less',
  377. ],
  378. dest: 'vamtam/assets/css/dist/',
  379. ext: '.css',
  380. }
  381. },
  382. clean: {
  383. build: 'build/',
  384. dist: 'dist/',
  385. 'post-copy': {
  386. src: [
  387. 'build/**/vamtam/plugins/**/*',
  388. '!build/**/vamtam/plugins/*.php',
  389. '!build/**/vamtam/plugins/foodpress.zip',
  390. '!build/**/vamtam/plugins/revslider.zip',
  391. '!build/**/vamtam/plugins/vamtam-importers.zip',
  392. '!build/**/vamtam/plugins/vamtam-elements-b.zip',
  393. 'build/**/node_modules',
  394. 'build/**/desktop.ini',
  395. 'build/**/style_switcher',
  396. 'build/**/secrets.json',
  397. 'build/**/cache/empty',
  398. ]
  399. }
  400. },
  401. copy: {
  402. theme: {
  403. src: '**/*',
  404. dest: path.join('build', theme_name) + path.sep
  405. },
  406. 'layerslider-samples': {
  407. expand: true,
  408. src: ['**'],
  409. cwd: 'samples/layerslider/',
  410. dest: 'vamtam/plugins/layerslider/sampleslider/'
  411. }
  412. },
  413. replace: {
  414. 'style-switcher': {
  415. options: {
  416. patterns: [{
  417. match: /\/\/ @todo remove everything after and including this comment when packaging for sale[\s\S]*/,
  418. replacement: ''
  419. }]
  420. },
  421. files: [{
  422. src: [ path.join('build', theme_name, 'functions.php') ],
  423. dest: path.join('build', theme_name, 'functions.php'),
  424. }]
  425. }
  426. },
  427. 'add-textdomain': {
  428. theme: [
  429. '**/*.php',
  430. '!vendor/**',
  431. '!vamtam/plugins/*/**',
  432. '!node_modules',
  433. ]
  434. },
  435. phpcs: {
  436. application: {
  437. src: [
  438. '**/*.php',
  439. '!vamtam/plugins/vamtam-importers/**',
  440. // not outputted as html
  441. '!vamtam/plugins/vamtam-elements-*/modules/*/includes/frontend.css.php',
  442. '!vamtam/plugins/vamtam-elements-*/modules/*/includes/frontend.js.php',
  443. // not used in this theme
  444. '!vamtam/plugins/vamtam-push-menu/**',
  445. '!vamtam/plugins/vamtam-sermons/**',
  446. '!vamtam/plugins/vamtam-scrolling/**',
  447. '!vamtam/plugins/vamtam-love-it/**',
  448. '!vamtam/options/help/docs.php',
  449. '!style_switcher/**',
  450. // third-party code
  451. '!vamtam/plugins/layerslider/**',
  452. '!vamtam/plugins/revslider/**',
  453. '!vamtam/plugins/foodpress/**',
  454. '!vamtam/plugins/timetable/**',
  455. '!vamtam/plugins/vamtam-elements-*/extensions/fl-builder-*/**',
  456. '!utils/**',
  457. '!vendor/**',
  458. '!vamtam/classes/mobile-detect.php',
  459. '!vamtam/classes/plugin-activation.php',
  460. '!vamtam/admin/helpers/updates/class-envato-protected-api.php',
  461. '!node_modules/**',
  462. '!**/node_modules/**',
  463. '!documentation/**',
  464. '!vamtam/redux/extensions/advanced_customizer/**',
  465. ],
  466. },
  467. options: {
  468. bin: 'phpcs',
  469. standard: 'vamtam',
  470. p: true,
  471. report: 'summary',
  472. // report: 'full',
  473. }
  474. },
  475. ucss: {
  476. local: {
  477. options: {
  478. // whitelist: [],
  479. // auth: null
  480. },
  481. pages: {
  482. crawl: 'http://construction.demo.local',
  483. include: []
  484. },
  485. css: ['http://construction.demo.local/wp-content/themes/construction/cache/all.css']
  486. }
  487. }
  488. };
  489. };