Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of mjs #154

Merged
merged 4 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -79,7 +79,7 @@
"access": "public"
},
"lint-staged": {
"*.(cjs|js|ts)": "eslint --fix",
"*.(cjs|mjs|js|ts)": "eslint --fix",
"*.(json)": "prettier --write"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/presets/ghost-gulp-rollup/get-template-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion template/ghost-gulp-rollup/.eslintrc.cjs.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {

{% endif %} parserOptions: {
ecmaVersion: 2020,
extraFileExtensions: ['.cjs', '.mjs'],
sourceType: 'module',{% if useTypeScript %}
project: './tsconfig.eslint.json',{% endif %}
},
Expand Down Expand Up @@ -33,7 +34,7 @@ module.exports = {
},
},{% else %}
{
files: ['./*.js', './*.cjs'],
files: ['./*.js', './*.cjs', './*.mjs'],
env: {
node: true,
},
Expand Down
2 changes: 1 addition & 1 deletion template/ghost-gulp-rollup/.gulp.json.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
"gulpfile": "gulpfile.mjs"
}
}
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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(
Expand All @@ -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 */
Expand All @@ -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}`)) {
Expand Down Expand Up @@ -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';
Expand All @@ -156,10 +156,3 @@ async function link() {
await fs.symlink(path.resolve(distDirectory), linkDirectory);
}
}

module.exports = {
watch,
build,
clean,
link
};
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion template/ghost-gulp-rollup/tsconfig.eslint.json.njk
Original file line number Diff line number Diff line change
@@ -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"]
}
63 changes: 39 additions & 24 deletions test/presets/ghost-gulp-rollup/generate-programmatic-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -112,60 +112,66 @@ 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',
});
});
});
});

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', () => {
it('generates a lint-staged configuration for ts, js, cjs, json, and less', () => {
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',
});
});
});
});

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', () => {
it('generates a lint-staged configuration for ts, js, cjs, json, and scss', () => {
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',
});
});
Expand All @@ -179,67 +185,76 @@ 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', () => {
it('generates a lint-staged configuration for js, cjs, json, and css', () => {
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',
});
});
});
});

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', () => {
it('generates a lint-staged configuration for js, cjs, json, and less', () => {
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',
});
});
});
});

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', () => {
it('generates a lint-staged configuration for js, cjs, json, and scss', () => {
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',
});
});
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -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"]
}