From a0f9a7dce1338d8a430372c82fc86870b204420f Mon Sep 17 00:00:00 2001 From: p4535992 Date: Wed, 22 Nov 2023 21:29:36 +0100 Subject: [PATCH] version 2.3.6 --- changelog.md | 7 +- gulpfile.js.bak | 667 ---------------------------------------------- package_gulp.json | 91 ------- src/module.json | 6 +- 4 files changed, 9 insertions(+), 762 deletions(-) delete mode 100644 gulpfile.js.bak delete mode 100644 package_gulp.json diff --git a/changelog.md b/changelog.md index 6237910..19f44b9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,9 @@ -# CHANGELOG +# CHANGELOG + +### 2.3.6 [BREAKING CHANGES] + +- Big clean and first refactoring for the new behaviour + ### 2.3.5 - Fixed bug in reselectTokenAfterInteraction functio, ty to @Saibot393 diff --git a/gulpfile.js.bak b/gulpfile.js.bak deleted file mode 100644 index 165d572..0000000 --- a/gulpfile.js.bak +++ /dev/null @@ -1,667 +0,0 @@ -/* eslint-disable no-useless-escape */ -/* eslint-disable @typescript-eslint/no-var-requires */ - -/** - * This is important for the bundle.js - */ -const mainFilePath = `src/foundryvtt-arms-reach.ts`; // MOD 4535992 - -const gulp = require(`gulp`); -const fs = require(`fs`); -const path = require(`path`); -const archiver = require(`archiver`); -const stringify = require(`json-stringify-pretty-compact`); - -const sourcemaps = require(`gulp-sourcemaps`); -const buffer = require(`vinyl-buffer`); -const source = require(`vinyl-source-stream`); - -const loadJson = (path) => { - console.log(path) - try { - const str = fs.readFileSync(path).toString(); - return JSON.parse(str); - } - catch { - throw Error(`Unable to load module.json`) - } -}; - -const typescript = require(`typescript`); -// const createLiteral = typescript.createLiteral; -const createLiteral = typescript.factory.createStringLiteral; -const factory = typescript.factory; -const isExportDeclaration = typescript.isExportDeclaration; -const isImportDeclaration = typescript.isImportDeclaration; -const isStringLiteral = typescript.isStringLiteral; -const LiteralExpression = typescript.LiteralExpression; -const Node = typescript.Node; -const TransformationContext = typescript.TransformationContext; -const TSTransformer = typescript.Transformer; -const TransformerFactory = typescript.TransformerFactory; -const visitEachChild = typescript.visitEachChild; -const visitNode = typescript.visitNode; - -const less = require(`gulp-less`); -const sass = require(`gulp-sass`)(require(`sass`)); - -// import type {ModuleData} from `@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/packages.mjs`; // MOD 4535992 -const browserify = require(`browserify`); -const tsify = require(`tsify`); - -const ts = require(`gulp-typescript`); -const git = require(`gulp-git`); -const jest = require(`gulp-jest`).default; - -const argv = require(`yargs`).argv; - -function getConfig() { - const configPath = path.resolve(process.cwd(), `foundryconfig.json`); - let config; - - if (fs.existsSync(configPath)) { - config = loadJson(configPath); - return config; - } else { - return; - } -} - -/* MOD 4535992 -interface Manifest { - root: string; - file: ModuleData; - name: string; -} -*/ -const getManifest = () => { - const json = { - root: ``, - // @ts-ignore - file: {}, - name: `` - }; - - if (fs.existsSync(`src`)) { - json.root = `src`; - } else { - json.root = `dist`; - } - - const modulePath = path.join(json.root, `module.json`); - const systemPath = path.join(json.root, `system.json`); - - if (fs.existsSync(modulePath)) { - json.file = loadJson(modulePath); - json.name = `module.json`; - } else if (fs.existsSync(systemPath)) { - json.file = loadJson(systemPath); - json.name = `system.json`; - } else { - return null; - } - - // If we can pull our version from our package - saves us having to maintain the number in different places - if (process.env.npm_package_version) { - json.file[`version`] = process.env.npm_package_version; - } - return json; -} - - -const createTransformer = () => { - /** - * @param {typescript.Node} node - */ - const shouldMutateModuleSpecifier = (node) => { - if (!isImportDeclaration(node) && !isExportDeclaration(node)) - return false; - if (node.moduleSpecifier === undefined) - return false; - if (!isStringLiteral(node.moduleSpecifier)) - return false; - if (!node.moduleSpecifier.text.startsWith(`./`) && !node.moduleSpecifier.text.startsWith(`../`)) - return false; - - return path.extname(node.moduleSpecifier.text) === ``; - } - - return (context) => { - return (node) => { - function visitor(node) { - if (shouldMutateModuleSpecifier(node)) { - if (isImportDeclaration(node)) { - const newModuleSpecifier = createLiteral(`${(node.moduleSpecifier).text}.js`); - return factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, newModuleSpecifier,undefined); - } else if (isExportDeclaration(node)) { - const newModuleSpecifier = createLiteral(`${(node.moduleSpecifier).text}.js`); - return factory.updateExportDeclaration(node, node.decorators, node.modifiers, false, node.exportClause, newModuleSpecifier,undefined); - } - } - return visitEachChild(node, visitor, context); - } - return visitNode(node, visitor); - }; - }; -} - -const tsConfig = ts.createProject(`tsconfig.json`, { - getCustomTransformers: (_program) => ({ - after: [createTransformer()], - }), -}); - -/********************/ -/* BUILD */ -/********************/ - -/** - * Build TypeScript - */ -function buildTS() { - - return ( - gulp - .src(`src/**/*.ts`) - .pipe(tsConfig()) - - - // // eslint() attaches the lint output to the `eslint` property - // // of the file object so it can be used by other modules. - // .pipe(eslint()) - // // eslint.format() outputs the lint results to the console. - // // Alternatively use eslint.formatEach() (see Docs). - // .pipe(eslint.format()) - // // To have the process exit with an error code (1) on - // // lint error, return the stream and pipe to failAfterError last. - // .pipe(eslint.failAfterError()) - - .pipe(gulp.dest(`dist`)) - ); -} - -// function buildTS() { -// const debug = process.env.npm_lifecycle_event !== `package`; -// const res = tsConfig.src() -// .pipe(sourcemaps.init()) -// .pipe(tsConfig()); - -// return res.js -// .pipe(sourcemaps.write(``, { debug: debug, includeContent: true, sourceRoot: `./ts/src` })) -// .pipe(gulp.dest(`dist`)); -// } - -/** - * Build JavaScript - */ -function buildJS() { - return ( - gulp - .src(`src/**/*.js`) - - // // eslint() attaches the lint output to the `eslint` property - // // of the file object so it can be used by other modules. - // .pipe(eslint()) - // // eslint.format() outputs the lint results to the console. - // // Alternatively use eslint.formatEach() (see Docs). - // .pipe(eslint.format()) - // // To have the process exit with an error code (1) on - // // lint error, return the stream and pipe to failAfterError last. - // .pipe(eslint.failAfterError()) - - .pipe(gulp.dest(`dist`)) - ); -} - -/** - * Build Module JavaScript - */ -function buildMJS() { - return ( - gulp - .src(`src/**/*.mjs`) - - // // eslint() attaches the lint output to the `eslint` property - // // of the file object so it can be used by other modules. - // .pipe(eslint()) - // // eslint.format() outputs the lint results to the console. - // // Alternatively use eslint.formatEach() (see Docs). - // .pipe(eslint.format()) - // // To have the process exit with an error code (1) on - // // lint error, return the stream and pipe to failAfterError last. - // .pipe(eslint.failAfterError()) - - .pipe(gulp.dest(`dist`)) - ); -} - -/** - * Build Css - */ -function buildCSS() { - return gulp.src(`src/**/*.css`).pipe(gulp.dest(`dist`)); -} - -/** - * Build Less - */ -function buildLess() { - return gulp.src(`src/**/*.less`).pipe(less()).pipe(gulp.dest(`dist`)); -} - -/** - * Build SASS - */ -function buildSASS() { - return gulp.src(`src/**/*.scss`).pipe(sass().on(`error`, sass.logError)).pipe(gulp.dest(`dist`)); -} - -const bundleModule = async () => { - const debug = argv.dbg || argv.debug; - const bsfy = browserify(path.join(__dirname, mainFilePath), { debug: debug }); - return bsfy - .on(`error`, console.error) - .plugin(tsify) - .bundle() - .pipe(source(path.join(`dist`, `bundle.js`))) - .pipe(buffer()) - .pipe(sourcemaps.init({loadMaps: true})) - .pipe(sourcemaps.write(`./`)) - .pipe(gulp.dest(`./`)); - - // await Promise.resolve(`bundleModule done`); -} - -const copyFiles = async() => { - const statics = [`lang`, `languages`, `fonts`, `assets`, `icons`, `templates`, `packs`, `module.json`, `system.json`, `template.json`]; - - const recursiveFileSearch = (dir, callback) => { - const err = callback.err; - const res = callback.res; - let results = []; - fs.readdir(dir, (err, list) => { - if (err) - return callback(err, results); - - let pending = list.length; - if (!pending) - return callback(null, results); - - for (let file of list) { - file = path.resolve(dir, file); - fs.stat(file, (err, stat) => { - if (stat && stat.isDirectory()) { - recursiveFileSearch(file, (err, res) => { - results = results.concat(res); - if (!--pending) - callback(null, results); - }); - } - else { - results.push(file); - if (!--pending) - callback(null, results); - } - }); - } - }); - }; - console.log(`files:` + statics); - try { - for (const entity of statics) { - - const p = path.join(`src`, entity); - /* MOD 4535992 - let p:string|null = null; - if (entity.endsWith(`module.json`) || entity.endsWith(`templates`) || entity.endsWith(`lang`)) { - p = path.join(`src`, entity); - } else { - p = path.join(`assets`, entity); - } - */ - if (fs.existsSync(p)) { - if (fs.lstatSync(p).isDirectory()) - recursiveFileSearch(p, (err, res) => { - if (err) - throw err; - - for (const file of res) { - const newFile = path.join(`dist`, path.relative(process.cwd(), file.replace(/src[\/\\]/g, ``))); - console.log(`Copying file: ` + newFile); - const folder = path.parse(newFile).dir; - if (!fs.existsSync(folder)) { - fs.mkdirSync(folder, { recursive: true }); - } - fs.copyFileSync(file, newFile); - } - }) - else { - console.log(`Copying file: ` + p + ` to ` + path.join(`dist`, entity)); - fs.copyFileSync(p, path.join(`dist`, entity)); - } - } - } - return Promise.resolve(); - } catch (err) { - await Promise.reject(err); - } -} - -const cleanDist = async () => { - if (argv.dbg || argv.debug){ - return; - } - console.log(`Cleaning dist file clutter`); - - const files = []; - const getFiles = async (dir) => { - const arr = await fs.promises.readdir(dir); - for(const entry of arr) - { - const fullPath = path.join(dir, entry); - const stat = await fs.promises.stat(fullPath); - if (stat.isDirectory()) - await getFiles(fullPath); - else - files.push(fullPath); - } - } - - await getFiles(path.resolve(`./dist`)); - for(const file of files) { - /* MOD 4535992 - if (file.endsWith(`bundle.js`) || - file.endsWith(`.css`) || - file.endsWith(`module.json`) || - file.endsWith(`templates`) || - file.endsWith(`lang`)|| - file.endsWith(`.json`) || - file.endsWith(`.html`)){ - continue; - } - */ - console.warn(`Cleaning ` + path.relative(process.cwd(), file)); - await fs.promises.unlink(file); - } -} - -/** - * Watch for changes for each build step - */ -const buildWatch = () => { - // gulp.watch(`src/**/*.ts`, { ignoreInitial: false }, gulp.series(buildTS, bundleModule)); - gulp.watch(`src/**/*.ts`, { ignoreInitial: false }, gulp.series(buildTS)); - gulp.watch(`src/**/*.less`, { ignoreInitial: false }, buildLess); - gulp.watch(`src/**/*.sass`, { ignoreInitial: false }, buildSASS); - gulp.watch([`src/fonts`, `src/lang`, `src/languages`, `src/templates`, `src/*.json`], { ignoreInitial: false }, copyFiles); -} - -/********************/ -/* CLEAN */ -/********************/ - -/** - * Remove built files from `dist` folder - * while ignoring source files - */ -const clean = async () => { - if (!fs.existsSync(`dist`)){ - fs.mkdirSync(`dist`); - } - - const name = path.basename(path.resolve(`.`)); - const files = []; - - // If the project uses TypeScript - // if (fs.existsSync(path.join(`src`, mainFilePath))) { // MOD 4535992 - files.push( - `lang`, - `languages`, - `fonts`, - `icons`, - `packs`, - `templates`, - `assets`, - `module`, - `index.js`, - `module.json`, - `system.json`, - `template.json` - ); - // } // MOD 4535992 - - // If the project uses Less - /* MOD 4535992 - // if (fs.existsSync(path.join(`src/styles/`, `${name}.less`))) { - // files.push(`fonts`, `${name}.css`); - // } - */ - // Attempt to remove the files - try { - for (const filePath of files) { - if (fs.existsSync(path.join(`dist`, filePath))){ - // fs.unlinkSync(path.join(`dist`, filePath)); // MOD 4535992 - fs.rmSync(path.join(`dist`, filePath), { recursive: true, force: true }); - } - } - return Promise.resolve(); - } catch (err) { - await Promise.reject(err); - } -} - -const linkUserData = async () => { - const name = getManifest()?.file.name; - const config = loadJson(`foundryconfig.json`); - - let destDir; - try { - if (fs.existsSync(path.resolve(`.`, `dist`, `module.json`)) || fs.existsSync(path.resolve(`.`, `src`, `module.json`))) { - destDir = `modules`; - } else { - throw Error(`Could not find module.json or system.json`); - } - - let linkDir; - if (config.dataPath) { - if (!fs.existsSync(path.join(config.dataPath, `Data`))) - throw Error(`User Data path invalid, no Data directory found`); - - linkDir = path.join(config.dataPath, `Data`, destDir, name); - } else { - throw Error(`No User Data path defined in foundryconfig.json`); - } - - if (argv.clean || argv.c) { - console.warn(`Removing build in ${linkDir}`); - - fs.unlinkSync(linkDir); - } else if (!fs.existsSync(linkDir)) { - console.log(`Copying build to ${linkDir}`); - fs.symlinkSync(path.resolve(`./dist`), linkDir); - } - return Promise.resolve(); - } catch (err) { - await Promise.reject(err); - } -} - -/*********************/ -/* PACKAGE */ -/*********************/ - -/** - * Package build - */ -async function packageBuild() { - const manifest = getManifest(); - if (manifest === null) - { - console.error(`Manifest file could not be loaded.`); - throw Error(); - } - - return new Promise((resolve, reject) => { - try { - // Remove the package dir without doing anything else - if (argv.clean || argv.c) { - console.warn(`Removing all packaged files`); - fs.rmSync(`package`, { force: true, recursive: true }); - return; - } - - // Ensure there is a directory to hold all the packaged versions - // fs.existsSync(`package`); - if (!fs.existsSync(`package`)) { - fs.mkdirSync(`package`, { recursive: true }); - } - - // Initialize the zip file - const zipName = `module.zip`; // `${manifest.file.name}-v${manifest.file.version}.zip`; // MOD 4535992 - const zipFile = fs.createWriteStream(path.join(`package`, zipName)); - //@ts-ignore - const zip = archiver(`zip`, { zlib: { level: 9 } }); - - zipFile.on(`close`, () => { - console.log(zip.pointer() + ` total bytes`); - console.log(`Zip file ${zipName} has been written`); - return resolve(true); - }); - - zip.on(`error`, (err) => { - throw err; - }); - - zip.pipe(zipFile); - - // Add the directory with the final code - // zip.directory(`dist/`, manifest.file.name); - const moduleJson = JSON.parse(fs.readFileSync('./src/module.json')); - zip.directory(`dist/`, moduleJson.id); - /* MOD 4535992 - zip.file(`dist/module.json`, { name: `module.json` }); - zip.file(`dist/bundle.js`, { name: `bundle.js` }); - zip.glob(`dist/*.css`, {cwd:__dirname}); - zip.directory(`dist/lang`, `lang`); - zip.directory(`dist/templates`, `templates`); - */ - console.log(`Zip files`); - - zip.finalize(); - return resolve(`done`); - } catch (err) { - return reject(err); - } - }); -} - -/*********************/ -/* PACKAGE */ -/*********************/ - -/** - * Update version and URLs in the manifest JSON - */ -const updateManifest = (cb) => { - const packageJson = loadJson(`package.json`); - const config = getConfig(), - manifest = getManifest(), - rawURL = config.rawURL, - repoURL = config.repository, - manifestRoot = manifest?.root; - - if (!config) { - cb(Error(`foundryconfig.json not found`)); - } - if (manifest === null) { - cb(Error(`Manifest JSON not found`)); - return; - } - if (!rawURL || !repoURL) { - cb(Error(`Repository URLs not configured in foundryconfig.json`)); - } - try { - const version = argv.update || argv.u; - - /* Update version */ - - const versionMatch = /^(\d{1,}).(\d{1,}).(\d{1,})$/; - const currentVersion = manifest?.file.version; - let targetVersion = ``; - - if (!version) { - cb(Error(`Missing version number`)); - } - - if (versionMatch.test(version)) { - targetVersion = version; - } else { - targetVersion = currentVersion.replace(versionMatch, (substring, major, minor, patch) => { - console.log(substring, Number(major) + 1, Number(minor) + 1, Number(patch) + 1); - if (version === `major`) { - return `${Number(major) + 1}.0.0`; - } else if (version === `minor`) { - return `${major}.${Number(minor) + 1}.0`; - } else if (version === `patch`) { - return `${major}.${minor}.${Number(patch) + 1}`; - } else { - return ``; - } - }); - } - - if (targetVersion === ``) { - return cb(Error(`Error: Incorrect version arguments.`)); - } - - if (targetVersion === currentVersion) { - return cb(Error(`Error: Target version is identical to current version.`)); - } - - console.log(`Updating version number to "${targetVersion}"`); - - packageJson.version = targetVersion; - manifest.file.version = targetVersion; - - /* Update URLs */ - - const result = `${repoURL}/releases/download/${manifest.file.version}/module.zip`; - - manifest.file.url = repoURL; - manifest.file.manifest = `${rawURL}/${manifest.file.version}/${manifestRoot}/${manifest.name}`; - manifest.file.download = result; - - const prettyProjectJson = stringify(manifest.file, { - maxLength: 35, - indent: `\t`, - }); - - fs.writeFileSync(`package.json`, JSON.stringify(packageJson, null, `\t`)); - fs.writeFileSync(path.join(manifest.root, manifest.name), prettyProjectJson, `utf8`); - - return cb(); - } catch (err) { - cb(err); - } -} -const test = () => { - return gulp.src(`src/__tests__`).pipe(jest({ - "preprocessorIgnorePatterns": [ - `dist/`, `node_modules/` - ], - "automock": false - })); -} - - -// const execBuild = gulp.parallel(buildTS, buildLess, copyFiles); // MOD 4535992 -const execBuild = gulp.parallel(buildTS, buildJS, buildMJS, buildCSS, buildLess, buildSASS, copyFiles); - -exports.build = gulp.series(clean, execBuild); -exports.bundle = gulp.series(clean, execBuild, bundleModule, cleanDist); -exports.watch = buildWatch; -exports.clean = clean; -exports.link = linkUserData; -exports.package = packageBuild; -exports.update = updateManifest; -exports.publish = gulp.series(clean, updateManifest, execBuild, bundleModule, cleanDist, packageBuild); diff --git a/package_gulp.json b/package_gulp.json deleted file mode 100644 index a94a991..0000000 --- a/package_gulp.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "foundryvtt-arms-reach", - "title": "FoundryVTT Arms Reach", - "description": "Allows the GM to limit the distance that a player can interacted with a placeable object like door, journal, stairway, token, ecc..", - "version": "2.2.14", - "main": "foundryvtt-arms-reach.js", - "scripts": { - "publish": "gulp publish --update", - "package": "gulp package", - "build": "gulp build --dbg", - "build:link": "gulp build --dbg && gulp link", - "build:test": "gulp build --dbg && gulp link && npm test", - "build:prod": "gulp bundle && npm test", - "build:watch": "gulp watch", - "clean": "gulp clean && gulp link --clean", - "test": "jest", - "update": "npm install --save-dev @league-of-foundry-developers/foundry-vtt-types@9", - "prettier-format": "prettier --config .prettierrc.js --write \"./src/**/*.{ts,js,json,scss,css}\"" - }, - "keywords": [ - "foundryvtt", - "fvtt", - "module" - ], - "author": "", - "license": "SEE LICENSE IN LICENSE", - "devDependencies": { - "@babel/core": "^7.15.0", - "@babel/eslint-parser": "^7.15.4", - "@league-of-foundry-developers/foundry-vtt-types": "^9.280.0", - "@rollup/plugin-node-resolve": "^13.3.0", - "@types/archiver": "^5.1.1", - "@types/browserify": "^12.0.37", - "@types/color": "^3.0.2", - "@types/gulp": "^4.0.9", - "@types/gulp-less": "^0.0.32", - "@types/jest": "^27.4.0", - "@types/jquery": "^3.5.14", - "@types/yargs": "^17.0.2", - "@typescript-eslint/eslint-plugin": "^4.33.0", - "@typescript-eslint/parser": "^4.33.0", - "@typhonjs-fvtt/eslint-config-foundry.js": "^0.8.0", - "archiver": "^5.3.0", - "babelify": "^10.0.0", - "browserify": "^17.0.0", - "color": "3.2.1", - "eslint": "^7.32.0", - "eslint-plugin-jsdoc": "^39.3.3", - "fancy-log": "^2.0.0", - "fs": "^0.0.1-security", - "gulp": "^4.0.0", - "gulp-bro": "^2.0.0", - "gulp-changed": "^4.0.3", - "gulp-eslint-new": "^1.5.1", - "gulp-eslint7": "^0.3.1", - "gulp-git": "^2.10.1", - "gulp-if": "^3.0.0", - "gulp-less": "^5.0.0", - "gulp-rename": "^2.0.0", - "gulp-replace": "^1.1.3", - "gulp-sass": "^5.1.0", - "gulp-sourcemaps": "^3.0.0", - "gulp-typescript": "^6.0.0-alpha.1", - "gulp-uglify": "^3.0.2", - "merge-stream": "^2.0.0", - "nedb": "^1.8.0", - "path": "^0.12.7", - "rollup": "^2.77.0", - "jest": "^27.5.1", - "json-stringify-pretty-compact": "^3.0.0", - "sass": "^1.49.11", - "through2": "^4.0.2", - "ts-jest": "^27.1.3", - "ts-node": "^10.2.1", - "typescript": "^4.4.2", - "uglifyify": "^5.0.2", - "vinyl-buffer": "^1.0.1", - "vinyl-source-stream": "^2.0.0", - "yargs": "^17.1.1" - }, - "dependencies": { - "build": "^0.1.4", - "csv-parse": "^4.16.3", - "gulp-jest": "^4.0.4", - "node-sass": "^7.0.1", - "prettier": "^2.7.1", - "prettier-format": "^3.1.0", - "tsify": "^5.0.4", - "typescript": "^4.6.3" - } -} diff --git a/src/module.json b/src/module.json index e419e18..52eb837 100644 --- a/src/module.json +++ b/src/module.json @@ -2,7 +2,7 @@ "id": "arms-reach", "title": "Arms Reach", "description": "Allows the GM to limit the distance that a player can interacted with a placeable object like door, journal, stairway, token, ecc..", - "version": "2.3.5", + "version": "2.3.6", "authors": [ { "name": "Psyny" @@ -91,8 +91,8 @@ }, "manifestPlusVersion": "1.2.1", "url": "https://github.com/p4535992/foundryvtt-arms-reach", - "manifest": "https://github.com/p4535992/foundryvtt-arms-reach/releases/download/2.3.5/module.json", - "download": "https://github.com/p4535992/foundryvtt-arms-reach/releases/download/2.3.5/module.zip", + "manifest": "https://github.com/p4535992/foundryvtt-arms-reach/releases/download/2.3.6/module.json", + "download": "https://github.com/p4535992/foundryvtt-arms-reach/releases/download/2.3.6/module.zip", "readme": "https://github.com/p4535992/foundryvtt-arms-reach/blob/main/README.md", "changelog": "https://github.com/p4535992/foundryvtt-arms-reach/blob/main/changelog.md", "bugs": "https://github.com/p4535992/foundryvtt-arms-reach/issues",