From cbb3aee3ed900cc5f9972603045ae2d831408ec8 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 26 Nov 2024 23:58:03 +0100 Subject: [PATCH 1/8] Convert Gulpfile to ESM --- hooks/post_gen_project.py | 2 +- .../{gulpfile.js => gulpfile.mjs} | 43 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) rename {{cookiecutter.project_slug}}/{gulpfile.js => gulpfile.mjs} (83%) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 081e806c58..844b1e850f 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -179,7 +179,7 @@ def handle_js_runner(choice, use_docker, use_async): remove_keys=["babel"], scripts={ "dev": "gulp", - "build": "gulp generate-assets", + "build": "gulp build", }, ) remove_webpack_files() diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.mjs similarity index 83% rename from {{cookiecutter.project_slug}}/gulpfile.js rename to {{cookiecutter.project_slug}}/gulpfile.mjs index ee6e702822..339007d40f 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.js +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -3,24 +3,29 @@ //////////////////////////////// // Gulp and package -const { src, dest, parallel, series, watch } = require('gulp'); -const pjson = require('./package.json'); +import { src, dest, parallel, series, watch } from 'gulp'; +import pjson from './package.json' with {type: 'json'}; // Plugins -const autoprefixer = require('autoprefixer'); -const browserSync = require('browser-sync').create(); -const concat = require('gulp-concat'); -const tildeImporter = require('node-sass-tilde-importer'); -const cssnano = require('cssnano'); -const imagemin = require('gulp-imagemin'); -const pixrem = require('pixrem'); -const plumber = require('gulp-plumber'); -const postcss = require('gulp-postcss'); +import autoprefixer from 'autoprefixer'; +import browserSyncLib from 'browser-sync'; +import concat from 'gulp-concat'; +import tildeImporter from 'node-sass-tilde-importer'; +import cssnano from 'cssnano'; +import imagemin from 'gulp-imagemin'; +import pixrem from 'pixrem'; +import plumber from 'gulp-plumber'; +import postcss from 'gulp-postcss'; +import rename from 'gulp-rename'; +import gulpSass from 'gulp-sass'; +import sassLib from 'sass'; +import gulUglifyES from 'gulp-uglify-es'; +import { spawn } from 'node:child_process'; + +const browserSync = browserSyncLib.create(); const reload = browserSync.reload; -const rename = require('gulp-rename'); -const sass = require('gulp-sass')(require('sass')); -const spawn = require('child_process').spawn; -const uglify = require('gulp-uglify-es').default; +const sass = gulpSass(sassLib); +const uglify = gulUglifyES.default; // Relative paths function function pathsConfig(appName) { @@ -163,7 +168,7 @@ function watchPaths() { } // Generate all assets -const generateAssets = parallel(styles, scripts, vendorScripts, imgCompression); +const build = parallel(styles, scripts, vendorScripts, imgCompression); // Set up dev environment {%- if cookiecutter.use_docker == 'n' %} @@ -176,6 +181,6 @@ const dev = parallel(runServer, initBrowserSync, watchPaths); const dev = parallel(initBrowserSync, watchPaths); {%- endif %} -exports.default = series(generateAssets, dev); -exports['generate-assets'] = generateAssets; -exports['dev'] = dev; +export default series(build, dev); +export build; +export dev; From 6b0ceea7db701dc8253414c748c0ced2776696ba Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 00:01:35 +0100 Subject: [PATCH 2/8] fixup! Convert Gulpfile to ESM --- hooks/post_gen_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 844b1e850f..ca1ffad329 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -114,7 +114,7 @@ def remove_sass_files(): def remove_gulp_files(): - file_names = ["gulpfile.js"] + file_names = ["gulpfile.mjs"] for file_name in file_names: os.remove(file_name) From ea014e749997af5c459657374bcb0b22a84d9f8b Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 00:13:20 +0100 Subject: [PATCH 3/8] Fix Gulp tasks definition --- {{cookiecutter.project_slug}}/gulpfile.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index 339007d40f..e070f350ba 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -3,7 +3,7 @@ //////////////////////////////// // Gulp and package -import { src, dest, parallel, series, watch } from 'gulp'; +import { src, dest, parallel, series, task, watch } from 'gulp'; import pjson from './package.json' with {type: 'json'}; // Plugins @@ -181,6 +181,6 @@ const dev = parallel(runServer, initBrowserSync, watchPaths); const dev = parallel(initBrowserSync, watchPaths); {%- endif %} -export default series(build, dev); -export build; -export dev; +task('default', series(build, dev)); +task('build', build); +task('dev', dev); From 8adc4534122ca2780938ea57bfa589f4e9b33b0e Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 08:41:38 +0100 Subject: [PATCH 4/8] Fix sass import --- {{cookiecutter.project_slug}}/gulpfile.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index e070f350ba..d7053a1239 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -18,7 +18,7 @@ import plumber from 'gulp-plumber'; import postcss from 'gulp-postcss'; import rename from 'gulp-rename'; import gulpSass from 'gulp-sass'; -import sassLib from 'sass'; +import * as sassLib from 'sass'; import gulUglifyES from 'gulp-uglify-es'; import { spawn } from 'node:child_process'; From 1763831328bb943a664e8768fe8d5ee7b04d86db Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 08:43:58 +0100 Subject: [PATCH 5/8] Log package.json --- {{cookiecutter.project_slug}}/gulpfile.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index d7053a1239..e96b0405de 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -27,6 +27,8 @@ const reload = browserSync.reload; const sass = gulpSass(sassLib); const uglify = gulUglifyES.default; +console.log("package.json: %o", pjson); + // Relative paths function function pathsConfig(appName) { this.app = `./${pjson.name}`; From 1fe180ae8cad5159803e8ff93beece34dffc7bee Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 09:01:28 +0100 Subject: [PATCH 6/8] Fix setting app name from package.json --- {{cookiecutter.project_slug}}/gulpfile.mjs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index e96b0405de..dc46519da6 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -28,10 +28,11 @@ const sass = gulpSass(sassLib); const uglify = gulUglifyES.default; console.log("package.json: %o", pjson); +console.log("pjson.name=%o", pjson.name); // Relative paths function -function pathsConfig(appName) { - this.app = `./${pjson.name}`; +function pathsConfig() { + const appName = `./${pjson.name}`; const vendorsRoot = 'node_modules'; return { @@ -39,13 +40,13 @@ function pathsConfig(appName) { `${vendorsRoot}/@popperjs/core/dist/umd/popper.js`, `${vendorsRoot}/bootstrap/dist/js/bootstrap.js`, ], - app: this.app, - templates: `${this.app}/templates`, - css: `${this.app}/static/css`, - sass: `${this.app}/static/sass`, - fonts: `${this.app}/static/fonts`, - images: `${this.app}/static/images`, - js: `${this.app}/static/js`, + app: appName, + templates: `${appName}/templates`, + css: `${appName}/static/css`, + sass: `${appName}/static/sass`, + fonts: `${appName}/static/fonts`, + images: `${appName}/static/images`, + js: `${appName}/static/js`, }; } From e30f4df0591a58114639f61d3f1f4e1788cec53f Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 09:07:16 +0100 Subject: [PATCH 7/8] Rename import --- {{cookiecutter.project_slug}}/gulpfile.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index dc46519da6..f6d4a6467b 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -18,13 +18,13 @@ import plumber from 'gulp-plumber'; import postcss from 'gulp-postcss'; import rename from 'gulp-rename'; import gulpSass from 'gulp-sass'; -import * as sassLib from 'sass'; +import * as dartSass from 'sass'; import gulUglifyES from 'gulp-uglify-es'; import { spawn } from 'node:child_process'; const browserSync = browserSyncLib.create(); const reload = browserSync.reload; -const sass = gulpSass(sassLib); +const sass = gulpSass(dartSass); const uglify = gulUglifyES.default; console.log("package.json: %o", pjson); From 8ff3b3bd425f09cfe21428097834775c5e67fc10 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 27 Nov 2024 09:07:26 +0100 Subject: [PATCH 8/8] Rename console.logs --- {{cookiecutter.project_slug}}/gulpfile.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/gulpfile.mjs b/{{cookiecutter.project_slug}}/gulpfile.mjs index f6d4a6467b..8fee32dc7f 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.mjs +++ b/{{cookiecutter.project_slug}}/gulpfile.mjs @@ -27,9 +27,6 @@ const reload = browserSync.reload; const sass = gulpSass(dartSass); const uglify = gulUglifyES.default; -console.log("package.json: %o", pjson); -console.log("pjson.name=%o", pjson.name); - // Relative paths function function pathsConfig() { const appName = `./${pjson.name}`;