diff --git a/.eslintrc.js b/.eslintrc.js index 59124a08..d33d75cb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,6 +18,7 @@ module.exports = { root: true, rules: { '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/switch-exhaustiveness-check': 'error', '@typescript-eslint/no-explicit-any': [ 'error', { diff --git a/.gitignore b/.gitignore index b58664cf..bbc7ab8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/* packages/*/generators packages/*/lib -packages/*/node_modules \ No newline at end of file +packages/*/node_modules +tsconfig.tsbuildinfo \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index aeb76351..19f9f868 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,7 +12,6 @@ module.exports = { ], testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'], transform: { - "\\.js$": "ts-jest", - "\\.ts$": "ts-jest" - } + '\\.ts$': 'ts-jest', + }, }; diff --git a/package.json b/package.json index 95d2cd4a..c31ff07b 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,10 @@ "packages/*" ], "scripts": { - "build": "node scripts/build.js", + "build": "tsc --build packages/*/tsconfig.json && yarn workspaces run copyfiles", "check-deps": "node scripts/check-deps.js", - "ci": "yarn check-deps && yarn format:check && yarn lint && yarn build && yarn test", + "ci": "yarn clean && yarn check-deps && yarn format:check && yarn lint && yarn build && yarn test", + "clean": "yarn workspaces run clean", "format": "prettier --write \".*.ts\" \"packages/**/*.ts\"", "format:check": "prettier --list-different \".*.ts\" \"packages/**/*.ts\"", "level-deps": "node scripts/level-deps.js", @@ -23,7 +24,7 @@ "lint:fix": "eslint --fix .", "qa": "node scripts/qa/index.js", "test": "jest --runInBand", - "watch": "node scripts/watch" + "watch": "node scripts/watch.js" }, "devDependencies": { "@types/jest": "^24.0.18", diff --git a/packages/generator-liferay-js/package.json b/packages/generator-liferay-js/package.json index 3021d3d6..f21a1dd2 100644 --- a/packages/generator-liferay-js/package.json +++ b/packages/generator-liferay-js/package.json @@ -2,6 +2,7 @@ "name": "generator-liferay-js", "version": "3.0.0", "description": "Yeoman generators for Liferay DXP and Portal CE JavaScript projects.", + "license": "LGPL-3.0", "main": "generators/app/index.js", "files": [ "generators" @@ -12,11 +13,13 @@ "liferay-js" ], "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "devDependencies": { + "@types/yeoman-generator": "^3.1.4", "mem-fs": "^1.1.3", "mem-fs-editor": "^6.0.0", "rimraf": "^3.0.0" diff --git a/packages/generator-liferay-js/src/adapt/index.js b/packages/generator-liferay-js/src/adapt/index.ts similarity index 96% rename from packages/generator-liferay-js/src/adapt/index.js rename to packages/generator-liferay-js/src/adapt/index.ts index 7cea06a1..cc673508 100644 --- a/packages/generator-liferay-js/src/adapt/index.js +++ b/packages/generator-liferay-js/src/adapt/index.ts @@ -4,8 +4,8 @@ */ import { - info, error, + info, print, success, title, @@ -109,6 +109,9 @@ if (argv.which) { * Generator to add deploy support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman constructor */ @@ -182,7 +185,8 @@ export default class extends Generator { ]); // Set project's package manager internally using a hack - project._pkgManager = answers.pkgManager; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (project as any)._pkgManager = answers.pkgManager; } Object.assign( @@ -352,6 +356,10 @@ export default class extends Generator { pkgJson.addPortletProperty('com.liferay.portlet.instanceable', true); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _options: any; + private _pkgManager: string; } module.exports = exports['default']; diff --git a/packages/generator-liferay-js/src/app/index.js b/packages/generator-liferay-js/src/app/index.ts similarity index 92% rename from packages/generator-liferay-js/src/app/index.js rename to packages/generator-liferay-js/src/app/index.ts index 9c6b54c3..369b645c 100644 --- a/packages/generator-liferay-js/src/app/index.js +++ b/packages/generator-liferay-js/src/app/index.ts @@ -1,6 +1,5 @@ /** - * © 2017 Liferay, Inc. - * + * SPDX-FileCopyrightText: © 2017 Liferay, Inc. * SPDX-License-Identifier: LGPL-3.0-or-later */ @@ -44,7 +43,10 @@ export default class extends Generator { ]); this.destinationRoot(path.resolve(answers.folder)); - this.composeWith(require.resolve(`../target-${answers.target}`)); + this.composeWith( + require.resolve(`../target-${answers.target}`), + undefined + ); } /** @@ -55,7 +57,7 @@ export default class extends Generator { _findTargets() { const tds = fs .readdirSync(path.join(__dirname, '..')) - .filter(file => file.indexOf('target-') == 0) + .filter(file => file.indexOf('target-') === 0) .map(target => target.replace('target-', '')) .map(target => ({ ...getTargetDescription(target), @@ -91,6 +93,7 @@ export default class extends Generator { _getTargetCategories(tds) { const map = tds.reduce((map, td) => { map[td.category] = true; + return map; }, {}); diff --git a/packages/generator-liferay-js/src/config.js b/packages/generator-liferay-js/src/config.ts similarity index 96% rename from packages/generator-liferay-js/src/config.js rename to packages/generator-liferay-js/src/config.ts index fdbf5a05..09c88bd1 100644 --- a/packages/generator-liferay-js/src/config.js +++ b/packages/generator-liferay-js/src/config.ts @@ -7,7 +7,8 @@ import os from 'os'; import path from 'path'; import readJsonSync from 'read-json-sync'; -let cfg = {}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +let cfg: any = {}; Object.assign( cfg, @@ -101,6 +102,7 @@ function safeReadJsonSync(path) { if (err.code !== 'ENOENT') { throw err; } + return {}; } } diff --git a/packages/generator-liferay-js/src/facet-configuration/constants.js b/packages/generator-liferay-js/src/facet-configuration/constants.ts similarity index 100% rename from packages/generator-liferay-js/src/facet-configuration/constants.js rename to packages/generator-liferay-js/src/facet-configuration/constants.ts diff --git a/packages/generator-liferay-js/src/facet-configuration/index.js b/packages/generator-liferay-js/src/facet-configuration/index.ts similarity index 96% rename from packages/generator-liferay-js/src/facet-configuration/index.js rename to packages/generator-liferay-js/src/facet-configuration/index.ts index 53d4c15c..c37696a5 100644 --- a/packages/generator-liferay-js/src/facet-configuration/index.js +++ b/packages/generator-liferay-js/src/facet-configuration/index.ts @@ -16,6 +16,9 @@ import {DEFAULT_CONFIGURATION} from './constants'; * Generator to add configuration support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/facet-configuration/sample-generator.js b/packages/generator-liferay-js/src/facet-configuration/sample-generator.ts similarity index 96% rename from packages/generator-liferay-js/src/facet-configuration/sample-generator.js rename to packages/generator-liferay-js/src/facet-configuration/sample-generator.ts index 860c05ce..589220fe 100644 --- a/packages/generator-liferay-js/src/facet-configuration/sample-generator.js +++ b/packages/generator-liferay-js/src/facet-configuration/sample-generator.ts @@ -118,4 +118,7 @@ export default class { } } } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; } diff --git a/packages/generator-liferay-js/src/facet-deploy/index.js b/packages/generator-liferay-js/src/facet-deploy/index.ts similarity index 95% rename from packages/generator-liferay-js/src/facet-deploy/index.js rename to packages/generator-liferay-js/src/facet-deploy/index.ts index 35e5fe2a..a64dc6e4 100644 --- a/packages/generator-liferay-js/src/facet-deploy/index.js +++ b/packages/generator-liferay-js/src/facet-deploy/index.ts @@ -14,6 +14,9 @@ import PkgJsonModifier from '../utils/modifier/package.json'; * Generator to add deploy support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/facet-localization/constants.js b/packages/generator-liferay-js/src/facet-localization/constants.ts similarity index 100% rename from packages/generator-liferay-js/src/facet-localization/constants.js rename to packages/generator-liferay-js/src/facet-localization/constants.ts diff --git a/packages/generator-liferay-js/src/facet-localization/index.js b/packages/generator-liferay-js/src/facet-localization/index.ts similarity index 95% rename from packages/generator-liferay-js/src/facet-localization/index.js rename to packages/generator-liferay-js/src/facet-localization/index.ts index 232197c8..8865d641 100644 --- a/packages/generator-liferay-js/src/facet-localization/index.js +++ b/packages/generator-liferay-js/src/facet-localization/index.ts @@ -16,6 +16,9 @@ import {DEFAULT_LOCALIZATION} from './constants'; * Generator to add localization support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/facet-localization/sample-generator.js b/packages/generator-liferay-js/src/facet-localization/sample-generator.ts similarity index 91% rename from packages/generator-liferay-js/src/facet-localization/sample-generator.js rename to packages/generator-liferay-js/src/facet-localization/sample-generator.ts index 1ec2d2ef..49a3f91f 100644 --- a/packages/generator-liferay-js/src/facet-localization/sample-generator.js +++ b/packages/generator-liferay-js/src/facet-localization/sample-generator.ts @@ -39,7 +39,11 @@ export default class { _toProperties(labels) { return Object.keys(labels).reduce((obj, key) => { obj[hyphenate(key)] = labels[key]; + return obj; }, {}); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; } diff --git a/packages/generator-liferay-js/src/facet-portlet/index.js b/packages/generator-liferay-js/src/facet-portlet/index.ts similarity index 97% rename from packages/generator-liferay-js/src/facet-portlet/index.js rename to packages/generator-liferay-js/src/facet-portlet/index.ts index 5fddb349..0dfd977f 100644 --- a/packages/generator-liferay-js/src/facet-portlet/index.js +++ b/packages/generator-liferay-js/src/facet-portlet/index.ts @@ -16,6 +16,9 @@ import PkgJsonModifier from '../utils/modifier/package.json'; * Generator to add portlet support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/facet-project/index.js b/packages/generator-liferay-js/src/facet-project/index.ts similarity index 94% rename from packages/generator-liferay-js/src/facet-project/index.js rename to packages/generator-liferay-js/src/facet-project/index.ts index 965da639..1655fb7d 100644 --- a/packages/generator-liferay-js/src/facet-project/index.js +++ b/packages/generator-liferay-js/src/facet-project/index.ts @@ -17,6 +17,9 @@ import { * Generator to add base scaffolding to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/facet-start/index.js b/packages/generator-liferay-js/src/facet-start/index.ts similarity index 93% rename from packages/generator-liferay-js/src/facet-start/index.js rename to packages/generator-liferay-js/src/facet-start/index.ts index 94d5ab85..64c692d7 100644 --- a/packages/generator-liferay-js/src/facet-start/index.js +++ b/packages/generator-liferay-js/src/facet-start/index.ts @@ -13,6 +13,9 @@ import PkgJsonModifier from '../utils/modifier/package.json'; * Generator to add start support to projects. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.js b/packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.ts similarity index 93% rename from packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.js rename to packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.ts index 97d2e70f..1ae62fbd 100644 --- a/packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.js +++ b/packages/generator-liferay-js/src/target-angular-portlet/angular-portlet.ts @@ -9,7 +9,7 @@ import Generator from 'yeoman-generator'; import {Copier} from '../utils'; import ProjectAnalyzer from '../utils/ProjectAnalyzer'; import NpmbuildrcModifier from '../utils/modifier/npmbuildrc'; -import PkgJsonModifier from '../utils/modifier/package.json.js'; +import PkgJsonModifier from '../utils/modifier/package.json'; import * as standardTarget from '../utils/target/standard'; import dependenciesJson from './dependencies.json'; @@ -17,6 +17,10 @@ import dependenciesJson from './dependencies.json'; * Implementation of generation of Angular portlets. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + namespace: string; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-angular-portlet/index.js b/packages/generator-liferay-js/src/target-angular-portlet/index.ts similarity index 89% rename from packages/generator-liferay-js/src/target-angular-portlet/index.js rename to packages/generator-liferay-js/src/target-angular-portlet/index.ts index d2c031d7..571d252c 100644 --- a/packages/generator-liferay-js/src/target-angular-portlet/index.js +++ b/packages/generator-liferay-js/src/target-angular-portlet/index.ts @@ -17,7 +17,7 @@ export default class extends Generator { initializing() { standardTarget.initializing(this); - this.composeWith(require.resolve('./angular-portlet')); + this.composeWith(require.resolve('./angular-portlet'), undefined); } /** diff --git a/packages/generator-liferay-js/src/target-metaljs-portlet/index.js b/packages/generator-liferay-js/src/target-metaljs-portlet/index.ts similarity index 89% rename from packages/generator-liferay-js/src/target-metaljs-portlet/index.js rename to packages/generator-liferay-js/src/target-metaljs-portlet/index.ts index 46a593de..2b7a3cbb 100644 --- a/packages/generator-liferay-js/src/target-metaljs-portlet/index.js +++ b/packages/generator-liferay-js/src/target-metaljs-portlet/index.ts @@ -17,7 +17,7 @@ export default class extends Generator { initializing() { standardTarget.initializing(this); - this.composeWith(require.resolve('./metaljs-portlet')); + this.composeWith(require.resolve('./metaljs-portlet'), undefined); } /** diff --git a/packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.js b/packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.ts similarity index 96% rename from packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.js rename to packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.ts index f5b1fbd1..5be90fdd 100644 --- a/packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.js +++ b/packages/generator-liferay-js/src/target-metaljs-portlet/metaljs-portlet.ts @@ -19,6 +19,10 @@ import importsJson from './imports.json'; * Implementation of generation of Metal.js portlets. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + namespace: string; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-react-portlet/index.js b/packages/generator-liferay-js/src/target-react-portlet/index.ts similarity index 89% rename from packages/generator-liferay-js/src/target-react-portlet/index.js rename to packages/generator-liferay-js/src/target-react-portlet/index.ts index 5fb40ed0..9689e0a5 100644 --- a/packages/generator-liferay-js/src/target-react-portlet/index.js +++ b/packages/generator-liferay-js/src/target-react-portlet/index.ts @@ -17,7 +17,7 @@ export default class extends Generator { initializing() { standardTarget.initializing(this); - this.composeWith(require.resolve('./react-portlet')); + this.composeWith(require.resolve('./react-portlet'), undefined); } /** diff --git a/packages/generator-liferay-js/src/target-react-portlet/react-portlet.js b/packages/generator-liferay-js/src/target-react-portlet/react-portlet.ts similarity index 95% rename from packages/generator-liferay-js/src/target-react-portlet/react-portlet.js rename to packages/generator-liferay-js/src/target-react-portlet/react-portlet.ts index 734b0c24..3c028dc4 100644 --- a/packages/generator-liferay-js/src/target-react-portlet/react-portlet.js +++ b/packages/generator-liferay-js/src/target-react-portlet/react-portlet.ts @@ -17,6 +17,10 @@ import dependenciesJson from './dependencies.json'; * Implementation of generation of React portlets. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + namespace: string; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-shared-bundle/index.js b/packages/generator-liferay-js/src/target-shared-bundle/index.ts similarity index 57% rename from packages/generator-liferay-js/src/target-shared-bundle/index.js rename to packages/generator-liferay-js/src/target-shared-bundle/index.ts index 9a5b4c9e..c941593c 100644 --- a/packages/generator-liferay-js/src/target-shared-bundle/index.js +++ b/packages/generator-liferay-js/src/target-shared-bundle/index.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: LGPL-3.0-or-later */ -import Generator from 'yeoman-generator'; +import Generator, {InstallOptions} from 'yeoman-generator'; /** * Generator for shared bundles. @@ -13,10 +13,10 @@ export default class extends Generator { * Standard Yeoman initialization function */ initializing() { - this.composeWith(require.resolve('../facet-project')); - this.composeWith(require.resolve('../facet-localization')); - this.composeWith(require.resolve('../facet-deploy')); - this.composeWith(require.resolve('./shared-bundle')); + this.composeWith(require.resolve('../facet-project'), undefined); + this.composeWith(require.resolve('../facet-localization'), undefined); + this.composeWith(require.resolve('../facet-deploy'), undefined); + this.composeWith(require.resolve('./shared-bundle'), undefined); } /** @@ -27,7 +27,8 @@ export default class extends Generator { bower: false, skipMessage: this.options['skip-install-message'], skipInstall: this.options['skip-install'], - }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any); } } diff --git a/packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.js b/packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.ts similarity index 95% rename from packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.js rename to packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.ts index d7d62640..0418b0ba 100644 --- a/packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.js +++ b/packages/generator-liferay-js/src/target-shared-bundle/shared-bundle.ts @@ -13,6 +13,9 @@ import PkgJsonModifier from '../utils/modifier/package.json'; * Implementation of generation of shared bundles. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-vanilla-portlet/index.js b/packages/generator-liferay-js/src/target-vanilla-portlet/index.ts similarity index 89% rename from packages/generator-liferay-js/src/target-vanilla-portlet/index.js rename to packages/generator-liferay-js/src/target-vanilla-portlet/index.ts index 30bc75c5..6a38da1a 100644 --- a/packages/generator-liferay-js/src/target-vanilla-portlet/index.js +++ b/packages/generator-liferay-js/src/target-vanilla-portlet/index.ts @@ -17,7 +17,7 @@ export default class extends Generator { initializing() { standardTarget.initializing(this); - this.composeWith(require.resolve('./vanilla-portlet')); + this.composeWith(require.resolve('./vanilla-portlet'), undefined); } /** diff --git a/packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.js b/packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.ts similarity index 93% rename from packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.js rename to packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.ts index 9c2adf2d..7f4a0589 100644 --- a/packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.js +++ b/packages/generator-liferay-js/src/target-vanilla-portlet/vanilla-portlet.ts @@ -9,13 +9,17 @@ import Generator from 'yeoman-generator'; import {Copier, promptWithConfig} from '../utils'; import ProjectAnalyzer from '../utils/ProjectAnalyzer'; import NpmbuildrcModifier from '../utils/modifier/npmbuildrc'; -import PkgJsonModifier from '../utils/modifier/package.json.js'; +import PkgJsonModifier from '../utils/modifier/package.json'; import * as standardTarget from '../utils/target/standard'; /** * Implementation of generation of plain JavaScript portlets. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + answers: any; + namespace: string; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/target-vuejs-portlet/index.js b/packages/generator-liferay-js/src/target-vuejs-portlet/index.ts similarity index 89% rename from packages/generator-liferay-js/src/target-vuejs-portlet/index.js rename to packages/generator-liferay-js/src/target-vuejs-portlet/index.ts index 5ab206d2..7b4461e0 100644 --- a/packages/generator-liferay-js/src/target-vuejs-portlet/index.js +++ b/packages/generator-liferay-js/src/target-vuejs-portlet/index.ts @@ -17,7 +17,7 @@ export default class extends Generator { initializing() { standardTarget.initializing(this); - this.composeWith(require.resolve('./vuejs-portlet')); + this.composeWith(require.resolve('./vuejs-portlet'), undefined); } /** diff --git a/packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.js b/packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.ts similarity index 92% rename from packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.js rename to packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.ts index 17ffbc7a..3b2fdc19 100644 --- a/packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.js +++ b/packages/generator-liferay-js/src/target-vuejs-portlet/vuejs-portlet.ts @@ -9,7 +9,7 @@ import Generator from 'yeoman-generator'; import {Copier} from '../utils'; import ProjectAnalyzer from '../utils/ProjectAnalyzer'; import NpmbuildrcModifier from '../utils/modifier/npmbuildrc'; -import PkgJsonModifier from '../utils/modifier/package.json.js'; +import PkgJsonModifier from '../utils/modifier/package.json'; import * as standardTarget from '../utils/target/standard'; import dependenciesJson from './dependencies.json'; @@ -17,6 +17,9 @@ import dependenciesJson from './dependencies.json'; * Implementation of generation of Vue.js portlets. */ export default class extends Generator { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace: string; + /** * Standard Yeoman initialization function */ diff --git a/packages/generator-liferay-js/src/utils/JsonModifier.js b/packages/generator-liferay-js/src/utils/JsonModifier.ts similarity index 79% rename from packages/generator-liferay-js/src/utils/JsonModifier.js rename to packages/generator-liferay-js/src/utils/JsonModifier.ts index 61f3a3db..feb3e34a 100644 --- a/packages/generator-liferay-js/src/utils/JsonModifier.js +++ b/packages/generator-liferay-js/src/utils/JsonModifier.ts @@ -10,10 +10,9 @@ export default class JsonModifier { /** * @param {Generator} generator a Yeoman generator * @param {String} path path to file - * @param {string|number} space the space string/number of spaces to use - * when stringifying + * @param space the space string/number of spaces to use when stringifying */ - constructor(generator, path, space = ' ') { + constructor(generator, path, space: string | number = ' ') { this._generator = generator; this._path = path; this._space = space; @@ -50,4 +49,9 @@ export default class JsonModifier { _escapeProp(name) { return name.replace(/\./g, '\\.'); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; + private _path: string; + private _space: string | number; } diff --git a/packages/generator-liferay-js/src/utils/ProjectAnalyzer.js b/packages/generator-liferay-js/src/utils/ProjectAnalyzer.ts similarity index 94% rename from packages/generator-liferay-js/src/utils/ProjectAnalyzer.js rename to packages/generator-liferay-js/src/utils/ProjectAnalyzer.ts index 2932e372..5cd8934a 100644 --- a/packages/generator-liferay-js/src/utils/ProjectAnalyzer.js +++ b/packages/generator-liferay-js/src/utils/ProjectAnalyzer.ts @@ -92,10 +92,10 @@ export default class ProjectAnalyzer { * Get the path to localization properties file. * @return {string} */ - get localizationFilePath() { + get localizationFilePath(): string { const fs = this._generator.fs; - let localization = prop.get( + let localization: string = prop.get( this._npmbundlerrc, 'create-jar.features.localization' ); @@ -149,4 +149,7 @@ export default class ProjectAnalyzer { get _packageJson() { return this._generator.fs.readJSON('package.json'); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; } diff --git a/packages/generator-liferay-js/src/utils/__tests__/ProjectAnalyzer.test.js b/packages/generator-liferay-js/src/utils/__tests__/ProjectAnalyzer.test.ts similarity index 100% rename from packages/generator-liferay-js/src/utils/__tests__/ProjectAnalyzer.test.js rename to packages/generator-liferay-js/src/utils/__tests__/ProjectAnalyzer.test.ts diff --git a/packages/generator-liferay-js/src/utils/__tests__/index.test.js b/packages/generator-liferay-js/src/utils/__tests__/index.test.ts similarity index 100% rename from packages/generator-liferay-js/src/utils/__tests__/index.test.js rename to packages/generator-liferay-js/src/utils/__tests__/index.test.ts diff --git a/packages/generator-liferay-js/src/utils/index.js b/packages/generator-liferay-js/src/utils/index.ts similarity index 94% rename from packages/generator-liferay-js/src/utils/index.js rename to packages/generator-liferay-js/src/utils/index.ts index edd77656..f88e3261 100644 --- a/packages/generator-liferay-js/src/utils/index.js +++ b/packages/generator-liferay-js/src/utils/index.ts @@ -1,13 +1,13 @@ /** - * © 2017 Liferay, Inc. - * + * SPDX-FileCopyrightText: © 2017 Liferay, Inc. * SPDX-License-Identifier: LGPL-3.0-or-later */ import fs from 'fs'; import path from 'path'; -import pkgJson from '../../package.json'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const pkgJson = require('../../package.json'); import * as cfg from '../config'; /** @@ -28,7 +28,7 @@ export class Copier { * instantiating the template (defaults to {}) * @param {String} dest optional destination name (defaults to src) */ - copyFile(src, {context = {}, dest} = {}) { + copyFile(src, {context = {}, dest = undefined} = {}) { const gen = this._generator; const fullContext = { @@ -69,6 +69,9 @@ export class Copier { } }); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; } /** @@ -82,18 +85,22 @@ export function formatLabels(labels) { raw: labels, quoted: Object.entries(labels).reduce((obj, [key, value]) => { obj[key] = `'${value}'`; + return obj; }, {}), template: Object.keys(labels).reduce((obj, key) => { obj[key] = `\${Liferay.Language.get('${hyphenate(key)}')}`; + return obj; }, {}), js: Object.keys(labels).reduce((obj, key) => { obj[key] = `Liferay.Language.get('${hyphenate(key)}')`; + return obj; }, {}), jsx: Object.keys(labels).reduce((obj, key) => { obj[key] = `{Liferay.Language.get('${hyphenate(key)}')}`; + return obj; }, {}), }; @@ -168,7 +175,7 @@ export function hyphenate(key) { * @param {Array} prompts a Yeoman prompts array * @return {object} the set of answers */ -export async function promptWithConfig(generator, namespace, prompts) { +export async function promptWithConfig(generator, namespace, prompts?) { if (Array.isArray(namespace)) { prompts = namespace; namespace = generator.namespace; @@ -195,6 +202,7 @@ export async function promptWithConfig(generator, namespace, prompts) { if (cfg.batchMode()) { return prompts.reduce((answers, prompt) => { answers[prompt.name] = prompt.default; + return answers; }, {}); } else { diff --git a/packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.js b/packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.ts similarity index 86% rename from packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.js rename to packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.ts index 77803da1..da6a24e5 100644 --- a/packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.js +++ b/packages/generator-liferay-js/src/utils/modifier/assets/css/styles.css.ts @@ -31,4 +31,8 @@ ${values.map(value => ` ${value}`).join('\n')} gen.fs.write(this._path, css); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; + private _path: string; } diff --git a/packages/generator-liferay-js/src/utils/modifier/features/configuration.json.js b/packages/generator-liferay-js/src/utils/modifier/features/configuration.json.ts similarity index 94% rename from packages/generator-liferay-js/src/utils/modifier/features/configuration.json.js rename to packages/generator-liferay-js/src/utils/modifier/features/configuration.json.ts index 10f928f5..55b194e4 100644 --- a/packages/generator-liferay-js/src/utils/modifier/features/configuration.json.js +++ b/packages/generator-liferay-js/src/utils/modifier/features/configuration.json.ts @@ -12,6 +12,11 @@ import ProjectAnalyzer from '../../ProjectAnalyzer'; * A class to help modifying the configuration.json file. */ export default class ConfigurationJsonModifier extends JsonModifier { + static readonly Section = { + SYSTEM: 'system', + PORTLET_INSTANCE: 'portletInstance', + }; + /** * @param {Generator} generator a Yeoman generator */ @@ -61,8 +66,3 @@ export default class ConfigurationJsonModifier extends JsonModifier { }); } } - -ConfigurationJsonModifier.Section = { - SYSTEM: 'system', - PORTLET_INSTANCE: 'portletInstance', -}; diff --git a/packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.js b/packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.ts similarity index 90% rename from packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.js rename to packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.ts index c2ab9d22..45dc2b6f 100644 --- a/packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.js +++ b/packages/generator-liferay-js/src/utils/modifier/features/localization/Language.properties.ts @@ -46,4 +46,8 @@ export default class { fs.write(this._path, content); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; + private _path: string; } diff --git a/packages/generator-liferay-js/src/utils/modifier/gitignore.js b/packages/generator-liferay-js/src/utils/modifier/gitignore.ts similarity index 85% rename from packages/generator-liferay-js/src/utils/modifier/gitignore.js rename to packages/generator-liferay-js/src/utils/modifier/gitignore.ts index 4bb416ce..b48d574b 100644 --- a/packages/generator-liferay-js/src/utils/modifier/gitignore.js +++ b/packages/generator-liferay-js/src/utils/modifier/gitignore.ts @@ -32,4 +32,8 @@ export default class { gen.fs.write(this._path, content); } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _generator: any; + private _path: string; } diff --git a/packages/generator-liferay-js/src/utils/modifier/npmbuildrc.js b/packages/generator-liferay-js/src/utils/modifier/npmbuildrc.ts similarity index 100% rename from packages/generator-liferay-js/src/utils/modifier/npmbuildrc.js rename to packages/generator-liferay-js/src/utils/modifier/npmbuildrc.ts diff --git a/packages/generator-liferay-js/src/utils/modifier/npmbundlerrc.js b/packages/generator-liferay-js/src/utils/modifier/npmbundlerrc.ts similarity index 100% rename from packages/generator-liferay-js/src/utils/modifier/npmbundlerrc.js rename to packages/generator-liferay-js/src/utils/modifier/npmbundlerrc.ts diff --git a/packages/generator-liferay-js/src/utils/modifier/package.json.js b/packages/generator-liferay-js/src/utils/modifier/package.json.ts similarity index 94% rename from packages/generator-liferay-js/src/utils/modifier/package.json.js rename to packages/generator-liferay-js/src/utils/modifier/package.json.ts index 1e549474..9736276b 100644 --- a/packages/generator-liferay-js/src/utils/modifier/package.json.js +++ b/packages/generator-liferay-js/src/utils/modifier/package.json.ts @@ -13,10 +13,9 @@ import JsonModifier from '../JsonModifier'; export default class extends JsonModifier { /** * @param {Generator} generator a Yeoman generator - * @param {string|number} space the space string/number of spaces to use - * when stringifying + * @param space the space string/number of spaces to use when stringifying */ - constructor(generator, space = '\t') { + constructor(generator, space: string | number = '\t') { super(generator, 'package.json', space); } diff --git a/packages/generator-liferay-js/src/utils/target/standard.js b/packages/generator-liferay-js/src/utils/target/standard.ts similarity index 97% rename from packages/generator-liferay-js/src/utils/target/standard.js rename to packages/generator-liferay-js/src/utils/target/standard.ts index fd472693..2cda6061 100644 --- a/packages/generator-liferay-js/src/utils/target/standard.js +++ b/packages/generator-liferay-js/src/utils/target/standard.ts @@ -1,6 +1,5 @@ /** - * © 2017 Liferay, Inc. - * + * SPDX-FileCopyrightText: © 2017 Liferay, Inc. * SPDX-License-Identifier: LGPL-3.0-or-later */ diff --git a/packages/generator-liferay-js/tsconfig.json b/packages/generator-liferay-js/tsconfig.json index 6c2d08ea..1f65bd81 100644 --- a/packages/generator-liferay-js/tsconfig.json +++ b/packages/generator-liferay-js/tsconfig.json @@ -1,8 +1,11 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./generators" + "allowJs": true, + "composite": true, + "outDir": "./generators", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "src/*/templates/**/*", "**/__tests__/**"] + "include": ["src/**/*", "src/**/*.json"], + "references": [{"path": "../liferay-npm-build-tools-common"}] } diff --git a/packages/liferay-npm-bridge-generator/package.json b/packages/liferay-npm-bridge-generator/package.json index f378d07d..dbb657d3 100644 --- a/packages/liferay-npm-bridge-generator/package.json +++ b/packages/liferay-npm-bridge-generator/package.json @@ -2,12 +2,14 @@ "name": "liferay-npm-bridge-generator", "version": "3.0.0", "description": "A CLI utility to generate module bridges (modules that re-export other modules).", + "license": "LGPL-3.0", "bin": { "liferay-npm-bridge-generator": "bin/liferay-npm-bridge-generator.js" }, "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bridge-generator/src/liferay-npm-bridge-generator.js b/packages/liferay-npm-bridge-generator/src/liferay-npm-bridge-generator.ts similarity index 100% rename from packages/liferay-npm-bridge-generator/src/liferay-npm-bridge-generator.js rename to packages/liferay-npm-bridge-generator/src/liferay-npm-bridge-generator.ts diff --git a/packages/liferay-npm-bridge-generator/tsconfig.json b/packages/liferay-npm-bridge-generator/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bridge-generator/tsconfig.json +++ b/packages/liferay-npm-bridge-generator/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-build-support/package.json b/packages/liferay-npm-build-support/package.json index 01711270..2b02a351 100644 --- a/packages/liferay-npm-build-support/package.json +++ b/packages/liferay-npm-build-support/package.json @@ -2,6 +2,7 @@ "name": "liferay-npm-build-support", "version": "3.0.0", "description": "A library of scripts and helpers used by generated projects in their build processes.", + "license": "LGPL-3.0", "bin": { "lnbs-build": "bin/lnbs-build.js", "lnbs-copy-assets": "bin/lnbs-copy-assets.js", @@ -11,8 +12,9 @@ "lnbs-translate": "bin/lnbs-translate.js" }, "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-build-support/src/config.js b/packages/liferay-npm-build-support/src/config.ts similarity index 89% rename from packages/liferay-npm-build-support/src/config.js rename to packages/liferay-npm-build-support/src/config.ts index fd45312c..6fde0884 100644 --- a/packages/liferay-npm-build-support/src/config.js +++ b/packages/liferay-npm-build-support/src/config.ts @@ -7,8 +7,10 @@ import prop from 'dot-prop'; import project from 'liferay-npm-build-tools-common/lib/project'; import readJsonSync from 'read-json-sync'; -let npmbuildrc = {}; -let npmbundlerrc = {}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +let npmbuildrc: any = {}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +let npmbundlerrc: any = {}; loadConfig(); @@ -17,7 +19,8 @@ loadConfig(); */ function loadConfig() { npmbuildrc = safeReadJsonSync(project.dir.join('.npmbuildrc').asNative); - npmbundlerrc = project._configuration; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + npmbundlerrc = (project as any)._configuration; // Normalize configurations normalize(npmbuildrc, 'supportedLocales', []); diff --git a/packages/liferay-npm-build-support/src/loader/util.ts b/packages/liferay-npm-build-support/src/loader/util.ts index 48480ae0..02ba59a1 100644 --- a/packages/liferay-npm-build-support/src/loader/util.ts +++ b/packages/liferay-npm-build-support/src/loader/util.ts @@ -48,7 +48,7 @@ export function removeWebpackHash(filePath: string): string { } } - if (hashIndex == -1) { + if (hashIndex === -1) { return filePath; } diff --git a/packages/liferay-npm-build-support/src/portal/gogo-shell.js b/packages/liferay-npm-build-support/src/portal/gogo-shell.js deleted file mode 100644 index 234a9f14..00000000 --- a/packages/liferay-npm-build-support/src/portal/gogo-shell.js +++ /dev/null @@ -1,152 +0,0 @@ -/** - * © 2017 Liferay, Inc. - * - * SPDX-License-Identifier: LGPL-3.0-or-later - */ - -import {Socket} from 'net'; - -const DEFAULT_CONNECT_OPTIONS = { - host: '127.0.0.1', - port: 11311, -}; - -/** - * - */ -export default class extends Socket { - /** - * @param {boolean} debug set to true to dump transmited data - */ - constructor({debug = false} = {}) { - super({}); - - this._debug = debug; - this._active = false; - this._lastResponse = undefined; - this._lastCommand = undefined; - } - - /** - * Connect to the console. - * @param {object} options for Socket.connect method - * @return {Promise} resolves when ready - */ - connect(options) { - return new Promise((resolve, reject) => { - this.once('connect', () => this._onConnect()); - - super.connect({ - ...DEFAULT_CONNECT_OPTIONS, - ...options, - }); - - this.once('error', reject); - this.once('ready', () => { - this.removeListener('error', reject); - resolve(); - }); - }); - } - - /** - * Send a command to console. - * @param {string} command - * @param {...string} args - * @return {Promise} resolves with the obtained response - */ - sendCommand(command, ...args) { - return new Promise((resolve, reject) => { - // Signal error if command is on its way - if (this._active) { - reject( - new Error( - 'Only one command can be sent at a time. ' + - 'Current command: ' + - `"${this._lastCommand.replace('\n', '')}"` + - ' has not finished.' - ) - ); - - return; - } - - // Normalize arguments - if (args.length > 0) { - command += ` ${args.join(' ')}`; - } - - if (!command.endsWith('\n')) { - command += '\n'; - } - - // Set command handler - this.once('error', reject); - this.once('prompt', response => { - this.removeListener('error', reject); - this._active = false; - resolve(response); - }); - - // Send command - this._lastResponse = ''; - this._lastCommand = command; - this._active = true; - this.write(command); - }); - } - - /** - * Handler for connect event. Emits 'ready' event when everything is setup - * and running. - */ - _onConnect() { - // Emit ready event on first prompt - this.once('prompt', () => this.emit('ready')); - - // Attach data handlers - this.on('data', data => this._debugDataListener(data)); - this.on('data', data => this._promptDataListener(data)); - - // Write handshake chars so that telnet knows we are an VT220 - this.write(new Buffer([255, 251, 24])); - this.write(new Buffer([255, 250, 24, 0, 86, 84, 50, 50, 48, 255, 240])); - } - - /** - * Handler for debugging transmited data. Prints data to console when debug - * option is set. - * @param {Buffer} data a chunk of data - */ - _debugDataListener(data) { - if (this._debug) { - process.stdout.write(data.toString()); - } - } - - /** - * Handler for prompt and responses. Emits a 'prompt' event with obtained - * response when the console replies to some command. - * @param {Buffer} data a chunk of data - */ - _promptDataListener(data) { - const finished = data.toString().endsWith('g! '); - - this._lastResponse += data.toString(); - - if (finished) { - let lastResponse = this._lastResponse; - - if (this._lastCommand) { - lastResponse = lastResponse.substr( - this._lastCommand.length + 1 - ); - } - lastResponse = lastResponse.substr(0, lastResponse.length - 3); - - this._lastResponse = lastResponse; - - this.emit('prompt', this._lastResponse); - } - } -} diff --git a/packages/liferay-npm-build-support/src/portal/portal-shell.js b/packages/liferay-npm-build-support/src/portal/portal-shell.js deleted file mode 100644 index 272b5ee3..00000000 --- a/packages/liferay-npm-build-support/src/portal/portal-shell.js +++ /dev/null @@ -1,118 +0,0 @@ -/** - * SPDX-FileCopyrightText: © 2017 Liferay, Inc. - * SPDX-License-Identifier: LGPL-3.0-or-later - */ - -import path from 'path'; - -import GogoShell from './gogo-shell'; - -/** - * - */ -export default class extends GogoShell { - /** - * - * @param {string} fileOrDir - * @return {Promise} resolves to the bundle id - */ - install(fileOrDir) { - return this.sendCommand( - `install file://${path.resolve(fileOrDir)}` - ).then(response => { - const matches = /.*BundleId\s+(\d+).*/.exec(response); - - if (!matches || matches.length < 2) { - throw new Error(response); - } - - return Number.parseInt(matches[1], 10); - }); - } - - /** - * - * @param {int} bundleId - * @return {Promise} resolves to the bundle id - */ - start(bundleId) { - return this.sendCommand(`start ${bundleId}`).then(response => { - if (response.length != 0) { - throw new Error(response); - } - - return bundleId; - }); - } - - /** - * - * @param {int} bundleId - * @return {Promise} resolves to the bundle id - */ - stop(bundleId) { - return this.sendCommand(`stop ${bundleId}`).then(response => { - if (response.length != 0) { - throw new Error(response); - } - - return bundleId; - }); - } - - /** - * - * @param {int} bundleId - * @return {Promise} resolves to undefined - */ - uninstall(bundleId) { - return this.sendCommand(`uninstall ${bundleId}`).then(response => { - if (response.length != 0) { - throw new Error(response); - } - - return undefined; - }); - } - - /** - * - * @param {int} bundleId - * @return {Promise} resolves to status string - */ - getStatus(bundleId) { - return this.sendCommand(`bundle ${bundleId}`).then(response => { - const matches = /.*Status=(\S+).*/.exec(response); - - if (!matches || matches.length < 2) { - throw new Error(response); - } - - return matches[1]; - }); - } - - /** - * - * @param {string} symbolicName symbolic name - * @param {string} version version number - * @return {Promise} resolves to bundle id - */ - getBundleId(symbolicName, version) { - return this.sendCommand(`lb -s "${symbolicName}"`).then(response => { - const lines = response.split('\n'); - - const bundleLine = lines.find( - line => line.indexOf(`|${symbolicName} (${version})`) != -1 - ); - - if (!bundleLine) { - throw new Error(response); - } - - const fields = bundleLine.split('|'); - - return Number.parseInt(fields[0], 10); - }); - } -} diff --git a/packages/liferay-npm-build-support/src/scripts/__tests__/translate.test.js b/packages/liferay-npm-build-support/src/scripts/__tests__/translate.test.ts similarity index 100% rename from packages/liferay-npm-build-support/src/scripts/__tests__/translate.test.js rename to packages/liferay-npm-build-support/src/scripts/__tests__/translate.test.ts diff --git a/packages/liferay-npm-build-support/src/scripts/build/index.js b/packages/liferay-npm-build-support/src/scripts/build/index.ts similarity index 100% rename from packages/liferay-npm-build-support/src/scripts/build/index.js rename to packages/liferay-npm-build-support/src/scripts/build/index.ts diff --git a/packages/liferay-npm-build-support/src/scripts/copy-assets.js b/packages/liferay-npm-build-support/src/scripts/copy-assets.ts similarity index 100% rename from packages/liferay-npm-build-support/src/scripts/copy-assets.js rename to packages/liferay-npm-build-support/src/scripts/copy-assets.ts diff --git a/packages/liferay-npm-build-support/src/scripts/copy-sources.js b/packages/liferay-npm-build-support/src/scripts/copy-sources.ts similarity index 100% rename from packages/liferay-npm-build-support/src/scripts/copy-sources.js rename to packages/liferay-npm-build-support/src/scripts/copy-sources.ts diff --git a/packages/liferay-npm-build-support/src/scripts/deploy.js b/packages/liferay-npm-build-support/src/scripts/deploy.ts similarity index 100% rename from packages/liferay-npm-build-support/src/scripts/deploy.js rename to packages/liferay-npm-build-support/src/scripts/deploy.ts diff --git a/packages/liferay-npm-build-support/src/scripts/start.js b/packages/liferay-npm-build-support/src/scripts/start.ts similarity index 91% rename from packages/liferay-npm-build-support/src/scripts/start.js rename to packages/liferay-npm-build-support/src/scripts/start.ts index fa3e98af..cecc8985 100644 --- a/packages/liferay-npm-build-support/src/scripts/start.js +++ b/packages/liferay-npm-build-support/src/scripts/start.ts @@ -4,7 +4,7 @@ */ import childProcess from 'child_process'; -import project from 'liferay-npm-build-tools-common/lib/project'; +import project, {PkgJson} from 'liferay-npm-build-tools-common/lib/project'; import os from 'os'; import path from 'path'; import util from 'util'; @@ -45,6 +45,7 @@ function copyWebpackResources() { rules: util.inspect( cfg.getWebpackRules().map(rule => { rule.test = new RegExp(rule.test); + return rule; }) ), @@ -56,7 +57,7 @@ function copyWebpackResources() { * Get the portlet's CSS path from package.json * @return {string} */ -function getCssPath() { +function getCssPath(pkgJson: PkgJson) { if ( !pkgJson['portlet'] || !pkgJson['portlet']['com.liferay.portlet.header-portlet-css'] @@ -64,7 +65,9 @@ function getCssPath() { return undefined; } - let path = pkgJson['portlet']['com.liferay.portlet.header-portlet-css']; + let path = pkgJson['portlet'][ + 'com.liferay.portlet.header-portlet-css' + ] as string; if (path.charAt(0) !== '/') { path = `/${path}`; diff --git a/packages/liferay-npm-build-support/src/scripts/translate.js b/packages/liferay-npm-build-support/src/scripts/translate.ts similarity index 97% rename from packages/liferay-npm-build-support/src/scripts/translate.js rename to packages/liferay-npm-build-support/src/scripts/translate.ts index 6f6bc727..76391cdc 100644 --- a/packages/liferay-npm-build-support/src/scripts/translate.js +++ b/packages/liferay-npm-build-support/src/scripts/translate.ts @@ -30,7 +30,7 @@ export default function() { subscriptionKey = cfg.getTranslatorTextKey(); } - if (!subscriptionKey || subscriptionKey == '') { + if (!subscriptionKey || subscriptionKey === '') { console.error( '-------------------------------------------------------------\n' + ' 🛑 Microsoft Translator credentials not set 🛑\n\n' + @@ -53,7 +53,7 @@ export default function() { locale => locale != 'default' ); - if (locales.length == 0) { + if (locales.length === 0) { console.log( 'No locales found: nothing to translate.\n\n' + 'You can edit your .npmbuildrc file to add new supported ' + @@ -127,7 +127,7 @@ export function addMissingTranslations(translation, labels) { }); console.log( - count == 0 + count === 0 ? ` · No missing translations found for locale ${locale}` : ` · Added ${count} missing translations for locale ${locale}` ); @@ -224,7 +224,7 @@ function showMissingSupportedLocales() { const supportedLocales = cfg.getSupportedLocales(); const missingLocales = availableLocales.filter( - locale => supportedLocales.indexOf(locale) == -1 + locale => supportedLocales.indexOf(locale) === -1 ); if (missingLocales.length > 0) { @@ -248,7 +248,7 @@ function createMissingSupportedLocalesFiles() { const supportedLocales = cfg.getSupportedLocales(); const missingLocales = supportedLocales.filter( - locale => project.l10n.availableLocales.indexOf(locale) == -1 + locale => project.l10n.availableLocales.indexOf(locale) === -1 ); if (missingLocales.length > 0) { diff --git a/packages/liferay-npm-build-support/src/util.js b/packages/liferay-npm-build-support/src/util.ts similarity index 89% rename from packages/liferay-npm-build-support/src/util.js rename to packages/liferay-npm-build-support/src/util.ts index 3928f3d3..43040dfc 100644 --- a/packages/liferay-npm-build-support/src/util.js +++ b/packages/liferay-npm-build-support/src/util.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: LGPL-3.0-or-later */ -import child_process from 'child_process'; +import childProcess from 'child_process'; import spawn from 'cross-spawn'; import ejs from 'ejs'; import fs from 'fs-extra'; @@ -31,7 +31,7 @@ export class Renderer { * @param {string} dir optional relative directory in output path * @param {string} name optional output file name */ - render(templatePath, data = {}, {dir = '', name} = {}) { + render(templatePath, data = {}, {dir = '', name = undefined} = {}) { dir = path.join(this._outputPath, dir); name = name || templatePath; @@ -50,6 +50,9 @@ export class Renderer { } ); } + + private readonly _templatesPath: string; + private readonly _outputPath: string; } /** @@ -91,7 +94,7 @@ export function runPkgJsonScript(script, args = []) { args = ['--'].concat(args); } - const proc = child_process.spawnSync(pkgManager, ['run', script, ...args], { + const proc = childProcess.spawnSync(pkgManager, ['run', script, ...args], { shell: true, stdio: 'inherit', }); diff --git a/packages/liferay-npm-build-support/tsconfig.json b/packages/liferay-npm-build-support/tsconfig.json index bc90c2a6..47453166 100644 --- a/packages/liferay-npm-build-support/tsconfig.json +++ b/packages/liferay-npm-build-support/tsconfig.json @@ -1,8 +1,9 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "references": [{"path": "../liferay-npm-build-tools-common"}] } diff --git a/packages/liferay-npm-build-tools-common/package.json b/packages/liferay-npm-build-tools-common/package.json index 16cd38a9..6cb70abf 100644 --- a/packages/liferay-npm-build-tools-common/package.json +++ b/packages/liferay-npm-build-tools-common/package.json @@ -2,9 +2,11 @@ "name": "liferay-npm-build-tools-common", "version": "3.0.0", "description": "Utility library for Liferay NPM Build Tools.", + "license": "LGPL-3.0", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "node ../../scripts/disable-publish.js", "release:snapshot": "node ../../scripts/release-snapshot.js" }, diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/imports.test.js.snap b/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/imports.test.ts.snap similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/imports.test.js.snap rename to packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/imports.test.ts.snap diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.js.snap b/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.ts.snap similarity index 55% rename from packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.js.snap rename to packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.ts.snap index 5950e8f5..c56b17a8 100644 --- a/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.js.snap +++ b/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/manifest.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`addPackage/getPackage work 1`] = ` +exports[`addPackage works 1`] = ` Object { "dest": Object { "dir": "./dest", @@ -17,41 +17,6 @@ Object { } `; -exports[`constructor with file works 1`] = ` -"{ - \\"packages\\": { - \\"a-package@1.0.0\\": { - \\"dest\\": { - \\"dir\\": \\"./dest-1\\", - \\"id\\": \\"a-package@1.0.0\\", - \\"name\\": \\"a-package\\", - \\"version\\": \\"1.0.0\\" - }, - \\"src\\": { - \\"dir\\": \\"./src-1\\", - \\"id\\": \\"a-package@1.0.0\\", - \\"name\\": \\"a-package\\", - \\"version\\": \\"1.0.0\\" - } - }, - \\"a-package@2.0.0\\": { - \\"dest\\": { - \\"dir\\": \\"./dest-2\\", - \\"id\\": \\"a-package@2.0.0\\", - \\"name\\": \\"a-package\\", - \\"version\\": \\"2.0.0\\" - }, - \\"src\\": { - \\"dir\\": \\"./src-2\\", - \\"id\\": \\"a-package@2.0.0\\", - \\"name\\": \\"a-package\\", - \\"version\\": \\"2.0.0\\" - } - } - } -}" -`; - exports[`save works 1`] = ` "{ \\"packages\\": { diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/plugin-logger.test.js.snap b/packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/plugin-logger.test.ts.snap similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/plugin-logger.test.js.snap rename to packages/liferay-npm-build-tools-common/src/__tests__/__snapshots__/plugin-logger.test.ts.snap diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.ts similarity index 80% rename from packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.ts index e326dde9..3498cb4e 100644 --- a/packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.js +++ b/packages/liferay-npm-build-tools-common/src/__tests__/babel-ipc.test.ts @@ -16,7 +16,7 @@ const state = { beforeEach(() => { babelIpc.clear(filePath); - expect(babelIpc.get(state)).toBeUndefined(); + expect(babelIpc.get(state, undefined)).toBeUndefined(); }); it('set/get works', () => { @@ -24,7 +24,7 @@ it('set/get works', () => { babelIpc.set(filePath, value); - expect(babelIpc.get(state)).toBe(value); + expect(babelIpc.get(state, undefined)).toBe(value); }); it('get with default value works', () => { @@ -45,9 +45,9 @@ it('clear works', () => { babelIpc.set(filePath, value); - expect(babelIpc.get(state)).toBe(value); + expect(babelIpc.get(state, undefined)).toBe(value); babelIpc.clear(filePath); - expect(babelIpc.get(state)).toBeUndefined(); + expect(babelIpc.get(state, undefined)).toBeUndefined(); }); diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.ts similarity index 81% rename from packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.ts index 2958f179..4a27e19e 100644 --- a/packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.js +++ b/packages/liferay-npm-build-tools-common/src/__tests__/file-path.test.ts @@ -9,11 +9,11 @@ const savedNativeIsPosix = FilePath.nativeIsPosix; describe('in posix systems', () => { beforeEach(() => { - FilePath.nativeIsPosix = true; + (FilePath as object)['nativeIsPosix'] = true; }); afterEach(() => { - FilePath.nativeIsPosix = savedNativeIsPosix; + (FilePath as object)['nativeIsPosix'] = savedNativeIsPosix; }); it('toString works', () => { @@ -41,11 +41,11 @@ describe('in posix systems', () => { describe('in windows systems', () => { beforeEach(() => { - FilePath.nativeIsPosix = false; + (FilePath as object)['nativeIsPosix'] = false; }); afterEach(() => { - FilePath.nativeIsPosix = savedNativeIsPosix; + (FilePath as object)['nativeIsPosix'] = savedNativeIsPosix; }); it('toString works', () => { @@ -74,17 +74,17 @@ describe('in windows systems', () => { describe('posix constructor', () => { it('works in posix systems', () => { - FilePath.nativeIsPosix = true; + (FilePath as object)['nativeIsPosix'] = true; const filePath = new FilePath('/tmp/tt', {posix: true}); - FilePath.nativeIsPosix = savedNativeIsPosix; + (FilePath as object)['nativeIsPosix'] = savedNativeIsPosix; expect(filePath.asNative).toEqual('/tmp/tt'); }); it('works in windows systems', () => { - FilePath.nativeIsPosix = false; + (FilePath as object)['nativeIsPosix'] = false; const filePath = new FilePath('/tmp/tt', {posix: true}); - FilePath.nativeIsPosix = savedNativeIsPosix; + (FilePath as object)['nativeIsPosix'] = savedNativeIsPosix; expect(filePath.asNative).toEqual('\\tmp\\tt'); }); diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/globs.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/globs.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/globs.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/globs.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/imports.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/imports.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/imports.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/imports.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.js deleted file mode 100644 index 69794eed..00000000 --- a/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.js +++ /dev/null @@ -1,162 +0,0 @@ -/** - * SPDX-FileCopyrightText: © 2017 Liferay, Inc. - * SPDX-License-Identifier: LGPL-3.0-or-later - */ - -import fs from 'fs'; -import path from 'path'; - -import Manifest from '../manifest'; -import PkgDesc from '../pkg-desc'; - -it('addPackage/getPackage work', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', './src'); - const destPkg = new PkgDesc('a-package', '1.0.0', './dest'); - - manifest.addPackage(srcPkg, destPkg); - - expect(manifest.getPackage(srcPkg)).toMatchSnapshot(); -}); - -it('getPackage returns entries with relative paths', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', path.resolve('./src')); - const destPkg = new PkgDesc('a-package', '1.0.0', path.resolve('./dest')); - - manifest.addPackage(srcPkg, destPkg); - - const entry = manifest.getPackage(srcPkg); - - expect(entry.src.dir).toBe('./src'); - expect(entry.dest.dir).toBe('./dest'); -}); - -describe('save', () => { - it('works', () => { - const manifest = new Manifest(); - - const srcPkg1 = new PkgDesc('a-package', '1.0.0', './src-1'); - const destPkg1 = new PkgDesc('a-package', '1.0.0', './dest-1'); - - const srcPkg2 = new PkgDesc('a-package', '2.0.0', './src-2'); - const destPkg2 = new PkgDesc('a-package', '2.0.0', './dest-2'); - - manifest.addPackage(srcPkg1, destPkg1); - manifest.addPackage(srcPkg2, destPkg2); - - const tmpDir = fs.mkdtempSync('manifest'); - const tmpFilePath = path.join(tmpDir, 'manifest.json'); - - manifest.save(tmpFilePath); - - expect(fs.readFileSync(tmpFilePath).toString()).toMatchSnapshot(); - - fs.unlinkSync(tmpFilePath); - fs.rmdirSync(tmpDir); - }); - - it('throws if called with no path and no default file path is set', () => { - const manifest = new Manifest(); - - expect(() => manifest.save()).toThrow(); - }); -}); - -it('constructor with file works', () => { - const tmpDir = fs.mkdtempSync('manifest'); - const tmpFilePath = path.join(tmpDir, 'manifest.json'); - - const manifest = new Manifest(tmpFilePath); - - const srcPkg1 = new PkgDesc('a-package', '1.0.0', './src-1'); - const destPkg1 = new PkgDesc('a-package', '1.0.0', './dest-1'); - - const srcPkg2 = new PkgDesc('a-package', '2.0.0', './src-2'); - const destPkg2 = new PkgDesc('a-package', '2.0.0', './dest-2'); - - manifest.addPackage(srcPkg1, destPkg1); - manifest.addPackage(srcPkg2, destPkg2); - - manifest.save(); - - const manifest2 = new Manifest(tmpFilePath); - - expect(manifest2.toJSON()).toMatchSnapshot(); - - fs.unlinkSync(tmpFilePath); - fs.rmdirSync(tmpDir); -}); - -describe('isOutdated', () => { - it('returns false for up-to-date packages', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', './src'); - const destPkg = new PkgDesc('a-package', '1.0.0', '.'); - - manifest.addPackage(srcPkg, destPkg); - - expect(manifest.isOutdated(srcPkg)).toBe(false); - }); - - // TODO: This test can be removed if we implement enhanced outdated detection by using timestamps/digests. - // However, we are not sure that it is the bundler's responsibility to detect such modifications as it is - // more a multi-tool build issue that may happen with other configurations. - it('returns true for root package no matter what', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', './src', true); - const destPkg = new PkgDesc('a-package', '1.0.0', '.', true); - - manifest.addPackage(srcPkg, destPkg); - - expect(manifest.isOutdated(srcPkg)).toBe(true); - }); - - it('returns true for unregistered packages', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', './src'); - - expect(manifest.isOutdated(srcPkg)).toBe(true); - }); - - it('returns true for packages with missing destination directory', () => { - const manifest = new Manifest(); - - const srcPkg = new PkgDesc('a-package', '1.0.0', './src'); - const destPkg = new PkgDesc('a-package', '1.0.0', './non-existing-dir'); - - manifest.addPackage(srcPkg, destPkg); - - expect(manifest.isOutdated(srcPkg)).toBe(true); - }); -}); - -describe('toJSON', () => { - it('sorts keys alphabetically', () => { - const manifest = new Manifest(); - - const srcPkg1 = new PkgDesc('a-package', '1.0.0', './src-1'); - const destPkg1 = new PkgDesc('a-package', '1.0.0', './dest-1'); - - const srcPkg2 = new PkgDesc('z-package', '2.0.0', './src-2'); - const destPkg2 = new PkgDesc('z-package', '2.0.0', './dest-2'); - - manifest.addPackage(srcPkg2, destPkg2); - manifest.addPackage(srcPkg1, destPkg1); - - manifest.addModuleFlags(srcPkg2, 'z-module', {flag: true}); - manifest.addModuleFlags(srcPkg2, 'a-module', {flag: true}); - - const json = manifest.toJSON(); - - expect(json.indexOf('a-package')).toBeLessThan( - json.indexOf('z-package') - ); - expect(json.indexOf('a-module')).toBeLessThan(json.indexOf('z-module')); - }); -}); diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.ts b/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.ts new file mode 100644 index 00000000..85301f40 --- /dev/null +++ b/packages/liferay-npm-build-tools-common/src/__tests__/manifest.test.ts @@ -0,0 +1,85 @@ +/** + * SPDX-FileCopyrightText: © 2017 Liferay, Inc. + * SPDX-License-Identifier: LGPL-3.0-or-later + */ + +import fs from 'fs'; +import path from 'path'; + +import Manifest from '../manifest'; +import PkgDesc from '../pkg-desc'; + +it('addPackage works', () => { + const manifest = new Manifest(); + + const srcPkg = new PkgDesc('a-package', '1.0.0', './src'); + const destPkg = new PkgDesc('a-package', '1.0.0', './dest'); + + manifest.addPackage(srcPkg, destPkg); + + expect((manifest as any)._data.packages[srcPkg.id]).toMatchSnapshot(); +}); + +it('getPackage returns entries with relative paths', () => { + const manifest = new Manifest(); + + const srcPkg = new PkgDesc('a-package', '1.0.0', path.resolve('./src')); + const destPkg = new PkgDesc('a-package', '1.0.0', path.resolve('./dest')); + + manifest.addPackage(srcPkg, destPkg); + + const entry = (manifest as any)._data.packages[srcPkg.id]; + + expect(entry.src.dir).toBe('./src'); + expect(entry.dest.dir).toBe('./dest'); +}); + +describe('save', () => { + it('works', () => { + const manifest = new Manifest(); + + const srcPkg1 = new PkgDesc('a-package', '1.0.0', './src-1'); + const destPkg1 = new PkgDesc('a-package', '1.0.0', './dest-1'); + + const srcPkg2 = new PkgDesc('a-package', '2.0.0', './src-2'); + const destPkg2 = new PkgDesc('a-package', '2.0.0', './dest-2'); + + manifest.addPackage(srcPkg1, destPkg1); + manifest.addPackage(srcPkg2, destPkg2); + + const tmpDir = fs.mkdtempSync('manifest'); + const tmpFilePath = path.join(tmpDir, 'manifest.json'); + + manifest.save(tmpFilePath); + + expect(fs.readFileSync(tmpFilePath).toString()).toMatchSnapshot(); + + fs.unlinkSync(tmpFilePath); + fs.rmdirSync(tmpDir); + }); +}); + +describe('toJSON', () => { + it('sorts keys alphabetically', () => { + const manifest = new Manifest(); + + const srcPkg1 = new PkgDesc('a-package', '1.0.0', './src-1'); + const destPkg1 = new PkgDesc('a-package', '1.0.0', './dest-1'); + + const srcPkg2 = new PkgDesc('z-package', '2.0.0', './src-2'); + const destPkg2 = new PkgDesc('z-package', '2.0.0', './dest-2'); + + manifest.addPackage(srcPkg2, destPkg2); + manifest.addPackage(srcPkg1, destPkg1); + + manifest.addModuleFlags(srcPkg2.id, 'z-module', {esModule: true}); + manifest.addModuleFlags(srcPkg2.id, 'a-module', {esModule: true}); + + const json = manifest.toJSON(); + + expect(json.indexOf('a-package')).toBeLessThan( + json.indexOf('z-package') + ); + expect(json.indexOf('a-module')).toBeLessThan(json.indexOf('z-module')); + }); +}); diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/modules.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/modules.test.ts similarity index 94% rename from packages/liferay-npm-build-tools-common/src/__tests__/modules.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/modules.test.ts index b0098908..4eb14e8f 100644 --- a/packages/liferay-npm-build-tools-common/src/__tests__/modules.test.js +++ b/packages/liferay-npm-build-tools-common/src/__tests__/modules.test.ts @@ -49,13 +49,13 @@ it('joinModuleName() works', () => { expect(mod.joinModuleName('@a-scope', 'a-package', '/a-dir/a-module')).toBe( '@a-scope/a-package/a-dir/a-module' ); - expect(mod.joinModuleName('@a-scope', 'a-package')).toBe( + expect(mod.joinModuleName('@a-scope', 'a-package', '')).toBe( '@a-scope/a-package' ); expect(mod.joinModuleName(undefined, 'a-package', '/a-dir/a-module')).toBe( 'a-package/a-dir/a-module' ); - expect(mod.joinModuleName(undefined, 'a-package')).toBe('a-package'); + expect(mod.joinModuleName(undefined, 'a-package', '')).toBe('a-package'); }); it('splitModuleName() works', () => { diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/namespace.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/namespace.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/namespace.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/namespace.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/packages.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/packages.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/packages.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/packages.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/pkg-desc.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/pkg-desc.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/pkg-desc.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/pkg-desc.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/__tests__/plugin-logger.test.js b/packages/liferay-npm-build-tools-common/src/__tests__/plugin-logger.test.ts similarity index 100% rename from packages/liferay-npm-build-tools-common/src/__tests__/plugin-logger.test.js rename to packages/liferay-npm-build-tools-common/src/__tests__/plugin-logger.test.ts diff --git a/packages/liferay-npm-build-tools-common/src/imports.ts b/packages/liferay-npm-build-tools-common/src/imports.ts index 509e0e96..4238a6c6 100644 --- a/packages/liferay-npm-build-tools-common/src/imports.ts +++ b/packages/liferay-npm-build-tools-common/src/imports.ts @@ -84,7 +84,7 @@ export function normalizeImportsConfig( delete normalized[namespace][pkgName]; - if (Object.keys(normalized[namespace]).length == 0) { + if (Object.keys(normalized[namespace]).length === 0) { delete normalized[namespace]; } } diff --git a/packages/liferay-npm-build-tools-common/src/manifest.ts b/packages/liferay-npm-build-tools-common/src/manifest.ts index 5b52bc94..145fe4ca 100644 --- a/packages/liferay-npm-build-tools-common/src/manifest.ts +++ b/packages/liferay-npm-build-tools-common/src/manifest.ts @@ -7,9 +7,7 @@ import fs from 'fs-extra'; import path from 'path'; import {Manifest as Data, ModuleFlags, Package} from './api/manifest'; -import FilePath from './file-path'; import PkgDesc from './pkg-desc'; -import project from './project'; export {ModuleFlags, Package}; @@ -18,39 +16,12 @@ export {ModuleFlags, Package}; * it to/from disk. */ export default class Manifest { - /** - * @param filePath an optional path to a file to load initial status - */ - constructor(filePath: string = null) { - this._loadedFromFile = false; - - if (filePath) { - this._filePath = filePath; - - try { - this._data = JSON.parse(fs.readFileSync(filePath).toString()); - this._loadedFromFile = true; - - return; - } catch (err) { - if (err.code !== 'ENOENT') { - throw err; - } - } - } - + constructor() { this._data = { packages: {}, }; } - /** - * Set to true when the manifest has been loaded from a file. - */ - get loadedFromFile(): boolean { - return this._loadedFromFile; - } - /** * Add a processed package entry * @param srcPkg the source package descriptor @@ -104,56 +75,11 @@ export default class Manifest { Object.assign(pkg.modules[moduleName].flags, flags); } - /** - * Get a processed package entry - * @param srcPkg the source package descriptor - * @return the processed package entry (see addPackage for format description) - */ - getPackage(srcPkg: PkgDesc): Package { - return this._data.packages[srcPkg.id]; - } - - /** - * Tests whether a package must be regenerated - * @param destPkg destination package - * @return true if package is outdated - */ - isOutdated(destPkg: PkgDesc): boolean { - // Unless we use real timestamps or digests, we cannot detect reliably - // if the root package is outdated or up-to-date. - if (destPkg.isRoot) { - return true; - } - - const entry = this._data.packages[destPkg.id]; - - if (entry === undefined) { - return true; - } - - if ( - !fs.existsSync( - project.dir.join(new FilePath(entry.dest.dir, {posix: true})) - .asNative - ) - ) { - return true; - } - - return false; - } - /** * Save current manifest to a file - * @param filePath path to file or null to use default path + * @param filePath path to file */ - save(filePath: string = null): void { - filePath = filePath || this._filePath; - - if (filePath === undefined) { - throw new Error('No file path given and no default path set'); - } - + save(filePath: string): void { fs.ensureDirSync(path.dirname(filePath)); fs.writeFileSync(filePath, this.toJSON()); } @@ -165,8 +91,6 @@ export default class Manifest { return JSON.stringify(this._data, sortObjectKeysReplacer, 2); } - private _loadedFromFile: boolean; - private _filePath: string; private _data: Data; } diff --git a/packages/liferay-npm-build-tools-common/src/pkg-desc.ts b/packages/liferay-npm-build-tools-common/src/pkg-desc.ts index 8f2420f2..5650b25d 100644 --- a/packages/liferay-npm-build-tools-common/src/pkg-desc.ts +++ b/packages/liferay-npm-build-tools-common/src/pkg-desc.ts @@ -95,7 +95,7 @@ export default class PkgDesc { } get isRoot(): boolean { - return this.id == PkgDesc.ROOT_ID; + return this.id === PkgDesc.ROOT_ID; } private _clean: boolean; diff --git a/packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.js b/packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.ts similarity index 96% rename from packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.js rename to packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.ts index 51f1af90..2f80ce01 100644 --- a/packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.js +++ b/packages/liferay-npm-build-tools-common/src/project/__tests__/index.test.ts @@ -287,9 +287,10 @@ describe('project.pkgManager', () => { path.join(__dirname, '__fixtures__', 'pkg-manager', 'none') ); - child_process.spawnSync = cmd => ({ - error: cmd === 'npm' ? undefined : {}, - }); + child_process.spawnSync = cmd => + ({ + error: cmd === 'npm' ? undefined : {}, + } as any); expect(project.pkgManager).toBe('npm'); }); @@ -299,9 +300,10 @@ describe('project.pkgManager', () => { path.join(__dirname, '__fixtures__', 'pkg-manager', 'none') ); - child_process.spawnSync = cmd => ({ - error: cmd === 'yarn' ? undefined : {}, - }); + child_process.spawnSync = cmd => + ({ + error: cmd === 'yarn' ? undefined : {}, + } as any); expect(project.pkgManager).toBe('yarn'); }); @@ -311,9 +313,10 @@ describe('project.pkgManager', () => { path.join(__dirname, '__fixtures__', 'pkg-manager', 'both') ); - child_process.spawnSync = cmd => ({ - error: cmd === 'npm' ? undefined : {}, - }); + child_process.spawnSync = cmd => + ({ + error: cmd === 'npm' ? undefined : {}, + } as any); expect(project.pkgManager).toBe('npm'); }); @@ -323,9 +326,10 @@ describe('project.pkgManager', () => { path.join(__dirname, '__fixtures__', 'pkg-manager', 'both') ); - child_process.spawnSync = cmd => ({ - error: cmd === 'yarn' ? undefined : {}, - }); + child_process.spawnSync = cmd => + ({ + error: cmd === 'yarn' ? undefined : {}, + } as any); expect(project.pkgManager).toBe('yarn'); }); @@ -335,9 +339,10 @@ describe('project.pkgManager', () => { path.join(__dirname, '__fixtures__', 'pkg-manager', 'both') ); - child_process.spawnSync = () => ({ - error: undefined, - }); + child_process.spawnSync = () => + ({ + error: undefined, + } as any); expect(project.pkgManager).toBeNull(); }); diff --git a/packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.js b/packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.ts similarity index 98% rename from packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.js rename to packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.ts index 61692827..c13595bf 100644 --- a/packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.js +++ b/packages/liferay-npm-build-tools-common/src/project/__tests__/rules.test.ts @@ -20,7 +20,7 @@ describe('single rule', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.css')).toEqual([ { @@ -49,7 +49,7 @@ describe('single rule', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.css')).toEqual([ { @@ -80,7 +80,7 @@ describe('single rule', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.css')).toEqual([ { @@ -116,7 +116,7 @@ describe('single rule', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.css')).toEqual([ { @@ -153,7 +153,7 @@ it('works with rules not based in file extension', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('a-folder/main.js')).toEqual([ { @@ -187,7 +187,7 @@ it('multiple rules', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.css')).toEqual([ { @@ -232,7 +232,7 @@ it('rule with options', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.js')).toEqual([ { @@ -275,7 +275,7 @@ it('retrieves loader metadata', () => { ], }, toolRequire: () => requireReturn, - }); + } as any); expect(rules.loadersForFile('main.js')).toEqual([ { diff --git a/packages/liferay-npm-build-tools-common/src/project/index.ts b/packages/liferay-npm-build-tools-common/src/project/index.ts index 6fc6e98d..e53f4633 100644 --- a/packages/liferay-npm-build-tools-common/src/project/index.ts +++ b/packages/liferay-npm-build-tools-common/src/project/index.ts @@ -451,6 +451,31 @@ export class Project { } } + /** + * Get directory where work files must be placed. + * + * @remarks + * Work files are files that can be cached between different builds to speed + * the process or simply because they can help in debugging a failed build. + * + * @return the work dir or undefined if not configured + */ + get workDir(): FilePath | undefined { + if (this._workDir === undefined) { + let dir = prop.get(this._configuration, 'work-dir', undefined); + + if (dir) { + if (!dir.startsWith('./')) { + dir = `./${dir}`; + } + + this._workDir = new FilePath(dir, {posix: true}); + } + } + + return this._workDir; + } + _loadConfiguration(): void { const {_configFile} = this; const configDir = _configFile.dirname(); @@ -506,6 +531,8 @@ export class Project { private _webpackConfiguration: webpack.Configuration; private _versionsInfo: Map; + + private _workDir: FilePath; } export default new Project('.'); diff --git a/packages/liferay-npm-build-tools-common/src/project/misc.ts b/packages/liferay-npm-build-tools-common/src/project/misc.ts index 0fd988c5..8da2e762 100644 --- a/packages/liferay-npm-build-tools-common/src/project/misc.ts +++ b/packages/liferay-npm-build-tools-common/src/project/misc.ts @@ -7,6 +7,16 @@ import {Project} from '.'; import prop from 'dot-prop'; import FilePath from '../file-path'; +import {print, warn} from '../format'; + +/** Valid log levels for console and report */ +export enum LogLevel { + off = 0, + error = 1, + warn = 2, + info = 3, + debug = 4, +} /** * Reflects miscellaneous project configuration values. @@ -14,19 +24,37 @@ import FilePath from '../file-path'; export default class Misc { /** * - * @param {Project} project + * @param project */ - constructor(project) { + constructor(project: Project) { this._project = project; } /** * Whether or not to dump detailed information about what the tool is doing */ - get logLevel(): 'off' | 'error' | 'warn' | 'info' | 'debug' { - const {npmbundlerrc} = this._project; + get logLevel(): LogLevel { + if (this._logLevel === undefined) { + const {npmbundlerrc} = this._project; + + let logLevel = prop.get( + npmbundlerrc, + 'log-level', + LogLevel[LogLevel.warn] + ); + + if (LogLevel[logLevel] === undefined) { + print( + warn`Configuration value {log-level} has invalid value: it will be ignored` + ); + + logLevel = LogLevel[LogLevel.warn]; + } + + this._logLevel = LogLevel[logLevel]; + } - return prop.get(npmbundlerrc, 'log-level', 'warn'); + return this._logLevel; } /** @@ -35,36 +63,94 @@ export default class Misc { */ get maxParallelFiles(): number { - const {npmbundlerrc} = this._project; - - // Default values for "ulimit -n" vary across different OSes. Some - // - // values I have found are: - // - Apparently Mac OS X limit is 256 but usually people increase it - // - Fedora: 1024 - // - Windows: there's no ulimit, but MSVCRT.DLL has a 2048 limit - // - // Given this mess and the impossibility of retrieving the limit from - // Node, I'm giving this a default value of 128 because it looks like it - // doesn't impact performance and should be low enough to make it work - // in all OSes. - return prop.get(npmbundlerrc, 'max-parallel-files', 128); + if (this._maxParallelFiles === undefined) { + const {npmbundlerrc} = this._project; + + // Default values for "ulimit -n" vary across different OSes. Some + // + // values I have found are: + // - Apparently Mac OS X limit is 256 but usually people increase it + // - Fedora: 1024 + // - Windows: there's no ulimit, but MSVCRT.DLL has a 2048 limit + // + // Given this mess and the impossibility of retrieving the limit from + // Node, I'm giving this a default value of 128 because it looks like it + // doesn't impact performance and should be low enough to make it work + // in all OSes. + let maxParallelFiles: string = prop.get( + npmbundlerrc, + 'max-parallel-files', + '128' + ); + + if (parseInt(maxParallelFiles, 10) === Number.NaN) { + print( + warn`Configuration value {max-parallel-files} has invalid value: it will be ignored` + ); + + maxParallelFiles = '128'; + } + + this._maxParallelFiles = parseInt(maxParallelFiles, 10); + } + + return this._maxParallelFiles; } /** * Get the path to the report file or undefined if no report is configured. */ - get reportFile(): FilePath | undefined { - const {_project} = this; - const {npmbundlerrc} = _project; + if (this._reportFile === undefined) { + const {_project} = this; + const {npmbundlerrc} = _project; + + const dumpReport = prop.get(npmbundlerrc, 'dump-report', false); + + this._reportFile = dumpReport + ? _project.dir.join('liferay-npm-bundler-report.html') + : undefined; + } + + return this._reportFile; + } + + /** + * Get report log level + */ + get reportLevel(): LogLevel { + if (this._reportLevel === undefined) { + const {_project} = this; + const {npmbundlerrc} = _project; + + let dumpReport = prop.get( + npmbundlerrc, + 'dump-report', + false + ); + + if (typeof dumpReport === 'boolean') { + if (dumpReport) { + dumpReport = LogLevel[LogLevel.info]; + } else { + dumpReport = LogLevel[LogLevel.off]; + } + } else if (LogLevel[dumpReport] === undefined) { + print( + warn`Configuration value {dump-report} has invalid value: it will be ignored` + ); + dumpReport = LogLevel[LogLevel.off]; + } - const dumpReport = prop.get(npmbundlerrc, 'dump-report', false); + this._reportLevel = LogLevel[dumpReport]; + } - return dumpReport - ? _project.dir.join('liferay-npm-bundler-report.html') - : undefined; + return this._reportLevel; } private readonly _project: Project; + private _logLevel: LogLevel; + private _maxParallelFiles: number; + private _reportFile: FilePath; + private _reportLevel: LogLevel; } diff --git a/packages/liferay-npm-build-tools-common/tsconfig.json b/packages/liferay-npm-build-tools-common/tsconfig.json index 94a4b356..e76aebd0 100644 --- a/packages/liferay-npm-build-tools-common/tsconfig.json +++ b/packages/liferay-npm-build-tools-common/tsconfig.json @@ -1,11 +1,10 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "composite": true, + "declaration": true, "outDir": "./lib", - - "allowJs": false, - "declaration": true + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-babel-loader/package.json b/packages/liferay-npm-bundler-loader-babel-loader/package.json index cdb012f6..08190f27 100644 --- a/packages/liferay-npm-bundler-loader-babel-loader/package.json +++ b/packages/liferay-npm-bundler-loader-babel-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-babel-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that runs Babel on source files.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-babel-loader/src/__tests__/index.test.js b/packages/liferay-npm-bundler-loader-babel-loader/src/__tests__/index.test.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-babel-loader/src/__tests__/index.test.js rename to packages/liferay-npm-bundler-loader-babel-loader/src/__tests__/index.test.ts diff --git a/packages/liferay-npm-bundler-loader-babel-loader/src/index.js b/packages/liferay-npm-bundler-loader-babel-loader/src/index.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-babel-loader/src/index.js rename to packages/liferay-npm-bundler-loader-babel-loader/src/index.ts diff --git a/packages/liferay-npm-bundler-loader-babel-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-babel-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-babel-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-babel-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-copy-loader/package.json b/packages/liferay-npm-bundler-loader-copy-loader/package.json index e772686a..722f004b 100644 --- a/packages/liferay-npm-bundler-loader-copy-loader/package.json +++ b/packages/liferay-npm-bundler-loader-copy-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-copy-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that copies files.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-copy-loader/src/index.js b/packages/liferay-npm-bundler-loader-copy-loader/src/index.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-copy-loader/src/index.js rename to packages/liferay-npm-bundler-loader-copy-loader/src/index.ts diff --git a/packages/liferay-npm-bundler-loader-copy-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-copy-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-copy-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-copy-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-css-loader/package.json b/packages/liferay-npm-bundler-loader-css-loader/package.json index 7056743c..db345b0f 100644 --- a/packages/liferay-npm-bundler-loader-css-loader/package.json +++ b/packages/liferay-npm-bundler-loader-css-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-css-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that turns CSS files into JavaScript modules that inject a into the HTML when they are required.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-css-loader/src/__tests__/__snapshots__/index.test.js.snap b/packages/liferay-npm-bundler-loader-css-loader/src/__tests__/__snapshots__/index.test.ts.snap similarity index 100% rename from packages/liferay-npm-bundler-loader-css-loader/src/__tests__/__snapshots__/index.test.js.snap rename to packages/liferay-npm-bundler-loader-css-loader/src/__tests__/__snapshots__/index.test.ts.snap diff --git a/packages/liferay-npm-bundler-loader-css-loader/src/__tests__/index.test.js b/packages/liferay-npm-bundler-loader-css-loader/src/__tests__/index.test.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-css-loader/src/__tests__/index.test.js rename to packages/liferay-npm-bundler-loader-css-loader/src/__tests__/index.test.ts diff --git a/packages/liferay-npm-bundler-loader-css-loader/src/index.js b/packages/liferay-npm-bundler-loader-css-loader/src/index.ts similarity index 97% rename from packages/liferay-npm-bundler-loader-css-loader/src/index.js rename to packages/liferay-npm-bundler-loader-css-loader/src/index.ts index b66bba8f..a93fb5f9 100644 --- a/packages/liferay-npm-bundler-loader-css-loader/src/index.js +++ b/packages/liferay-npm-bundler-loader-css-loader/src/index.ts @@ -14,7 +14,7 @@ import readJsonSync from 'read-json-sync'; */ export default function( context, - {extension, namespaceDependencies = true, pathModule = '/o'} + {extension = undefined, namespaceDependencies = true, pathModule = '/o'} ) { const {filePath, log} = context; @@ -122,7 +122,7 @@ function getHref(filePath, extension, pathModule, namespaceDependencies) { if (extension !== undefined) { const extname = path.extname(filePath); - if (extname == '') { + if (extname === '') { filePath = `${filePath}.${extension}`; } else { filePath = filePath.replace( diff --git a/packages/liferay-npm-bundler-loader-css-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-css-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-css-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-css-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-json-loader/package.json b/packages/liferay-npm-bundler-loader-json-loader/package.json index c7c0be6c..2a90d892 100644 --- a/packages/liferay-npm-bundler-loader-json-loader/package.json +++ b/packages/liferay-npm-bundler-loader-json-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-json-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that turns JSON files into JavaScript modules that export the parsed JSON object.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/__snapshots__/index.test.js.snap b/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/__snapshots__/index.test.ts.snap similarity index 100% rename from packages/liferay-npm-bundler-loader-json-loader/src/__tests__/__snapshots__/index.test.js.snap rename to packages/liferay-npm-bundler-loader-json-loader/src/__tests__/__snapshots__/index.test.ts.snap diff --git a/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.js b/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.ts similarity index 94% rename from packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.js rename to packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.ts index a8956b20..c354ca11 100644 --- a/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.js +++ b/packages/liferay-npm-bundler-loader-json-loader/src/__tests__/index.test.ts @@ -31,7 +31,7 @@ it('logs results correctly', () => { extraArtifacts: {}, }; - loader(context, {}); + loader(context); expect(context.log.messages).toEqual([ { @@ -50,7 +50,7 @@ it('correctly generates JS module', () => { extraArtifacts: {}, }; - const result = loader(context, {}); + const result = loader(context); expect(result).toBeUndefined(); @@ -66,7 +66,7 @@ it('fails define when JSON is invalid', () => { extraArtifacts: {}, }; - const result = loader(context, {}); + const result = loader(context); expect(result).toBeUndefined(); diff --git a/packages/liferay-npm-bundler-loader-json-loader/src/index.js b/packages/liferay-npm-bundler-loader-json-loader/src/index.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-json-loader/src/index.js rename to packages/liferay-npm-bundler-loader-json-loader/src/index.ts diff --git a/packages/liferay-npm-bundler-loader-json-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-json-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-json-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-json-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-sass-loader/package.json b/packages/liferay-npm-bundler-loader-sass-loader/package.json index 856f4850..d9eb836d 100644 --- a/packages/liferay-npm-bundler-loader-sass-loader/package.json +++ b/packages/liferay-npm-bundler-loader-sass-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-sass-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that runs `sass` or `node-sass` on source files.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-sass-loader/src/__tests__/index.test.js b/packages/liferay-npm-bundler-loader-sass-loader/src/__tests__/index.test.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-sass-loader/src/__tests__/index.test.js rename to packages/liferay-npm-bundler-loader-sass-loader/src/__tests__/index.test.ts diff --git a/packages/liferay-npm-bundler-loader-sass-loader/src/index.js b/packages/liferay-npm-bundler-loader-sass-loader/src/index.ts similarity index 93% rename from packages/liferay-npm-bundler-loader-sass-loader/src/index.js rename to packages/liferay-npm-bundler-loader-sass-loader/src/index.ts index 69f8607f..6825f5c8 100644 --- a/packages/liferay-npm-bundler-loader-sass-loader/src/index.js +++ b/packages/liferay-npm-bundler-loader-sass-loader/src/index.ts @@ -1,6 +1,5 @@ /** - * © 2017 Liferay, Inc. - * + * SPDX-FileCopyrightText: © 2017 Liferay, Inc. * SPDX-License-Identifier: LGPL-3.0-or-later */ @@ -46,7 +45,7 @@ function getRenderer() { rendererSource = 'from loader'; } - const pkgJson = JSON.parse(fs.readFileSync(rendererPkgJsonPath)); + const pkgJson = JSON.parse(fs.readFileSync(rendererPkgJsonPath).toString()); let rendererDescription = `${pkgJson.name} v${pkgJson.version}`; @@ -68,7 +67,7 @@ function changeFilePathExtension(context) { const extname = path.extname(filePath); - if (extname == '') { + if (extname === '') { filePath = `${filePath}.css`; } else { filePath = filePath.replace(new RegExp(`\\${extname}$`), '.css'); @@ -91,7 +90,7 @@ function renderCSS(renderer, content, options) { * @param {string} moduleName module name * @param {string} basedir optional base directory */ -function tryResolve(moduleName, basedir) { +function tryResolve(moduleName, basedir = undefined) { try { return resolveModule.sync(moduleName, { basedir, diff --git a/packages/liferay-npm-bundler-loader-sass-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-sass-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-sass-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-sass-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-loader-style-loader/package.json b/packages/liferay-npm-bundler-loader-style-loader/package.json index 26f28a48..c5564098 100644 --- a/packages/liferay-npm-bundler-loader-style-loader/package.json +++ b/packages/liferay-npm-bundler-loader-style-loader/package.json @@ -2,10 +2,12 @@ "name": "liferay-npm-bundler-loader-style-loader", "version": "3.0.0", "description": "A liferay-npm-bundler loader that turns CSS files into JavaScript modules that inject the CSS into the HTML when they are required.", + "license": "LGPL-3.0", "main": "lib/index.js", "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "yarn build" }, "dependencies": { diff --git a/packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.js b/packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.ts similarity index 94% rename from packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.js rename to packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.ts index 81a391ca..14ae2bc8 100644 --- a/packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.js +++ b/packages/liferay-npm-bundler-loader-style-loader/src/__tests__/index.test.ts @@ -17,7 +17,7 @@ it('logs results correctly', () => { extraArtifacts: {}, }; - loader(context, {}); + loader(context); expect(context.log.messages).toEqual([ { @@ -36,7 +36,7 @@ it('correctly generates JS module', () => { extraArtifacts: {}, }; - const result = loader(context, {}); + const result = loader(context); expect(result).toBeUndefined(); diff --git a/packages/liferay-npm-bundler-loader-style-loader/src/index.js b/packages/liferay-npm-bundler-loader-style-loader/src/index.ts similarity index 100% rename from packages/liferay-npm-bundler-loader-style-loader/src/index.js rename to packages/liferay-npm-bundler-loader-style-loader/src/index.ts diff --git a/packages/liferay-npm-bundler-loader-style-loader/tsconfig.json b/packages/liferay-npm-bundler-loader-style-loader/tsconfig.json index bc90c2a6..5be45a48 100644 --- a/packages/liferay-npm-bundler-loader-style-loader/tsconfig.json +++ b/packages/liferay-npm-bundler-loader-style-loader/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib", + "rootDir": "./src" }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/__tests__/**"] + "include": ["src/**/*"] } diff --git a/packages/liferay-npm-bundler-preset-angular-cli/package.json b/packages/liferay-npm-bundler-preset-angular-cli/package.json index ae4962f2..7aef7ad9 100644 --- a/packages/liferay-npm-bundler-preset-angular-cli/package.json +++ b/packages/liferay-npm-bundler-preset-angular-cli/package.json @@ -2,7 +2,11 @@ "name": "liferay-npm-bundler-preset-angular-cli", "version": "3.0.0", "description": "Configuration for liferay-npm-bundler to integrate with Angular CLI projects", + "license": "LGPL-3.0", "main": "config.json", + "scripts": { + "clean": "node ../../scripts/clean.js" + }, "dependencies": { "liferay-npm-build-support": "3.0.0", "liferay-npm-bundler-loader-babel-loader": "3.0.0", diff --git a/packages/liferay-npm-bundler-preset-create-react-app/package.json b/packages/liferay-npm-bundler-preset-create-react-app/package.json index b63228ba..92f2fbb0 100644 --- a/packages/liferay-npm-bundler-preset-create-react-app/package.json +++ b/packages/liferay-npm-bundler-preset-create-react-app/package.json @@ -2,7 +2,11 @@ "name": "liferay-npm-bundler-preset-create-react-app", "version": "3.0.0", "description": "Configuration for liferay-npm-bundler to integrate with create-react-app projects", + "license": "LGPL-3.0", "main": "config.json", + "scripts": { + "clean": "node ../../scripts/clean.js" + }, "dependencies": { "liferay-npm-bundler-loader-babel-loader": "3.0.0", "liferay-npm-bundler-loader-copy-loader": "3.0.0" diff --git a/packages/liferay-npm-bundler-preset-standard/package.json b/packages/liferay-npm-bundler-preset-standard/package.json index 38963104..eb62508a 100644 --- a/packages/liferay-npm-bundler-preset-standard/package.json +++ b/packages/liferay-npm-bundler-preset-standard/package.json @@ -2,5 +2,9 @@ "name": "liferay-npm-bundler-preset-standard", "version": "3.0.0", "description": "Standard configuration for liferay-npm-bundler.", - "main": "config.json" + "license": "LGPL-3.0", + "main": "config.json", + "scripts": { + "clean": "node ../../scripts/clean.js" + } } diff --git a/packages/liferay-npm-bundler-preset-vue-cli/package.json b/packages/liferay-npm-bundler-preset-vue-cli/package.json index b3d056bd..43d90b91 100644 --- a/packages/liferay-npm-bundler-preset-vue-cli/package.json +++ b/packages/liferay-npm-bundler-preset-vue-cli/package.json @@ -2,7 +2,11 @@ "name": "liferay-npm-bundler-preset-vue-cli", "version": "3.0.0", "description": "Configuration for liferay-npm-bundler to integrate with Vue CLI projects", + "license": "LGPL-3.0", "main": "config.json", + "scripts": { + "clean": "node ../../scripts/clean.js" + }, "dependencies": { "liferay-npm-build-support": "3.0.0", "liferay-npm-bundler-loader-babel-loader": "3.0.0", diff --git a/packages/liferay-npm-bundler/package.json b/packages/liferay-npm-bundler/package.json index 35d2866d..a4a6b130 100644 --- a/packages/liferay-npm-bundler/package.json +++ b/packages/liferay-npm-bundler/package.json @@ -2,13 +2,15 @@ "name": "liferay-npm-bundler", "version": "3.0.0", "description": "A CLI utility to bundle NPM dependencies of a Liferay OSGi bundle.", + "license": "LGPL-3.0", "main": "lib/index.js", "bin": { "liferay-npm-bundler": "bin/liferay-npm-bundler.js" }, "scripts": { - "copyfiles": "node ../../scripts/copyfiles.js", "build": "tsc && yarn copyfiles", + "clean": "node ../../scripts/clean.js", + "copyfiles": "node ../../scripts/copyfiles.js", "prepublish": "node ../../scripts/disable-publish.js", "release:snapshot": "node ../../scripts/release-snapshot.js" }, diff --git a/packages/liferay-npm-bundler/src/dirs.ts b/packages/liferay-npm-bundler/src/dirs.ts index 28600ddc..889af4ee 100644 --- a/packages/liferay-npm-bundler/src/dirs.ts +++ b/packages/liferay-npm-bundler/src/dirs.ts @@ -6,9 +6,15 @@ import fs from 'fs-extra'; import project from 'liferay-npm-build-tools-common/lib/project'; -export const buildBundlerDir = project.buildDir.join('bundler'); -export const buildGeneratedDir = project.buildDir.join('generated'); -export const buildWebpackDir = project.buildDir.join('webpack'); +export const buildBundlerDir = project.workDir + ? project.buildDir + : project.buildDir.join('output'); +export const buildGeneratedDir = project.workDir + ? project.workDir.join('generated') + : project.buildDir.join('generated'); +export const buildWebpackDir = project.workDir + ? project.workDir.join('webpack') + : project.buildDir.join('webpack'); fs.ensureDirSync(buildBundlerDir.asNative); fs.ensureDirSync(buildGeneratedDir.asNative); diff --git a/packages/liferay-npm-bundler/src/index.ts b/packages/liferay-npm-bundler/src/index.ts index f830cd41..875b5080 100644 --- a/packages/liferay-npm-bundler/src/index.ts +++ b/packages/liferay-npm-bundler/src/index.ts @@ -39,17 +39,9 @@ export default async function(argv: {version: boolean}): Promise { report.rulesConfig(project.rules.config); report.versionsInfo(versionsInfo); - // Warn about incremental builds - if (manifest.loadedFromFile) { - report.warn( - 'This report is from an incremental build: some steps may be ' + - 'missing (you may remove the output directory to force a ' + - 'full build).' - ); - } - // Do things copyPackageJson(); + addRootPackageToManifest(rootPkg); await runWebpack(); await runRules(rootPkg); saveManifest(); @@ -77,6 +69,13 @@ export default async function(argv: {version: boolean}): Promise { } } +function addRootPackageToManifest(rootPkg: PkgDesc): void { + manifest.addPackage( + rootPkg, + rootPkg.clone({dir: buildBundlerDir.asNative}) + ); +} + function copyPackageJson(): void { fs.copyFileSync( project.dir.join('package.json').asNative, @@ -87,7 +86,7 @@ function copyPackageJson(): void { } function saveManifest(): void { - manifest.save(); + manifest.save(buildBundlerDir.join('manifest.json').asNative); log.debug('Wrote manifest.json to output directory'); } diff --git a/packages/liferay-npm-bundler/src/jar/index.ts b/packages/liferay-npm-bundler/src/jar/index.ts index cad596b2..b4c16134 100644 --- a/packages/liferay-npm-bundler/src/jar/index.ts +++ b/packages/liferay-npm-bundler/src/jar/index.ts @@ -278,7 +278,7 @@ function getPortletInstanceConfigurationJson(): PortletInstanceConfiguration { if ( !configurationJson.portletInstance || !configurationJson.portletInstance.fields || - Object.keys(configurationJson.portletInstance.fields).length == 0 + Object.keys(configurationJson.portletInstance.fields).length === 0 ) { return undefined; } @@ -301,7 +301,7 @@ function getSystemConfigurationJson(): SystemConfiguration { if ( !configurationJson.system || !configurationJson.system.fields || - Object.keys(configurationJson.system.fields).length == 0 + Object.keys(configurationJson.system.fields).length === 0 ) { return undefined; } diff --git a/packages/liferay-npm-bundler/src/jar/xml.ts b/packages/liferay-npm-bundler/src/jar/xml.ts index 8f5c7cb3..7070c037 100644 --- a/packages/liferay-npm-bundler/src/jar/xml.ts +++ b/packages/liferay-npm-bundler/src/jar/xml.ts @@ -120,7 +120,7 @@ function findChild( ): XmlObject { const elements = parentNode.elements || []; - let childNode = elements.find(node => node.name == childName); + let childNode = elements.find(node => node.name === childName); if (childNode === undefined && create) { childNode = { diff --git a/packages/liferay-npm-bundler/src/log.ts b/packages/liferay-npm-bundler/src/log.ts index dfd6a763..c13e181c 100644 --- a/packages/liferay-npm-bundler/src/log.ts +++ b/packages/liferay-npm-bundler/src/log.ts @@ -5,26 +5,12 @@ import * as format from 'liferay-npm-build-tools-common/lib/format'; import project from 'liferay-npm-build-tools-common/lib/project'; +import {LogLevel} from 'liferay-npm-build-tools-common/lib/project/misc'; -let debugOn: boolean, infoOn: boolean, errorOn: boolean, warnOn: boolean; - -/* eslint-disable no-fallthrough */ -switch (project.misc.logLevel) { - case 'debug': - debugOn = true; - case 'info': - infoOn = true; - case 'warn': - warnOn = true; - case 'error': - default: - errorOn = true; - case 'off': -} -/* eslint-enable no-fallthrough */ +const {logLevel} = project.misc; export function error(...args: unknown[]): void { - if (!errorOn) { + if (logLevel < LogLevel.error) { return; } @@ -32,7 +18,7 @@ export function error(...args: unknown[]): void { } export function warn(...args: unknown[]): void { - if (!warnOn) { + if (logLevel < LogLevel.warn) { return; } @@ -40,7 +26,7 @@ export function warn(...args: unknown[]): void { } export function success(...args: unknown[]): void { - if (!errorOn) { + if (logLevel < LogLevel.error) { return; } @@ -48,7 +34,7 @@ export function success(...args: unknown[]): void { } export function info(...args: unknown[]): void { - if (!infoOn) { + if (logLevel < LogLevel.info) { return; } @@ -56,7 +42,7 @@ export function info(...args: unknown[]): void { } export function debug(...args: unknown[]): void { - if (!debugOn) { + if (logLevel < LogLevel.debug) { return; } diff --git a/packages/liferay-npm-bundler/src/manifest.ts b/packages/liferay-npm-bundler/src/manifest.ts index 4f432b3d..91411769 100644 --- a/packages/liferay-npm-bundler/src/manifest.ts +++ b/packages/liferay-npm-bundler/src/manifest.ts @@ -5,8 +5,6 @@ import Manifest from 'liferay-npm-build-tools-common/lib/manifest'; -import {buildBundlerDir} from './dirs'; - -const manifest = new Manifest(buildBundlerDir.join('manifest.json').asNative); +const manifest = new Manifest(); export default manifest; diff --git a/packages/liferay-npm-bundler/src/report/__tests__/__snapshots__/index.test.ts.snap b/packages/liferay-npm-bundler/src/report/__tests__/__snapshots__/index.test.ts.snap index b05c9f07..538cabd0 100644 --- a/packages/liferay-npm-bundler/src/report/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/liferay-npm-bundler/src/report/__tests__/__snapshots__/index.test.ts.snap @@ -45,20 +45,28 @@ exports[`correctly dumps HTML report 1`] = ` } th, td { - padding: .1em 0; + padding: .1em; vertical-align: top; } - td.info, td.warn, td.error { - background: green; + td.debug, td.info, td.warn, td.error { border-radius: 4px; color: white; + padding: 0 2px; text-align: center; vertical-align: middle; width: 1px; white-space: nowrap; } + td.debug { + background: gray; + } + + td.info { + background: green; + } + td.warn { background: orange; } @@ -68,6 +76,7 @@ exports[`correctly dumps HTML report 1`] = ` } td.source { + color: grey; white-space: nowrap; } @@ -128,7 +137,7 @@ exports[`correctly dumps HTML report 1`] = ` }