Merge branch 'experimental-rollup' into 'master'

Switch to using rollup instead of custom transformer

See merge request ghost/risk-dice-modifier!1
This commit is contained in:
Johannes Loher 2021-02-16 03:57:31 +01:00
commit f282e5bf3a
8 changed files with 1268 additions and 3050 deletions

View file

@ -3,6 +3,7 @@
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"esbenp.prettier-vscode", "esbenp.prettier-vscode",
"gruntfuggly.todo-tree", "gruntfuggly.todo-tree",
"eg2.vscode-npm-script" "eg2.vscode-npm-script",
"msjsdiag.debugger-for-chrome"
] ]
} }

16
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"runtimeExecutable": "/usr/bin/chromium",
"name": "Launch Chrome against localhost",
"url": "http://localhost:30000/game",
"webRoot": "${workspaceFolder}/dist"
}
]
}

View file

@ -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:'));

4155
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -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-node-resolve": "^11.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,13 @@
"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",
"rollup-plugin-typescript2": "^0.29.0",
"tslib": "^2.1.0",
"typescript": "^4.1.3", "typescript": "^4.1.3",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },

12
rollup.config.js Normal file
View file

@ -0,0 +1,12 @@
const typescript = require('rollup-plugin-typescript2');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
module.exports = {
input: 'src/module/risk-dice-modifier.ts',
output: {
dir: 'dist/module',
format: 'es',
sourcemap: true,
},
plugins: [nodeResolve(), typescript({})],
};

View file

@ -6,9 +6,7 @@
"version": "0.1.1", "version": "0.1.1",
"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.1/download?job=build", "download": "https://git.f3l.de/ghost/risk-dice-modifier/-/jobs/artifacts/0.1.1/download?job=build",

View file

@ -6,7 +6,8 @@
"esModuleInterop": true, "esModuleInterop": true,
"moduleResolution": "node", "moduleResolution": "node",
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true "strict": true,
"sourceMap": true
}, },
"include": ["src"] "include": ["src"]
} }