diff --git a/package.json b/package.json index 338e3ab7..1a372575 100644 --- a/package.json +++ b/package.json @@ -43,12 +43,12 @@ "scripts": { "build": "rollup -c", "build:watch": "rollup -c --watch", - "lint": "eslint --ext .ts,.js,.cjs .", - "lint:fix": "eslint --ext .ts,.js,.cjs --fix .", + "lint": "eslint --ext .ts,.js,.cjs,.mjs .", + "lint:fix": "eslint --ext .ts,.js,.cjs,.mjs --fix .", "test": "jest", "test:watch": "jest --watch", "test:ci": "jest --ci --reporters=default --reporters=jest-junit", - "format": "prettier --write './**/*.(ts|js|json)'", + "format": "prettier --write './**/*.(ts|js|cjs|mjs|json)'", "prepare": "husky install" }, "contributors": [ @@ -79,7 +79,7 @@ "access": "public" }, "lint-staged": { - "*.(cjs|js|ts)": "eslint --fix", + "*.(cjs|mjs|js|ts)": "eslint --fix", "*.(json)": "prettier --write" } } diff --git a/rollup.config.js b/rollup.config.mjs similarity index 100% rename from rollup.config.js rename to rollup.config.mjs diff --git a/src/presets/ghost-gulp-rollup/generate-programmatic-files.ts b/src/presets/ghost-gulp-rollup/generate-programmatic-files.ts index dc43e46e..754dc28c 100644 --- a/src/presets/ghost-gulp-rollup/generate-programmatic-files.ts +++ b/src/presets/ghost-gulp-rollup/generate-programmatic-files.ts @@ -36,7 +36,7 @@ export function generatePackage( options: Options, ghostGulpRollupOptions: GhostGulpRollupOptions, ): Package { - const codeFileTypes = ghostGulpRollupOptions.useTypeScript ? ['ts', 'js', 'cjs'] : ['js', 'cjs']; + const codeFileTypes = ghostGulpRollupOptions.useTypeScript ? ['ts', 'js', 'cjs', 'mjs'] : ['js', 'cjs', 'mjs']; const codeFileExtensions = codeFileTypes.map((fileType) => `.${fileType}`); const typecheckScript = ghostGulpRollupOptions.useTypeScript ? `tsc --noEmit` : undefined; diff --git a/src/presets/ghost-gulp-rollup/get-template-files.ts b/src/presets/ghost-gulp-rollup/get-template-files.ts index 25035acd..6803a2a9 100644 --- a/src/presets/ghost-gulp-rollup/get-template-files.ts +++ b/src/presets/ghost-gulp-rollup/get-template-files.ts @@ -28,9 +28,9 @@ function getConfigTemplateFiles( '.gulp.json', '.nvmrc', 'foundryconfig.json', - 'gulpfile.cjs', + 'gulpfile.mjs', 'README.md', - 'rollup.config.cjs', + 'rollup.config.mjs', ]; if (useTesting) { diff --git a/template/ghost-gulp-rollup/.eslintrc.cjs.njk b/template/ghost-gulp-rollup/.eslintrc.cjs.njk index 9d6ba3c4..4e073207 100644 --- a/template/ghost-gulp-rollup/.eslintrc.cjs.njk +++ b/template/ghost-gulp-rollup/.eslintrc.cjs.njk @@ -3,6 +3,7 @@ module.exports = { {% endif %} parserOptions: { ecmaVersion: 2020, + extraFileExtensions: ['.cjs', '.mjs'], sourceType: 'module',{% if useTypeScript %} project: './tsconfig.eslint.json',{% endif %} }, @@ -33,7 +34,7 @@ module.exports = { }, },{% else %} { - files: ['./*.js', './*.cjs'], + files: ['./*.js', './*.cjs', './*.mjs'], env: { node: true, }, diff --git a/template/ghost-gulp-rollup/.gulp.json.njk b/template/ghost-gulp-rollup/.gulp.json.njk index 6cdb49a5..518fce83 100644 --- a/template/ghost-gulp-rollup/.gulp.json.njk +++ b/template/ghost-gulp-rollup/.gulp.json.njk @@ -1,5 +1,5 @@ { "flags": { - "gulpfile": "gulpfile.cjs" + "gulpfile": "gulpfile.mjs" } } diff --git a/template/ghost-gulp-rollup/gulpfile.cjs.njk b/template/ghost-gulp-rollup/gulpfile.mjs.njk similarity index 82% rename from template/ghost-gulp-rollup/gulpfile.cjs.njk rename to template/ghost-gulp-rollup/gulpfile.mjs.njk index 9b9e601b..b062ef1c 100644 --- a/template/ghost-gulp-rollup/gulpfile.cjs.njk +++ b/template/ghost-gulp-rollup/gulpfile.mjs.njk @@ -1,17 +1,17 @@ -const fs = require('fs-extra'); -const gulp = require('gulp');{% if styleType == 'less' %} -const less = require('gulp-less');{% elif styleType == 'scss' %} -const sass = require('gulp-dart-sass');{% endif %} -const sourcemaps = require('gulp-sourcemaps'); -const path = require('node:path'); -const buffer = require('vinyl-buffer'); -const source = require('vinyl-source-stream'); -const yargs = require('yargs'); -const { hideBin } = require('yargs/helpers'); +import fs from 'fs-extra' +import gulp from 'gulp'{% if styleType == 'less' %} +import less from 'gulp-less'{% elif styleType == 'scss' %} +import sass from 'gulp-dart-sass'{% endif %} +import sourcemaps from 'gulp-sourcemaps' +import path from 'node:path' +import buffer from 'vinyl-buffer' +import source from 'vinyl-source-stream' +import yargs from 'yargs' +import { hideBin } from 'yargs/helpers' -const rollupStream = require('@rollup/stream'); +import rollupStream from '@rollup/stream' -const rollupConfig = require('./rollup.config.cjs'); +import rollupConfig from './rollup.config.mjs' /********************/ /* CONFIGURATION */ @@ -71,7 +71,7 @@ async function copyFiles() { /** * Watch for changes for each build step */ -function watch() { +export function watch() { gulp.watch(`${sourceDirectory}/**/*.${sourceFileExtension}`, { ignoreInitial: false }, buildCode); gulp.watch(`${stylesDirectory}/**/*.${stylesExtension}`, { ignoreInitial: false }, buildStyles); gulp.watch( @@ -81,7 +81,7 @@ function watch() { ); } -const build = gulp.series(clean, gulp.parallel(buildCode, buildStyles, copyFiles)); +export const build = gulp.series(clean, gulp.parallel(buildCode, buildStyles, copyFiles)); /********************/ /* CLEAN */ @@ -90,7 +90,7 @@ const build = gulp.series(clean, gulp.parallel(buildCode, buildStyles, copyFiles /** * Remove built files from `dist` folder while ignoring source files */ -async function clean() { +export async function clean() { const files = [...staticFiles, 'module']; if (fs.existsSync(`${stylesDirectory}/${name}.${stylesExtension}`)) { @@ -129,7 +129,7 @@ function getDataPath() { /** * Link build to User Data folder */ -async function link() { +export async function link() { let destinationDirectory; if (fs.existsSync(path.resolve(sourceDirectory, '{{ type }}.json'))) { destinationDirectory = '{{ type }}s'; @@ -156,10 +156,3 @@ async function link() { await fs.symlink(path.resolve(distDirectory), linkDirectory); } } - -module.exports = { - watch, - build, - clean, - link -}; diff --git a/template/ghost-gulp-rollup/rollup.config.cjs.njk b/template/ghost-gulp-rollup/rollup.config.mjs.njk similarity index 57% rename from template/ghost-gulp-rollup/rollup.config.cjs.njk rename to template/ghost-gulp-rollup/rollup.config.mjs.njk index b94674ed..f891f990 100644 --- a/template/ghost-gulp-rollup/rollup.config.cjs.njk +++ b/template/ghost-gulp-rollup/rollup.config.mjs.njk @@ -1,7 +1,7 @@ -{% if useTypeScript %}const typescript = require('@rollup/plugin-typescript'); -{% endif %}const { nodeResolve } = require ('@rollup/plugin-node-resolve'); +{% if useTypeScript %}import typescript from '@rollup/plugin-typescript'; +{% endif %}import { nodeResolve } from '@rollup/plugin-node-resolve'; -module.exports = () => ({ +export default () => ({ input: 'src/module/{{ name }}.{% if useTypeScript %}ts{% else %}js{% endif %}', output: { dir: 'dist/module', diff --git a/template/ghost-gulp-rollup/tsconfig.eslint.json.njk b/template/ghost-gulp-rollup/tsconfig.eslint.json.njk index ab024eae..e895099e 100644 --- a/template/ghost-gulp-rollup/tsconfig.eslint.json.njk +++ b/template/ghost-gulp-rollup/tsconfig.eslint.json.njk @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "include": ["src", {% if useTesting %}"test", {% endif %}"*.js", "*.cjs", ".*.js", ".*.cjs"] + "include": ["src", {% if useTesting %}"test", {% endif %}"*.js", "*.cjs", "*.mjs", ".*.js", ".*.cjs", ".*.mjs"] } diff --git a/test/presets/ghost-gulp-rollup/generate-programmatic-files.test.ts b/test/presets/ghost-gulp-rollup/generate-programmatic-files.test.ts index db87090b..1a358ecb 100644 --- a/test/presets/ghost-gulp-rollup/generate-programmatic-files.test.ts +++ b/test/presets/ghost-gulp-rollup/generate-programmatic-files.test.ts @@ -95,11 +95,11 @@ describe('generatePackageJSON', () => { expect(_package.scripts.typecheck).toBe('tsc --noEmit'); }); - it('generates lint scripts that lint ts, js, and cjs', () => { + it('generates lint scripts that lint ts, js, cjs, and mjs', () => { const _package = generatePackage(defaultName, defaultOptions, typescriptOptions); - expect(_package.scripts.lint).toBe('eslint --ext .ts,.js,.cjs .'); - expect(_package.scripts['lint:fix']).toBe('eslint --ext .ts,.js,.cjs --fix .'); + expect(_package.scripts.lint).toBe('eslint --ext .ts,.js,.cjs,.mjs .'); + expect(_package.scripts['lint:fix']).toBe('eslint --ext .ts,.js,.cjs,.mjs --fix .'); }); describe('and not git initialization', () => { @@ -112,18 +112,18 @@ describe('generatePackageJSON', () => { describe('and no CSS preprocessor selected', () => { const cssOptions = { ...typescriptOptions, styleType: 'css' as const }; - it('generates a format script that formats ts, js, cjs, json, and css', () => { + it('generates a format script that formats ts, js, cjs, mjs, json, and css', () => { const _package = generatePackage(defaultName, defaultOptions, cssOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|json|yml|css)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|mjs|json|yml|css)"'); }); describe('and git initialization', () => { - it('generates a lint-staged configuration for ts, js, cjs, json, and css', () => { + it('generates a lint-staged configuration for ts, js, cjs, mjs, json, and css', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, cssOptions); expect(_package['lint-staged']).toEqual({ - '*.(ts|js|cjs)': 'eslint --fix', + '*.(ts|js|cjs|mjs)': 'eslint --fix', '*.(json|yml|css)': 'prettier --write', }); }); @@ -131,12 +131,15 @@ describe('generatePackageJSON', () => { }); describe('and less selected as CSS preprocessor', () => { - const lessOptions = { ...typescriptOptions, styleType: 'less' as const }; + const lessOptions = { + ...typescriptOptions, + styleType: 'less' as const, + }; it('generates a format script that formats ts, js, cjs, json, and less', () => { const _package = generatePackage(defaultName, defaultOptions, lessOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|json|yml|less)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|mjs|json|yml|less)"'); }); describe('and git initialization', () => { @@ -144,7 +147,7 @@ describe('generatePackageJSON', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, lessOptions); expect(_package['lint-staged']).toEqual({ - '*.(ts|js|cjs)': 'eslint --fix', + '*.(ts|js|cjs|mjs)': 'eslint --fix', '*.(json|yml|less)': 'prettier --write', }); }); @@ -152,12 +155,15 @@ describe('generatePackageJSON', () => { }); describe('and sass selected as CSS preprocessor', () => { - const sassOptions = { ...typescriptOptions, styleType: 'scss' as const }; + const sassOptions = { + ...typescriptOptions, + styleType: 'scss' as const, + }; it('generates a format script that formats ts, js, cjs, json, and scss', () => { const _package = generatePackage(defaultName, defaultOptions, sassOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|json|yml|scss)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(ts|js|cjs|mjs|json|yml|scss)"'); }); describe('and git initialization', () => { @@ -165,7 +171,7 @@ describe('generatePackageJSON', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, sassOptions); expect(_package['lint-staged']).toEqual({ - '*.(ts|js|cjs)': 'eslint --fix', + '*.(ts|js|cjs|mjs)': 'eslint --fix', '*.(json|yml|scss)': 'prettier --write', }); }); @@ -179,17 +185,20 @@ describe('generatePackageJSON', () => { it('generates lint scripts that lint js and cjs', () => { const _package = generatePackage(defaultName, defaultOptions, noTypescriptOptions); - expect(_package.scripts.lint).toBe('eslint --ext .js,.cjs .'); - expect(_package.scripts['lint:fix']).toBe('eslint --ext .js,.cjs --fix .'); + expect(_package.scripts.lint).toBe('eslint --ext .js,.cjs,.mjs .'); + expect(_package.scripts['lint:fix']).toBe('eslint --ext .js,.cjs,.mjs --fix .'); }); describe('and no CSS preprocessor selected', () => { - const cssOptions = { ...noTypescriptOptions, styleType: 'css' as const }; + const cssOptions = { + ...noTypescriptOptions, + styleType: 'css' as const, + }; it('generates a format script that formats ts, js, cjs, json, and css', () => { const _package = generatePackage(defaultName, defaultOptions, cssOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|json|yml|css)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|mjs|json|yml|css)"'); }); describe('and git initialization', () => { @@ -197,7 +206,7 @@ describe('generatePackageJSON', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, cssOptions); expect(_package['lint-staged']).toEqual({ - '*.(js|cjs)': 'eslint --fix', + '*.(js|cjs|mjs)': 'eslint --fix', '*.(json|yml|css)': 'prettier --write', }); }); @@ -205,12 +214,15 @@ describe('generatePackageJSON', () => { }); describe('and less selected as CSS preprocessor', () => { - const lessOptions = { ...noTypescriptOptions, styleType: 'less' as const }; + const lessOptions = { + ...noTypescriptOptions, + styleType: 'less' as const, + }; it('generates a format script that formats ts, js, cjs, json, and less', () => { const _package = generatePackage(defaultName, defaultOptions, lessOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|json|yml|less)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|mjs|json|yml|less)"'); }); describe('and git initialization', () => { @@ -218,7 +230,7 @@ describe('generatePackageJSON', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, lessOptions); expect(_package['lint-staged']).toEqual({ - '*.(js|cjs)': 'eslint --fix', + '*.(js|cjs|mjs)': 'eslint --fix', '*.(json|yml|less)': 'prettier --write', }); }); @@ -226,12 +238,15 @@ describe('generatePackageJSON', () => { }); describe('and sass selected as CSS preprocessor', () => { - const sassOptions = { ...noTypescriptOptions, styleType: 'scss' as const }; + const sassOptions = { + ...noTypescriptOptions, + styleType: 'scss' as const, + }; it('generates a format script that formats ts, js, cjs, json, and scss', () => { const _package = generatePackage(defaultName, defaultOptions, sassOptions); - expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|json|yml|scss)"'); + expect(_package.scripts.format).toBe('prettier --write "./**/*.(js|cjs|mjs|json|yml|scss)"'); }); describe('and git initialization', () => { @@ -239,7 +254,7 @@ describe('generatePackageJSON', () => { const _package = generatePackage(defaultName, { ...defaultOptions, git: true }, sassOptions); expect(_package['lint-staged']).toEqual({ - '*.(js|cjs)': 'eslint --fix', + '*.(js|cjs|mjs)': 'eslint --fix', '*.(json|yml|scss)': 'prettier --write', }); }); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 03bb07d3..0ed4f09f 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "include": ["index.ts", "src", "test", "*.js", ".*.js", "*.cjs", ".*.cjs"] + "include": ["index.ts", "src", "test", "*.js", ".*.js", "*.cjs", ".*.cjs", "*.mjs", ".*.mjs"] }