Skip to content

Commit

Permalink
Cleanup (#74)
Browse files Browse the repository at this point in the history
* Updated linting rules

* updated types building

* moved index inside source

* updated eslint to include mjs files
  • Loading branch information
kpal81xd authored Jul 31, 2024
1 parent e87054a commit b474287
Show file tree
Hide file tree
Showing 40 changed files with 304 additions and 167 deletions.
37 changes: 21 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": [
"@playcanvas/eslint-config"
"@playcanvas/eslint-config",
"eslint:recommended",
"plugin:regexp/recommended"
],
"globals": {
"share": "readonly"
Expand All @@ -15,21 +17,24 @@
"requireConfigFile": false
},
"rules": {
"indent": [
"error",
4,
{
"FunctionExpression": {
"body": 1,
"parameters": 2
},
"MemberExpression": 0,
"SwitchCase": 1
}
],
"jsdoc/check-tag-names": ["error", {
"definedTags": ["category"]
"accessor-pairs": ["error", { "setWithoutGet": false, "getWithoutSet": false }],
"curly": ["error", "multi-line"],
"import/order": ["error", {
"groups": ["builtin", "external", "internal", ["parent", "sibling"], "index", "unknown"],
"newlines-between": "always",
"alphabetize": { "order": "asc", "caseInsensitive": true }
}],
"jsdoc/check-examples": "off"
"indent": ["error", 4, {
"FunctionExpression": { "body": 1, "parameters": 2 },
"MemberExpression": 0,
"SwitchCase": 1
}],
"jsdoc/check-tag-names": ["error", { "definedTags": ["category"] }],
"jsdoc/check-examples": "off",
"no-prototype-builtins": "off",
"no-use-before-define": "off",
"prefer-arrow-callback": ["error", { "allowNamedFunctions": true }],
"prefer-template": "error",
"require-atomic-updates": "warn"
}
}
36 changes: 0 additions & 36 deletions index.js

This file was deleted.

62 changes: 62 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"@rollup/plugin-babel": "^6.0.4",
"chai": "^4.4.1",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-regexp": "^2.6.0",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.2.0",
"karma-mocha": "2.0.1",
Expand All @@ -52,8 +54,8 @@
"test": "karma start test/karma.conf.js --single-run",
"test:debug": "karma start test/karma.conf.js --single-run=false --browsers Chrome",
"build": "rollup -c",
"build:types": "tsc index.js --outDir types --allowJs --declaration --emitDeclarationOnly && rollup -c --environment target:types",
"build:types": "rollup -c --environment target:types",
"docs": "typedoc",
"lint": "eslint --ext .js src"
"lint": "eslint --ext .js,.mjs src"
}
}
11 changes: 7 additions & 4 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import babel from '@rollup/plugin-babel';
import dts from 'rollup-plugin-dts';
import { babel } from '@rollup/plugin-babel';
import { dts } from 'rollup-plugin-dts';

import { runTsc } from './utils/plugins/rollup-run-tsc.mjs';

const umd = {
external: ['@playcanvas/observer'],
input: 'index.js',
input: 'src/index.js',
output: {
file: 'dist/index.js',
format: 'umd',
Expand Down Expand Up @@ -37,7 +39,7 @@ const umd = {

const module = {
external: ['@playcanvas/observer'],
input: 'index.js',
input: 'src/index.js',
output: {
file: 'dist/index.mjs',
format: 'module',
Expand All @@ -60,6 +62,7 @@ const types = {
format: 'es'
}],
plugins: [
runTsc('tsconfig.build.json'),
dts()
]
};
Expand Down
12 changes: 7 additions & 5 deletions src/asset.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions src/assets.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Asset } from './asset.js';
import { globals as api } from './globals.js';
import { Events, ObserverList } from '@playcanvas/observer';
import { uploadFile } from './assets/upload.js';
import { createTemplate } from './assets/createTemplate.js';

import { Asset } from './asset.js';
import { createScript } from './assets/createScript.js';
import { createTemplate } from './assets/createTemplate.js';
import { instantiateTemplates } from './assets/instantiateTemplates.js';
import { uploadFile } from './assets/upload.js';
import { globals as api } from './globals.js';

/**
* Arguments passed when uploading an asset file.
Expand Down Expand Up @@ -68,8 +69,9 @@ class Assets extends Events {
index: 'id',
sorted: (a, b) => {
const f = (b._data.type === 'folder') - (a._data.type === 'folder');
if (f !== 0)
if (f !== 0) {
return f;
}
if ((a._data.name || '').toLowerCase() > (b._data.name || '').toLowerCase()) {
return 1;
} else if ((a._data.name || '').toLowerCase() < (b._data.name || '').toLowerCase()) {
Expand Down Expand Up @@ -234,8 +236,9 @@ class Assets extends Events {
let pos = this._assets.positionNextClosest(asset._observer, (a, b) => {
const f = (b._data.type === 'folder') - (a._data.type === 'folder');

if (f !== 0)
if (f !== 0) {
return f;
}

if ((a === b ? oldName : (a._data.name || '').toLowerCase()) > name) {
return 1;
Expand All @@ -246,14 +249,17 @@ class Assets extends Events {

});

if (pos === -1 && (ind + 1) === this._assets.data.length)
if (pos === -1 && (ind + 1) === this._assets.data.length) {
return;
}

if (ind !== -1 && (ind + 1 === pos) || (ind === pos))
if (ind !== -1 && (ind + 1 === pos) || (ind === pos)) {
return;
}

if (ind < pos)
if (ind < pos) {
pos--;
}

this._assets.move(asset._observer, pos);
this.emit('move', asset, pos);
Expand Down Expand Up @@ -450,7 +456,7 @@ class Assets extends Events {
getAssetForScript(script) {
return this.findOne((asset) => {
return asset.get('type') === 'script' &&
asset.has('data.scripts.' + script);
asset.has(`data.scripts.${script}`);
});
}

Expand Down Expand Up @@ -919,7 +925,7 @@ class Assets extends Events {
});

if (!response.ok) {
throw new Error(response.status + ': ' + response.statusText);
throw new Error(`${response.status}: ${response.statusText}`);
}

assets.forEach(a => this.remove(a));
Expand Down
9 changes: 5 additions & 4 deletions src/assets/createScript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const VALID_FILENAME = /^([^0-9.#<>$+%!`&='{}@\\/:*?"<>|\n])([^#<>$+%!`&='{}@\\/:*?"<>|\n])*$/i;
const VALID_FILENAME = /^[^0-9.#<>$+%!`&='{}@\\/:*?"|\n][^#<>$+%!`&='{}@\\/:*?"|\n]*$/;

/**
* Creates filename and script content from provided arguments. If the provide filename contains a '.mjs'
Expand All @@ -16,13 +16,14 @@ function createScript(filename, text) {
const tokens = [];
const name = filename.slice(0, -3);
const str = name.replace(/([^A-Z])([A-Z][^A-Z])/g, '$1 $2').replace(/([A-Z0-9]{2,})/g, ' $1');
const parts = str.split(/(\s|\-|_|\.)/g);
const parts = str.split(/([\s\-_.])/);

// filter valid tokens
for (let i = 0; i < parts.length; i++) {
parts[i] = parts[i].toLowerCase().trim();
if (parts[i] && parts[i] !== '-' && parts[i] !== '_' && parts[i] !== '.')
if (parts[i] && parts[i] !== '-' && parts[i] !== '_' && parts[i] !== '.') {
tokens.push(parts[i]);
}
}

if (tokens.length) {
Expand All @@ -45,7 +46,7 @@ function createScript(filename, text) {
}

if (!filename) {
filename = scriptName + '.js';
filename = `${scriptName}.js`;
}

if (!/.js$/i.test(filename)) {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/replace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { globals as api } from '../globals.js';
import { findAssetReferencesInComponents, updateReferences } from '../entities/references.js';
import { globals as api } from '../globals.js';
import { utils } from '../utils.js';

const REGEX_MODEL_DATA_MAPPING = /^data\.mapping\.(\d+)\.material$/;
Expand Down
Loading

0 comments on commit b474287

Please sign in to comment.