-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b5ffa2
Showing
20 changed files
with
6,677 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
|
||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
|
||
env: { | ||
browser: true, | ||
}, | ||
|
||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], | ||
|
||
plugins: ['@typescript-eslint'], | ||
|
||
rules: { | ||
// Specify any specific ESLint rules. | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
files: ['./*.js'], | ||
rules: { | ||
'@typescript-eslint/no-var-requires': 'off', | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# IDE | ||
.idea/ | ||
.vs/ | ||
|
||
# Node Modules | ||
node_modules/ | ||
npm-debug.log | ||
|
||
# yarn2 | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/releases | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.pnp.* | ||
|
||
# Local configuration | ||
foundryconfig.json | ||
|
||
# Distribution files | ||
dist | ||
|
||
# ESLint | ||
.eslintcache | ||
|
||
# Junit results | ||
junit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# gurps-easy-combat | ||
|
||
Add your description here. | ||
|
||
## Installation | ||
|
||
Add your installation instructions here. | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
In order to build this module, recent versions of `node` and `npm` are | ||
required. Most likely using `yarn` also works but only `npm` is officially | ||
supported. We recommend using the latest lts version of `node`, which is | ||
`v14.15.5` at the time of writing. If you use `nvm` to manage your `node` | ||
versions, you can simply run | ||
|
||
``` | ||
nvm install | ||
``` | ||
|
||
in the project's root directory. | ||
|
||
You also need to install the the project's dependencies. To do so, run | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
### Building | ||
|
||
You can build the project by running | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
Alternatively, you can run | ||
|
||
``` | ||
npm run build:watch | ||
``` | ||
|
||
to watch for changes and automatically build as necessary. | ||
|
||
### Linking the built project to Foundry VTT | ||
|
||
In order to provide a fluent development experience, it is recommended to link | ||
the built module to your local Foundry VTT installation's data folder. In | ||
order to do so, first add a file called `foundryconfig.json` to the project root | ||
with the following content: | ||
|
||
``` | ||
{ | ||
"dataPath": "/absolute/path/to/your/FoundryVTT/Data" | ||
} | ||
``` | ||
|
||
(if you are using Windows, make sure to use `\` as a path separator instead of | ||
`/`) | ||
|
||
Then run | ||
|
||
``` | ||
npm run link-project | ||
``` | ||
|
||
On Windows, creating symlinks requires administrator privileges so unfortunately | ||
you need to run the above command in an administrator terminal for it to work. | ||
|
||
### Running the tests | ||
|
||
You can run the tests with the following command: | ||
|
||
``` | ||
npm test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
const { rollup } = require('rollup'); | ||
const argv = require('yargs').argv; | ||
const chalk = require('chalk'); | ||
const fs = require('fs-extra'); | ||
const gulp = require('gulp'); | ||
const path = require('path'); | ||
const rollupConfig = require('./rollup.config'); | ||
const semver = require('semver'); | ||
|
||
/********************/ | ||
/* CONFIGURATION */ | ||
/********************/ | ||
|
||
const name = path.basename(path.resolve('.')); | ||
const sourceDirectory = './src'; | ||
const distDirectory = './dist'; | ||
const stylesDirectory = `${sourceDirectory}/styles`; | ||
const stylesExtension = 'css'; | ||
const sourceFileExtension = 'ts'; | ||
const staticFiles = ['assets', 'fonts', 'lang', 'packs', 'templates', 'module.json']; | ||
const getDownloadURL = (version) => `https://host/path/to/${version}.zip`; | ||
|
||
/********************/ | ||
/* BUILD */ | ||
/********************/ | ||
|
||
/** | ||
* Build the distributable JavaScript code | ||
*/ | ||
async function buildCode() { | ||
const build = await rollup({ input: rollupConfig.input, plugins: rollupConfig.plugins }); | ||
return build.write(rollupConfig.output); | ||
} | ||
|
||
/** | ||
* Build style sheets | ||
*/ | ||
function buildStyles() { | ||
return gulp.src(`${stylesDirectory}/${name}.${stylesExtension}`).pipe(gulp.dest(`${distDirectory}/styles`)); | ||
} | ||
|
||
/** | ||
* Copy static files | ||
*/ | ||
async function copyFiles() { | ||
for (const file of staticFiles) { | ||
if (fs.existsSync(`${sourceDirectory}/${file}`)) { | ||
await fs.copy(`${sourceDirectory}/${file}`, `${distDirectory}/${file}`); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Watch for changes for each build step | ||
*/ | ||
function buildWatch() { | ||
gulp.watch(`${sourceDirectory}/**/*.${sourceFileExtension}`, { ignoreInitial: false }, buildCode); | ||
gulp.watch(`${stylesDirectory}/**/*.${stylesExtension}`, { ignoreInitial: false }, buildStyles); | ||
gulp.watch( | ||
staticFiles.map((file) => `${sourceDirectory}/${file}`), | ||
{ ignoreInitial: false }, | ||
copyFiles, | ||
); | ||
} | ||
|
||
/********************/ | ||
/* CLEAN */ | ||
/********************/ | ||
|
||
/** | ||
* Remove built files from `dist` folder while ignoring source files | ||
*/ | ||
async function clean() { | ||
const files = [...staticFiles, 'module']; | ||
|
||
if (fs.existsSync(`${stylesDirectory}/${name}.${stylesExtension}`)) { | ||
files.push('styles'); | ||
} | ||
|
||
console.log(' ', chalk.yellow('Files to clean:')); | ||
console.log(' ', chalk.blueBright(files.join('\n '))); | ||
|
||
for (const filePath of files) { | ||
await fs.remove(`${distDirectory}/${filePath}`); | ||
} | ||
} | ||
|
||
/********************/ | ||
/* LINK */ | ||
/********************/ | ||
|
||
/** | ||
* Get the data path of Foundry VTT based on what is configured in `foundryconfig.json` | ||
*/ | ||
function getDataPath() { | ||
const config = fs.readJSONSync('foundryconfig.json'); | ||
|
||
if (config?.dataPath) { | ||
if (!fs.existsSync(path.resolve(config.dataPath))) { | ||
throw new Error('User Data path invalid, no Data directory found'); | ||
} | ||
|
||
return path.resolve(config.dataPath); | ||
} else { | ||
throw new Error('No User Data path defined in foundryconfig.json'); | ||
} | ||
} | ||
|
||
/** | ||
* Link build to User Data folder | ||
*/ | ||
async function linkUserData() { | ||
let destinationDirectory; | ||
if (fs.existsSync(path.resolve(sourceDirectory, 'module.json'))) { | ||
destinationDirectory = 'modules'; | ||
} else { | ||
throw new Error(`Could not find ${chalk.blueBright('module.json')}`); | ||
} | ||
|
||
const linkDirectory = path.resolve(getDataPath(), destinationDirectory, name); | ||
|
||
if (argv.clean || argv.c) { | ||
console.log(chalk.yellow(`Removing build in ${chalk.blueBright(linkDirectory)}.`)); | ||
|
||
await fs.remove(linkDirectory); | ||
} else if (!fs.existsSync(linkDirectory)) { | ||
console.log(chalk.green(`Linking dist to ${chalk.blueBright(linkDirectory)}.`)); | ||
await fs.ensureDir(path.resolve(linkDirectory, '..')); | ||
await fs.symlink(path.resolve(distDirectory), linkDirectory); | ||
} | ||
} | ||
|
||
/********************/ | ||
/* VERSIONING */ | ||
/********************/ | ||
|
||
/** | ||
* Get the contents of the manifest file as object. | ||
*/ | ||
function getManifest() { | ||
const manifestPath = `${sourceDirectory}/module.json`; | ||
|
||
if (fs.existsSync(manifestPath)) { | ||
return { | ||
file: fs.readJSONSync(manifestPath), | ||
name: 'module.json', | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Get the target version based on on the current version and the argument passed as release. | ||
*/ | ||
function getTargetVersion(currentVersion, release) { | ||
if (['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].includes(release)) { | ||
return semver.inc(currentVersion, release); | ||
} else { | ||
return semver.valid(release); | ||
} | ||
} | ||
|
||
/** | ||
* Update version and download URL. | ||
*/ | ||
function bumpVersion(cb) { | ||
const packageJson = fs.readJSONSync('package.json'); | ||
const packageLockJson = fs.existsSync('package-lock.json') ? fs.readJSONSync('package-lock.json') : undefined; | ||
const manifest = getManifest(); | ||
|
||
if (!manifest) cb(Error(chalk.red('Manifest JSON not found'))); | ||
|
||
try { | ||
const release = argv.release || argv.r; | ||
|
||
const currentVersion = packageJson.version; | ||
|
||
if (!release) { | ||
return cb(Error('Missing release type')); | ||
} | ||
|
||
const targetVersion = getTargetVersion(currentVersion, release); | ||
|
||
if (!targetVersion) { | ||
return cb(new Error(chalk.red('Error: Incorrect version arguments'))); | ||
} | ||
|
||
if (targetVersion === currentVersion) { | ||
return cb(new Error(chalk.red('Error: Target version is identical to current version'))); | ||
} | ||
|
||
console.log(`Updating version number to '${targetVersion}'`); | ||
|
||
packageJson.version = targetVersion; | ||
fs.writeJSONSync('package.json', packageJson, { spaces: 2 }); | ||
|
||
if (packageLockJson) { | ||
packageLockJson.version = targetVersion; | ||
fs.writeJSONSync('package-lock.json', packageLockJson, { spaces: 2 }); | ||
} | ||
|
||
manifest.file.version = targetVersion; | ||
manifest.file.download = getDownloadURL(targetVersion); | ||
fs.writeJSONSync(`${sourceDirectory}/${manifest.name}`, manifest.file, { spaces: 2 }); | ||
|
||
return cb(); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
} | ||
|
||
const execBuild = gulp.parallel(buildCode, buildStyles, copyFiles); | ||
|
||
exports.build = gulp.series(clean, execBuild); | ||
exports.watch = buildWatch; | ||
exports.clean = clean; | ||
exports.link = linkUserData; | ||
exports.bumpVersion = bumpVersion; |
Oops, something went wrong.