Switch to using rollup instead of custom transformer
This commit is contained in:
parent
e44ceca705
commit
5f8f0007a1
5 changed files with 1074 additions and 3068 deletions
85
gulpfile.js
85
gulpfile.js
|
@ -3,11 +3,9 @@ const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const stringify = require('json-stringify-pretty-compact');
|
const stringify = require('json-stringify-pretty-compact');
|
||||||
const typescript = require('typescript');
|
|
||||||
|
|
||||||
const ts = require('gulp-typescript');
|
|
||||||
|
|
||||||
const argv = require('yargs').argv;
|
const argv = require('yargs').argv;
|
||||||
|
const { rollup } = require('rollup');
|
||||||
|
const rollupConfig = require('./rollup.config');
|
||||||
|
|
||||||
function getManifest() {
|
function getManifest() {
|
||||||
const json = {};
|
const json = {};
|
||||||
|
@ -30,70 +28,6 @@ function getManifest() {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TypeScript transformers
|
|
||||||
* @returns {typescript.TransformerFactory<typescript.SourceFile>}
|
|
||||||
*/
|
|
||||||
function createTransformer() {
|
|
||||||
/**
|
|
||||||
* @param {typescript.Node} node
|
|
||||||
*/
|
|
||||||
function shouldMutateModuleSpecifier(node) {
|
|
||||||
if (!typescript.isImportDeclaration(node) && !typescript.isExportDeclaration(node)) return false;
|
|
||||||
if (node.moduleSpecifier === undefined) return false;
|
|
||||||
if (!typescript.isStringLiteral(node.moduleSpecifier)) return false;
|
|
||||||
if (!node.moduleSpecifier.text.startsWith('./') && !node.moduleSpecifier.text.startsWith('../')) return false;
|
|
||||||
if (path.extname(node.moduleSpecifier.text) !== '') return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms import/export declarations to append `.js` extension
|
|
||||||
* @param {typescript.TransformationContext} context
|
|
||||||
*/
|
|
||||||
function importTransformer(context) {
|
|
||||||
return (node) => {
|
|
||||||
/**
|
|
||||||
* @param {typescript.Node} node
|
|
||||||
*/
|
|
||||||
function visitor(node) {
|
|
||||||
if (shouldMutateModuleSpecifier(node)) {
|
|
||||||
if (typescript.isImportDeclaration(node)) {
|
|
||||||
const newModuleSpecifier = typescript.createLiteral(`${node.moduleSpecifier.text}.js`);
|
|
||||||
return typescript.updateImportDeclaration(
|
|
||||||
node,
|
|
||||||
node.decorators,
|
|
||||||
node.modifiers,
|
|
||||||
node.importClause,
|
|
||||||
newModuleSpecifier,
|
|
||||||
);
|
|
||||||
} else if (typescript.isExportDeclaration(node)) {
|
|
||||||
const newModuleSpecifier = typescript.createLiteral(`${node.moduleSpecifier.text}.js`);
|
|
||||||
return typescript.updateExportDeclaration(
|
|
||||||
node,
|
|
||||||
node.decorators,
|
|
||||||
node.modifiers,
|
|
||||||
node.exportClause,
|
|
||||||
newModuleSpecifier,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return typescript.visitEachChild(node, visitor, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return typescript.visitNode(node, visitor);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return importTransformer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tsConfig = ts.createProject('tsconfig.json', {
|
|
||||||
getCustomTransformers: (_program) => ({
|
|
||||||
after: [createTransformer()],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
/********************/
|
/********************/
|
||||||
/* BUILD */
|
/* BUILD */
|
||||||
/********************/
|
/********************/
|
||||||
|
@ -101,15 +35,16 @@ const tsConfig = ts.createProject('tsconfig.json', {
|
||||||
/**
|
/**
|
||||||
* Build TypeScript
|
* Build TypeScript
|
||||||
*/
|
*/
|
||||||
function buildTS() {
|
async function buildTS() {
|
||||||
return gulp.src('src/**/*.ts').pipe(tsConfig()).pipe(gulp.dest('dist'));
|
const build = await rollup({ input: rollupConfig.input, plugins: rollupConfig.plugins });
|
||||||
|
return build.write(rollupConfig.output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy static files
|
* Copy static files
|
||||||
*/
|
*/
|
||||||
async function copyFiles() {
|
async function copyFiles() {
|
||||||
const statics = ['lang', 'module.json'];
|
const statics = ['module.json'];
|
||||||
try {
|
try {
|
||||||
for (const file of statics) {
|
for (const file of statics) {
|
||||||
if (fs.existsSync(path.join('src', file))) {
|
if (fs.existsSync(path.join('src', file))) {
|
||||||
|
@ -127,11 +62,7 @@ async function copyFiles() {
|
||||||
*/
|
*/
|
||||||
function buildWatch() {
|
function buildWatch() {
|
||||||
gulp.watch('src/**/*.ts', { ignoreInitial: false }, buildTS);
|
gulp.watch('src/**/*.ts', { ignoreInitial: false }, buildTS);
|
||||||
gulp.watch(
|
gulp.watch(['src/*.json'], { ignoreInitial: false }, copyFiles);
|
||||||
['src/fonts', 'src/lang', 'src/templates', 'src/*.json', 'src/packs'],
|
|
||||||
{ ignoreInitial: false },
|
|
||||||
copyFiles,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************/
|
/********************/
|
||||||
|
@ -148,7 +79,7 @@ async function clean() {
|
||||||
|
|
||||||
// If the project uses TypeScript
|
// If the project uses TypeScript
|
||||||
if (fs.existsSync(path.join('src', 'module', `${name}.ts`))) {
|
if (fs.existsSync(path.join('src', 'module', `${name}.ts`))) {
|
||||||
files.push('lang', 'module', `${name}.js`, 'module.json');
|
files.push('module', `${name}.js`, 'module.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(' ', chalk.yellow('Files to clean:'));
|
console.log(' ', chalk.yellow('Files to clean:'));
|
||||||
|
|
4002
package-lock.json
generated
4002
package-lock.json
generated
File diff suppressed because it is too large
Load diff
11
package.json
11
package.json
|
@ -27,13 +27,13 @@
|
||||||
"updateManifest": "gulp updateManifest",
|
"updateManifest": "gulp updateManifest",
|
||||||
"lint": "eslint 'src/**/*.ts' --cache",
|
"lint": "eslint 'src/**/*.ts' --cache",
|
||||||
"lint:fix": "eslint 'src/**/*.ts' --cache --fix",
|
"lint:fix": "eslint 'src/**/*.ts' --cache --fix",
|
||||||
"format": "prettier --write 'src/**/*.(ts|json|scss)'"
|
"format": "prettier --write 'src/**/*.(ts|json)'"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-typescript": "^8.1.1",
|
||||||
"@types/fs-extra": "^9.0.6",
|
"@types/fs-extra": "^9.0.6",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
||||||
"@typescript-eslint/parser": "^4.14.2",
|
"@typescript-eslint/parser": "^4.14.2",
|
||||||
"archiver": "^5.2.0",
|
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
"eslint": "^7.19.0",
|
"eslint": "^7.19.0",
|
||||||
"eslint-config-prettier": "^7.2.0",
|
"eslint-config-prettier": "^7.2.0",
|
||||||
|
@ -41,15 +41,12 @@
|
||||||
"foundry-vtt-types": "github:League-of-Foundry-Developers/foundry-vtt-types#foundry-0.7.9",
|
"foundry-vtt-types": "github:League-of-Foundry-Developers/foundry-vtt-types#foundry-0.7.9",
|
||||||
"fs-extra": "^9.1.0",
|
"fs-extra": "^9.1.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"gulp-git": "^2.10.1",
|
|
||||||
"gulp-less": "^4.0.1",
|
|
||||||
"gulp-sass": "^4.1.0",
|
|
||||||
"gulp-typescript": "^6.0.0-alpha.1",
|
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"json-stringify-pretty-compact": "^2.0.0",
|
"json-stringify-pretty-compact": "^2.0.0",
|
||||||
"lint-staged": "^10.5.4",
|
"lint-staged": "^10.5.4",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.2.1",
|
||||||
"ts-node": "^9.1.1",
|
"rollup": "^2.38.5",
|
||||||
|
"tslib": "^2.1.0",
|
||||||
"typescript": "^4.1.3",
|
"typescript": "^4.1.3",
|
||||||
"yargs": "^16.2.0"
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
|
|
10
rollup.config.js
Normal file
10
rollup.config.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const typescript = require('@rollup/plugin-typescript');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
input: 'src/module/risk-dice-modifier.ts',
|
||||||
|
output: {
|
||||||
|
dir: 'dist/module',
|
||||||
|
format: 'es',
|
||||||
|
},
|
||||||
|
plugins: [typescript()],
|
||||||
|
};
|
|
@ -6,9 +6,7 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"minimumCoreVersion": "0.7.9",
|
"minimumCoreVersion": "0.7.9",
|
||||||
"compatibleCoreVersion": "0.7.9",
|
"compatibleCoreVersion": "0.7.9",
|
||||||
"esmodules": [
|
"esmodules": ["module/risk-dice-modifier.js"],
|
||||||
"module/risk-dice-modifier.js"
|
|
||||||
],
|
|
||||||
"url": "https://git.f3l.de/ghost/risk-dice-modifier",
|
"url": "https://git.f3l.de/ghost/risk-dice-modifier",
|
||||||
"manifest": "https://git.f3l.de/ghost/risk-dice-modifier/-/raw/latest/src/module.json?inline=false",
|
"manifest": "https://git.f3l.de/ghost/risk-dice-modifier/-/raw/latest/src/module.json?inline=false",
|
||||||
"download": "https://git.f3l.de/ghost/risk-dice-modifier/-/jobs/artifacts/0.1.0/download?job=build",
|
"download": "https://git.f3l.de/ghost/risk-dice-modifier/-/jobs/artifacts/0.1.0/download?job=build",
|
||||||
|
|
Reference in a new issue