Skip to content

Commit

Permalink
Merge pull request #196 from ckeditor/ci/3772
Browse files Browse the repository at this point in the history
Other: Converted the project repository to ESM. Closes #192.
  • Loading branch information
pomek authored Oct 30, 2024
2 parents af330a9 + 24f77cc commit 30f0ada
Show file tree
Hide file tree
Showing 88 changed files with 4,444 additions and 4,511 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ module.exports = {
' * @license Copyright (c) 2020-2024, CKSource Holding sp. z o.o. All rights reserved.',
' * For licensing, see LICENSE.md.',
' */'
] } ]
] } ],
'ckeditor5-rules/require-file-extensions-in-imports': [
'error',
{
extensions: [ '.ts', '.js', '.json' ]
}
]
}
};
43 changes: 13 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,46 @@
"author": "CKSource (http://cksource.com/)",
"license": "MIT",
"homepage": "https://ckeditor.com/ckeditor-5",
"type": "module",
"devDependencies": {
"@ckeditor/ckeditor5-dev-bump-year": "^42.0.0",
"@ckeditor/ckeditor5-dev-ci": "^42.0.0",
"@ckeditor/ckeditor5-dev-release-tools": "^42.0.0",
"@ckeditor/ckeditor5-dev-web-crawler": "^42.0.0",
"chalk": "^4.1.2",
"@ckeditor/ckeditor5-dev-bump-year": "^44.0.0",
"@ckeditor/ckeditor5-dev-ci": "^44.0.0",
"@ckeditor/ckeditor5-dev-release-tools": "^44.0.0",
"@ckeditor/ckeditor5-dev-web-crawler": "^44.0.0",
"@vitest/coverage-v8": "^2.1.1",
"chalk": "^5.0.0",
"coveralls": "^3.1.1",
"eslint": "^7.32.0",
"eslint-config-ckeditor5": "^6.0.0",
"fs-extra": "^11.2.0",
"glob": "^10.2.5",
"husky": "^8.0.2",
"lint-staged": "^10.5.4",
"minimist": "^1.2.8",
"mocha": "^10.7.3",
"nyc": "^15.1.0",
"semver": "^7.0.0",
"strip-ansi": "^6.0.1",
"upath": "^2.0.1"
"upath": "^2.0.1",
"vitest": "^2.0.5"
},
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"postinstall": "node ./scripts/postinstall.js",
"changelog": "node scripts/release/changelog.js",
"coverage": "nyc yarn run test",
"lint": "eslint --quiet \"**/*.js\"",
"precommit": "lint-staged",
"release:prepare-packages": "node scripts/release/preparepackages.js",
"release:publish-packages": "node scripts/release/publishpackages.js",
"test": "mocha 'packages/*/tests/**/*.js'",
"clean": "npx rimraf package-lock.json yarn.lock ./**/node_modules",
"test": "vitest run --config vitest.config.js",
"coverage": "vitest run --config vitest.config.js --coverage",
"clean": "npx rimraf --glob package-lock.json yarn.lock ./**/node_modules",
"reinstall": "yarn run clean && yarn install"
},
"repository": {
"type": "git",
"url": "https://github.com/ckeditor/ckeditor5-package-generator.git"
},
"nyc": {
"reporter": [
"text-summary",
"lcov"
],
"include": [
"packages/**/lib"
],
"exclude": [
"packages/ckeditor5-package-generator/lib/templates"
],
"cache": false,
"all": true,
"check-coverage": true,
"lines": 100,
"branches": 100,
"functions": 100,
"statements": 100
},
"lint-staged": {
"**/*.js": [
"eslint --quiet"
Expand Down
13 changes: 8 additions & 5 deletions packages/ckeditor5-package-generator/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
* For licensing, see LICENSE.md.
*/

const fs = require( 'fs' );
const path = require( 'path' );
const { Command } = require( 'commander' );
import fs from 'fs-extra';
import path from 'path';
import { Command } from 'commander';
import { fileURLToPath } from 'url';
import init from '../lib/index.js';

const packageJson = require( '../package.json' );
const __filename = fileURLToPath( import.meta.url );
const __dirname = path.dirname( __filename );

const init = require( '../lib/index' );
const packageJson = fs.readJsonSync( path.join( __dirname, '..', 'package.json' ) );

new Command( packageJson.name )
.argument( '[packageName]', 'name of the package (@scope/ckeditor5-*)' )
Expand Down
38 changes: 17 additions & 21 deletions packages/ckeditor5-package-generator/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const chalk = require( 'chalk' );

const Logger = require( './utils/logger' );

const chooseInstallationMethods = require( './utils/choose-installation-methods' );
const choosePackageManager = require( './utils/choose-package-manager' );
const chooseProgrammingLanguage = require( './utils/choose-programming-language' );
const setGlobalName = require( './utils/set-global-name' );
const copyFiles = require( './utils/copy-files' );
const createDirectory = require( './utils/create-directory' );
const getDependenciesVersions = require( './utils/get-dependencies-versions' );
const getPackageNameFormats = require( './utils/get-package-name-formats' );
const initializeGitRepository = require( './utils/initialize-git-repository' );
const installDependencies = require( './utils/install-dependencies' );
const installGitHooks = require( './utils/install-git-hooks' );
const validatePackageName = require( './utils/validate-package-name' );
const validatePluginName = require( './utils/validate-plugin-name' );
import chalk from 'chalk';
import Logger from './utils/logger.js';
import chooseInstallationMethods from './utils/choose-installation-methods.js';
import choosePackageManager from './utils/choose-package-manager.js';
import chooseProgrammingLanguage from './utils/choose-programming-language.js';
import setGlobalName from './utils/set-global-name.js';
import copyFiles from './utils/copy-files.js';
import createDirectory from './utils/create-directory.js';
import getDependenciesVersions from './utils/get-dependencies-versions.js';
import getPackageNameFormats from './utils/get-package-name-formats.js';
import initializeGitRepository from './utils/initialize-git-repository.js';
import installDependencies from './utils/install-dependencies.js';
import installGitHooks from './utils/install-git-hooks.js';
import validatePackageName from './utils/validate-package-name.js';
import validatePluginName from './utils/validate-plugin-name.js';

/**
* @param {String|undefined} packageName
* @param {CKeditor5PackageGeneratorOptions} options
*/
module.exports = async function init( packageName, options ) {
export default async function init( packageName, options ) {
const { dev, verbose, useNpm, useYarn, installationMethods, lang, pluginName, globalName } = options;

const logger = new Logger( verbose );
Expand Down Expand Up @@ -95,7 +91,7 @@ module.exports = async function init( packageName, options ) {
''
].join( '\n' ), { startWithNewLine: true } );
}
};
}

/**
* @typedef {Object} CKeditor5PackageGeneratorOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"scripts": {
"build:dist": "node ./scripts/build-dist.mjs",
"ts:build": "tsc -p ./tsconfig.release.json",
"ts:clear": "npx rimraf \"src/**/*.@(js|d.ts)\"",
"ts:clear": "npx rimraf --glob \"src/**/*.@(js|d.ts)\"",
"dll:build": "ckeditor5-package-tools dll:build",
"dll:serve": "http-server ./ -o sample/dll.html",
"lint": "eslint \"**/*.{js,ts}\" --quiet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"scripts": {
"build:dist": "node ./scripts/build-dist.mjs",
"ts:build": "tsc -p ./tsconfig.release.json",
"ts:clear": "npx rimraf \"src/**/*.@(js|d.ts)\"",
"ts:clear": "npx rimraf --glob \"src/**/*.@(js|d.ts)\"",
"lint": "eslint \"**/*.{js,ts}\" --quiet",
"start": "ckeditor5-package-tools start",
"stylelint": "stylelint --quiet --allow-empty-input 'theme/**/*.css'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const { prompt } = require( 'inquirer' );
import inquirer from 'inquirer';

const INSTALLATION_METHODS = [
{
Expand All @@ -27,7 +25,7 @@ const INSTALLATION_METHODS = [
* @param {String} method
* @returns {Promise<String>}
*/
module.exports = async function chooseIn( logger, method ) {
export default async function chooseInstallationMethods( logger, method ) {
if ( method ) {
const methodShorthands = INSTALLATION_METHODS.map( ( { value } ) => value );

Expand All @@ -40,7 +38,7 @@ module.exports = async function chooseIn( logger, method ) {
);
}

const { installationMethod } = await prompt( [ {
const { installationMethod } = await inquirer.prompt( [ {
prefix: '📍',
name: 'installationMethod',
message: 'Which installation methods of CKEditor 5 do you want to support?',
Expand All @@ -49,4 +47,4 @@ module.exports = async function chooseIn( logger, method ) {
} ] );

return INSTALLATION_METHODS.find( p => p.displayName === installationMethod ).value;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const { prompt } = require( 'inquirer' );
const isYarnInstalled = require( './is-yarn-installed' );
import inquirer from 'inquirer';
import isYarnInstalled from './is-yarn-installed.js';

/**
* @param {Boolean} useNpm
* @param {Boolean} useYarn
* @returns {Promise<'npm'|'yarn'>}
*/
module.exports = async function choosePackageManager( useNpm, useYarn ) {
export default async function choosePackageManager( useNpm, useYarn ) {
const yarnInstalled = isYarnInstalled();

if ( useYarn && !yarnInstalled ) {
Expand All @@ -37,13 +35,13 @@ module.exports = async function choosePackageManager( useNpm, useYarn ) {
}

return await askUserToChoosePackageManager();
};
}

/**
* @returns {Promise<'npm'|'yarn'>}
*/
async function askUserToChoosePackageManager() {
const { packageManager } = await prompt( [ {
const { packageManager } = await inquirer.prompt( [ {
prefix: '📍',
name: 'packageManager',
message: 'Choose the package manager:',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const { prompt } = require( 'inquirer' );
import inquirer from 'inquirer';

const PROGRAMMING_LANGUAGES = [
{ value: 'ts', displayName: 'TypeScript' },
Expand All @@ -20,7 +18,7 @@ const PROGRAMMING_LANGUAGES = [
* @param {String} lang
* @returns {Promise<String>}
*/
module.exports = async function chooseProgrammingLanguage( logger, lang ) {
export default async function chooseProgrammingLanguage( logger, lang ) {
if ( lang ) {
const langShorthands = PROGRAMMING_LANGUAGES.map( ( { value } ) => value );

Expand All @@ -31,7 +29,7 @@ module.exports = async function chooseProgrammingLanguage( logger, lang ) {
logger.error( `--lang option has to be one of: ${ langShorthands.join( ', ' ) }. Falling back to manual choice.` );
}

const { programmingLanguage } = await prompt( [ {
const { programmingLanguage } = await inquirer.prompt( [ {
prefix: '📍',
name: 'programmingLanguage',
message: 'Choose your programming language:',
Expand All @@ -41,4 +39,4 @@ module.exports = async function chooseProgrammingLanguage( logger, lang ) {

// Full name to shorthand: "JavaScript" => "js"
return PROGRAMMING_LANGUAGES.find( p => p.displayName === programmingLanguage ).value;
};
}
20 changes: 11 additions & 9 deletions packages/ckeditor5-package-generator/lib/utils/copy-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* For licensing, see LICENSE.md.
*/

'use strict';
import chalk from 'chalk';
import fs from 'fs';
import glob from 'glob';
import mkdirp from 'mkdirp';
import path from 'path';
import { template } from 'lodash-es';
import { fileURLToPath } from 'url';

const chalk = require( 'chalk' );
const fs = require( 'fs' );
const glob = require( 'glob' );
const mkdirp = require( 'mkdirp' );
const path = require( 'path' );
const { template } = require( 'lodash' );
const __filename = fileURLToPath( import.meta.url );
const __dirname = path.dirname( __filename );

const TEMPLATE_PATH = path.join( __dirname, '..', 'templates' );

Expand All @@ -28,7 +30,7 @@ const TEMPLATE_PATH = path.join( __dirname, '..', 'templates' );
* @param {String} options.installationMethodOfPackage
* @param {String} options.validatedGlobalName
*/
module.exports = function copyFiles( logger, options ) {
export default function copyFiles( logger, options ) {
logger.process( 'Copying files...' );

const supportsLegacyMethods = options.installationMethodOfPackage !== 'current';
Expand Down Expand Up @@ -58,7 +60,7 @@ module.exports = function copyFiles( logger, options ) {

copyTemplate( templatePath, options.directoryPath, data );
}
};
}

/**
* Copies all files into the package directory. If any file has any template placeholders, they are filled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const chalk = require( 'chalk' );
const fs = require( 'fs' );
const mkdirp = require( 'mkdirp' );
const path = require( 'path' );
import chalk from 'chalk';
import fs from 'fs';
import mkdirp from 'mkdirp';
import path from 'path';

/**
* Checks whether its possible to create a directory, and either creates it or ends the process with an error.
*
* @param {Logger} logger
* @param {String} packageName
*/
module.exports = function createDirectory( logger, packageName ) {
export default function createDirectory( logger, packageName ) {
const directoryName = packageName.split( '/' )[ 1 ];
const directoryPath = path.resolve( directoryName );

Expand All @@ -34,4 +32,4 @@ module.exports = function createDirectory( logger, packageName ) {
mkdirp.sync( directoryPath );

return { directoryName, directoryPath };
};
}
Loading

0 comments on commit 30f0ada

Please sign in to comment.