Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
fingerprint files & drop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mawburn committed Aug 1, 2021
1 parent ec4a761 commit 5fae980
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 2,932 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
node_modules
.DS_Store
yarn-error.log
package.zip
module.zip
dist
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Raw json file for importing into FoundryVTT:

https://raw.githubusercontent.com/mawburn/foundry-ping-logger/main/src/module.json

## Scripts

- clean - removes dist and package.zip folder
- build - runs clean & bumps package version & gulp build & updates manifest file
- _Note:_ versions in the manifest file are based on the version in package.json
- package - runs gulp build & outputs a module.zip file
- nuke - runs clean & removes node_modules
- lint- runs lint --fix on all files

## Fork - Response Times

- https://foundryvtt.com/packages/response-time
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

97 changes: 37 additions & 60 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
const archiver = require('archiver')
const typescript = require('typescript')
const ts = require('gulp-typescript')
const rollup = require('rollup')
const rollupTypescript = require('@rollup/plugin-typescript')
const { terser } = require('rollup-plugin-terser')
const { customAlphabet, urlAlphabet } = require('nanoid')

const PACKAGE_JSON_ROOT = path.join(__dirname, 'package.json')
const CONFIG_ROOT = path.join(__dirname, 'foundryconfig.json')
Expand All @@ -14,76 +16,49 @@ const packageJson = require(PACKAGE_JSON_ROOT)
const config = require(CONFIG_ROOT)
const manifest = require(MANIFEST_ROOT)

function createTransformer() {
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
}

function importTransformer(context) {
return 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()],
}),
})

const buildTS = () => gulp.src('src/**/*.ts').pipe(tsConfig()).pipe(gulp.dest('dist'))
const rand = () => Math.floor(Math.random() * (14 - 7 + 1) + 7)
const nanoid = customAlphabet(urlAlphabet, rand())
const id = nanoid().replace(/-_/gi, '7')
const packageId = `logger-${id}.js`
const cssId = `logger-${id}.css`

async function copyFiles() {
const statics = ['module.json', 'ping-logger.css']
const cssFile = path.join('src', 'ping-logger.css')

try {
for (const file of statics) {
if (fs.existsSync(path.join('src', file))) {
await fs.copy(path.join('src', file), path.join('dist', file))
}
if (fs.existsSync(MANIFEST_ROOT)) {
await fs.copy(MANIFEST_ROOT, path.join('dist', 'module.json'))
}

if (fs.existsSync(cssFile)) {
await fs.copy(cssFile, path.join('dist', cssId))
}

return Promise.resolve()
} catch (err) {
Promise.reject(err)
}
}

const bundler = () =>
rollup
.rollup({
input: './src/ping-logger.ts',
plugins: [rollupTypescript(), terser()],
})
.then(bundle =>
bundle.write({
file: `./dist/${packageId}`,
format: 'umd',
name: 'library',
sourcemap: true,
})
)

const packageBuild = async () =>
new Promise((resolve, reject) => {
try {
const zipFile = fs.createWriteStream(path.join(__dirname, 'package.zip'))
const zipFile = fs.createWriteStream(path.join(__dirname, 'module.zip'))
const zip = archiver('zip', { zlib: { level: 9 } })

zipFile.on('close', () => {
Expand Down Expand Up @@ -116,10 +91,12 @@ const updateManifest = cb => {
return
}

manifest.esmodules = [packageId]
manifest.styles = [cssId]
manifest.version = packageJson.version
manifest.url = config.url
manifest.manifest = config.manifest
manifest.download = `${config.downloadURL}/v${packageJson.version}/package.zip`
manifest.download = `${config.downloadURL}/v${packageJson.version}/module.zip`
manifest.readme = config.readme
manifest.bugs = config.bugs
manifest.changelog = config.changelog
Expand All @@ -135,5 +112,5 @@ const updateManifest = cb => {
}
}

exports.build = gulp.series(updateManifest, buildTS, copyFiles)
exports.build = gulp.series(updateManifest, bundler, copyFiles)
exports.package = packageBuild
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"private": true,
"name": "ping-logger",
"version": "1.0.2",
"version": "1.1.0",
"description": "Display average ping in user list.",
"scripts": {
"clean": "rimraf dist package.zip",
"prebuild": "yarn clean && yarn version --patch",
"clean": "rimraf dist module.zip",
"prebuild": "yarn clean && yarn version --patch --no-git-tag-version",
"build": "gulp build",
"prepackage": "yarn build",
"package": "gulp package",
Expand All @@ -32,8 +32,8 @@
"prettier-eslint": "^13.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.55.1",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.3.5",
"webpack-stream": "^6.1.2",
"yargs": "^15.3.1"
}
}
}
10 changes: 5 additions & 5 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ping-logger",
"title": "Ping Logger",
"description": "Display average ping in user list.",
"version": "1.0.1",
"version": "1.1.0",
"author": "hypnoCode",
"authors": [
{
Expand All @@ -13,15 +13,15 @@
{
"name": "tenuki",
"email": "",
"url": "https://gitlab.com/tenuki.igo/foundryvtt-ping-times"
"url": "https:/gitlab.com/tenuki.igo/foundryvtt-ping-times"
}
],
"scripts": [],
"esmodules": [
"ping-logger.js"
"logger-ezlylMh6SAh4V8.js"
],
"styles": [
"ping-logger.css"
"logger-ezlylMh6SAh4V8.css"
],
"packs": [],
"languages": [],
Expand All @@ -30,7 +30,7 @@
"compatibleCoreVersion": "0.8.8",
"url": "https://github.com/mawburn/foundry-ping-logger",
"manifest": "https://raw.githubusercontent.com/mawburn/foundry-ping-logger/main/src/module.json",
"download": "https://github.com/mawburn/foundry-ping-logger/releases/download/v1.0.1/package.zip",
"download": "https://github.com/mawburn/foundry-ping-logger/releases/download/v1.1.0/module.zip",
"license": "GNU AGPLv3",
"readme": "https://github.com/mawburn/foundry-ping-logger/blob/main/README.md",
"bugs": "https://github.com/mawburn/foundry-ping-logger/issues",
Expand Down
3 changes: 3 additions & 0 deletions src/module/PlayerList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export class PlayerList {
registerListeners = () => {
if ((game as Game).socket) {
;(game as Game).socket?.on(`module.${MODULE_NAME}`, (data: Pong) => {
console.log('--->', data)
this.playerPingTimes[data.userId] = {
userName: data.userName,
ping: data.average,
}

console.log('x')

this.updatePingText(data.userId)
})
} else {
Expand Down
29 changes: 0 additions & 29 deletions src/tests/PlayerList.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"target": "ES2020",
"strict": true,
"noImplicitAny": false,
"types": ["@league-of-foundry-developers/foundry-vtt-types", "jest"]
"types": ["@league-of-foundry-developers/foundry-vtt-types"]
},
"exclude": ["node_modules/*"]
}
Loading

0 comments on commit 5fae980

Please sign in to comment.