format files

This commit is contained in:
Johannes Loher 2020-12-23 17:09:02 +01:00
parent bd4c5308bf
commit 4f6a9b7e73
18 changed files with 541 additions and 622 deletions

View file

@ -1,22 +1,22 @@
const gulp = require('gulp');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const archiver = require('archiver');
const stringify = require('json-stringify-pretty-compact');
const typescript = require('typescript');
const gulp = require("gulp");
const fs = require("fs-extra");
const path = require("path");
const chalk = require("chalk");
const archiver = require("archiver");
const stringify = require("json-stringify-pretty-compact");
const typescript = require("typescript");
const ts = require('gulp-typescript');
const less = require('gulp-less');
const sass = require('gulp-sass');
const git = require('gulp-git');
const ts = require("gulp-typescript");
const less = require("gulp-less");
const sass = require("gulp-sass");
const git = require("gulp-git");
const argv = require('yargs').argv;
const argv = require("yargs").argv;
sass.compiler = require('sass');
sass.compiler = require("sass");
function getConfig() {
const configPath = path.resolve(process.cwd(), 'foundryconfig.json');
const configPath = path.resolve(process.cwd(), "foundryconfig.json");
let config;
if (fs.existsSync(configPath)) {
@ -30,21 +30,21 @@ function getConfig() {
function getManifest() {
const json = {};
if (fs.existsSync('src')) {
json.root = 'src';
if (fs.existsSync("src")) {
json.root = "src";
} else {
json.root = 'dist';
json.root = "dist";
}
const modulePath = path.join(json.root, 'module.json');
const systemPath = path.join(json.root, 'system.json');
const modulePath = path.join(json.root, "module.json");
const systemPath = path.join(json.root, "system.json");
if (fs.existsSync(modulePath)) {
json.file = fs.readJSONSync(modulePath);
json.name = 'module.json';
json.name = "module.json";
} else if (fs.existsSync(systemPath)) {
json.file = fs.readJSONSync(systemPath);
json.name = 'system.json';
json.name = "system.json";
} else {
return;
}
@ -61,19 +61,11 @@ function createTransformer() {
* @param {typescript.Node} node
*/
function shouldMutateModuleSpecifier(node) {
if (
!typescript.isImportDeclaration(node) &&
!typescript.isExportDeclaration(node)
)
return false;
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;
if (!node.moduleSpecifier.text.startsWith("./") && !node.moduleSpecifier.text.startsWith("../")) return false;
if (path.extname(node.moduleSpecifier.text) !== "") return false;
return true;
}
@ -89,9 +81,7 @@ function createTransformer() {
function visitor(node) {
if (shouldMutateModuleSpecifier(node)) {
if (typescript.isImportDeclaration(node)) {
const newModuleSpecifier = typescript.createLiteral(
`${node.moduleSpecifier.text}.js`
);
const newModuleSpecifier = typescript.createLiteral(`${node.moduleSpecifier.text}.js`);
return typescript.updateImportDeclaration(
node,
node.decorators,
@ -100,9 +90,7 @@ function createTransformer() {
newModuleSpecifier
);
} else if (typescript.isExportDeclaration(node)) {
const newModuleSpecifier = typescript.createLiteral(
`${node.moduleSpecifier.text}.js`
);
const newModuleSpecifier = typescript.createLiteral(`${node.moduleSpecifier.text}.js`);
return typescript.updateExportDeclaration(
node,
node.decorators,
@ -122,7 +110,7 @@ function createTransformer() {
return importTransformer;
}
const tsConfig = ts.createProject('tsconfig.json', {
const tsConfig = ts.createProject("tsconfig.json", {
getCustomTransformers: (_program) => ({
after: [createTransformer()],
}),
@ -136,43 +124,32 @@ const tsConfig = ts.createProject('tsconfig.json', {
* Build TypeScript
*/
function buildTS() {
return gulp.src('src/**/*.ts').pipe(tsConfig()).pipe(gulp.dest('dist'));
return gulp.src("src/**/*.ts").pipe(tsConfig()).pipe(gulp.dest("dist"));
}
/**
* Build Less
*/
function buildLess() {
return gulp.src('src/*.less').pipe(less()).pipe(gulp.dest('dist'));
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'));
return gulp.src("src/*.scss").pipe(sass().on("error", sass.logError)).pipe(gulp.dest("dist"));
}
/**
* Copy static files
*/
async function copyFiles() {
const statics = [
'lang',
'fonts',
'assets',
'templates',
'module.json',
'system.json',
'template.json',
];
const statics = ["lang", "fonts", "assets", "templates", "module.json", "system.json", "template.json"];
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(path.join("src", file))) {
await fs.copy(path.join("src", file), path.join("dist", file));
}
}
return Promise.resolve();
@ -185,14 +162,10 @@ async function copyFiles() {
* Watch for changes for each build step
*/
function buildWatch() {
gulp.watch('src/**/*.ts', { ignoreInitial: false }, buildTS);
gulp.watch('src/**/*.less', { ignoreInitial: false }, buildLess);
gulp.watch('src/**/*.scss', { ignoreInitial: false }, buildSASS);
gulp.watch(
['src/fonts', 'src/lang', 'src/templates', 'src/*.json'],
{ ignoreInitial: false },
copyFiles
);
gulp.watch("src/**/*.ts", { ignoreInitial: false }, buildTS);
gulp.watch("src/**/*.less", { ignoreInitial: false }, buildLess);
gulp.watch("src/**/*.scss", { ignoreInitial: false }, buildSASS);
gulp.watch(["src/fonts", "src/lang", "src/templates", "src/*.json"], { ignoreInitial: false }, copyFiles);
}
/********************/
@ -204,38 +177,35 @@ function buildWatch() {
* while ignoring source files
*/
async function clean() {
const name = path.basename(path.resolve('.'));
const name = path.basename(path.resolve("."));
const files = [];
// If the project uses TypeScript
if (fs.existsSync(path.join('src', `${name}.ts`))) {
if (fs.existsSync(path.join("src", `${name}.ts`))) {
files.push(
'lang',
'templates',
'assets',
'module',
"lang",
"templates",
"assets",
"module",
`${name}.js`,
'module.json',
'system.json',
'template.json'
"module.json",
"system.json",
"template.json"
);
}
// If the project uses Less or SASS
if (
fs.existsSync(path.join('src', `${name}.less`)) ||
fs.existsSync(path.join('src', `${name}.scss`))
) {
files.push('fonts', `${name}.css`);
if (fs.existsSync(path.join("src", `${name}.less`)) || fs.existsSync(path.join("src", `${name}.scss`))) {
files.push("fonts", `${name}.css`);
}
console.log(' ', chalk.yellow('Files to clean:'));
console.log(' ', chalk.blueBright(files.join('\n ')));
console.log(" ", chalk.yellow("Files to clean:"));
console.log(" ", chalk.blueBright(files.join("\n ")));
// Attempt to remove the files
try {
for (const filePath of files) {
await fs.remove(path.join('dist', filePath));
await fs.remove(path.join("dist", filePath));
}
return Promise.resolve();
} catch (err) {
@ -251,50 +221,42 @@ async function clean() {
* Link build to User Data folder
*/
async function linkUserData() {
const name = path.basename(path.resolve('.'));
const config = fs.readJSONSync('foundryconfig.json');
const name = path.basename(path.resolve("."));
const config = fs.readJSONSync("foundryconfig.json");
let destDir;
try {
if (
fs.existsSync(path.resolve('.', 'dist', 'module.json')) ||
fs.existsSync(path.resolve('.', 'src', 'module.json'))
fs.existsSync(path.resolve(".", "dist", "module.json")) ||
fs.existsSync(path.resolve(".", "src", "module.json"))
) {
destDir = 'modules';
destDir = "modules";
} else if (
fs.existsSync(path.resolve('.', 'dist', 'system.json')) ||
fs.existsSync(path.resolve('.', 'src', 'system.json'))
fs.existsSync(path.resolve(".", "dist", "system.json")) ||
fs.existsSync(path.resolve(".", "src", "system.json"))
) {
destDir = 'systems';
destDir = "systems";
} else {
throw Error(
`Could not find ${chalk.blueBright(
'module.json'
)} or ${chalk.blueBright('system.json')}`
);
throw Error(`Could not find ${chalk.blueBright("module.json")} or ${chalk.blueBright("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');
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);
linkDir = path.join(config.dataPath, "Data", destDir, name);
} else {
throw Error('No User Data path defined in foundryconfig.json');
throw Error("No User Data path defined in foundryconfig.json");
}
if (argv.clean || argv.c) {
console.log(
chalk.yellow(`Removing build in ${chalk.blueBright(linkDir)}`)
);
console.log(chalk.yellow(`Removing build in ${chalk.blueBright(linkDir)}`));
await fs.remove(linkDir);
} else if (!fs.existsSync(linkDir)) {
console.log(
chalk.green(`Copying build to ${chalk.blueBright(linkDir)}`)
);
await fs.symlink(path.resolve('./dist'), linkDir);
console.log(chalk.green(`Copying build to ${chalk.blueBright(linkDir)}`));
await fs.symlink(path.resolve("./dist"), linkDir);
}
return Promise.resolve();
} catch (err) {
@ -316,35 +278,33 @@ async function packageBuild() {
try {
// Remove the package dir without doing anything else
if (argv.clean || argv.c) {
console.log(chalk.yellow('Removing all packaged files'));
fs.removeSync('package');
console.log(chalk.yellow("Removing all packaged files"));
fs.removeSync("package");
return;
}
// Ensure there is a directory to hold all the packaged versions
fs.ensureDirSync('package');
fs.ensureDirSync("package");
// Initialize the zip file
const zipName = `${manifest.file.name}-v${manifest.file.version}.zip`;
const zipFile = fs.createWriteStream(path.join('package', zipName));
const zip = archiver('zip', { zlib: { level: 9 } });
const zipFile = fs.createWriteStream(path.join("package", zipName));
const zip = archiver("zip", { zlib: { level: 9 } });
zipFile.on('close', () => {
console.log(chalk.green(zip.pointer() + ' total bytes'));
console.log(
chalk.green(`Zip file ${zipName} has been written`)
);
zipFile.on("close", () => {
console.log(chalk.green(zip.pointer() + " total bytes"));
console.log(chalk.green(`Zip file ${zipName} has been written`));
return resolve();
});
zip.on('error', (err) => {
zip.on("error", (err) => {
throw err;
});
zip.pipe(zipFile);
// Add the directory with the final code
zip.directory('dist/', manifest.file.name);
zip.directory("dist/", manifest.file.name);
zip.finalize();
} catch (err) {
@ -361,23 +321,16 @@ async function packageBuild() {
* Update version and URLs in the manifest JSON
*/
function updateManifest(cb) {
const packageJson = fs.readJSONSync('package.json');
const packageJson = fs.readJSONSync("package.json");
const config = getConfig(),
manifest = getManifest(),
rawURL = config.rawURL,
repoURL = config.repository,
manifestRoot = manifest.root;
if (!config) cb(Error(chalk.red('foundryconfig.json not found')));
if (!manifest) cb(Error(chalk.red('Manifest JSON not found')));
if (!rawURL || !repoURL)
cb(
Error(
chalk.red(
'Repository URLs not configured in foundryconfig.json'
)
)
);
if (!config) cb(Error(chalk.red("foundryconfig.json not found")));
if (!manifest) cb(Error(chalk.red("Manifest JSON not found")));
if (!rawURL || !repoURL) cb(Error(chalk.red("Repository URLs not configured in foundryconfig.json")));
try {
const version = argv.update || argv.u;
@ -386,49 +339,35 @@ function updateManifest(cb) {
const versionMatch = /^(\d{1,}).(\d{1,}).(\d{1,})$/;
const currentVersion = manifest.file.version;
let targetVersion = '';
let targetVersion = "";
if (!version) {
cb(Error('Missing version number'));
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') {
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') {
} else if (version === "minor") {
return `${major}.${Number(minor) + 1}.0`;
} else if (version === 'patch') {
} else if (version === "patch") {
return `${major}.${minor}.${Number(patch) + 1}`;
} else {
return '';
return "";
}
}
);
});
}
if (targetVersion === '') {
return cb(Error(chalk.red('Error: Incorrect version arguments.')));
if (targetVersion === "") {
return cb(Error(chalk.red("Error: Incorrect version arguments.")));
}
if (targetVersion === currentVersion) {
return cb(
Error(
chalk.red(
'Error: Target version is identical to current version.'
)
)
);
return cb(Error(chalk.red("Error: Target version is identical to current version.")));
}
console.log(`Updating version number to '${targetVersion}'`);
@ -445,15 +384,11 @@ function updateManifest(cb) {
const prettyProjectJson = stringify(manifest.file, {
maxLength: 35,
indent: '\t',
indent: "\t",
});
fs.writeJSONSync('package.json', packageJson, { spaces: '\t' });
fs.writeFileSync(
path.join(manifest.root, manifest.name),
prettyProjectJson,
'utf8'
);
fs.writeJSONSync("package.json", packageJson, { spaces: "\t" });
fs.writeFileSync(path.join(manifest.root, manifest.name), prettyProjectJson, "utf8");
return cb();
} catch (err) {
@ -462,13 +397,13 @@ function updateManifest(cb) {
}
function gitAdd() {
return gulp.src('package').pipe(git.add({ args: '--no-all' }));
return gulp.src("package").pipe(git.add({ args: "--no-all" }));
}
function gitCommit() {
return gulp.src('./*').pipe(
return gulp.src("./*").pipe(
git.commit(`v${getManifest().file.version}`, {
args: '-a',
args: "-a",
disableAppendPaths: true,
})
);
@ -476,13 +411,9 @@ function gitCommit() {
function gitTag() {
const manifest = getManifest();
return git.tag(
`v${manifest.file.version}`,
`Updated to ${manifest.file.version}`,
(err) => {
return git.tag(`v${manifest.file.version}`, `Updated to ${manifest.file.version}`, (err) => {
if (err) throw err;
}
);
});
}
const execGit = gulp.series(gitAdd, gitCommit, gitTag);
@ -495,10 +426,4 @@ exports.clean = clean;
exports.link = linkUserData;
exports.package = packageBuild;
exports.update = updateManifest;
exports.publish = gulp.series(
clean,
updateManifest,
execBuild,
packageBuild,
execGit
);
exports.publish = gulp.series(clean, updateManifest, execBuild, packageBuild, execGit);

View file

@ -23,7 +23,6 @@ export class DS4ActorSheet extends ActorSheet<{
// TODO: replace ["..."] access with .
const data = super.getData();
data["dtypes"] = ["String", "Number", "Boolean"];
const innerData = data.data;
for (let attr of Object.values(data.data["attributes"])) {
attr["isCheckbox"] = attr["dtype"] === "Boolean";
}

View file

@ -35,7 +35,7 @@ export class DS4ItemSheet extends ItemSheet {
const position = super.setPosition(options);
const sheetBody = (this.element as JQuery).find(".sheet-body"); // TODO: Why is the cast necessary?
const bodyHeight = position.height - 192;
//sheetBody.css("height", bodyHeight);
sheetBody.css("height", bodyHeight);
return position;
}

View file

@ -12,5 +12,4 @@
overflow-y: auto;
align-content: flex-start;
}
}
}

View file

@ -12,7 +12,7 @@
height: 30px;
line-height: 24px;
padding: 3px 0;
border-bottom: 1px solid #BBB;
border-bottom: 1px solid #bbb;
.item-image {
flex: 0 0 24px;

View file

@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": [
"DOM",
"ES6",
"ES2017"
],
"lib": ["DOM", "ES6", "ES2017"],
"types": ["foundry-pc-types"]
}
}