• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ckeditor / ckeditor5-package-generator / 4c42dc7e-c078-4dd0-a5de-abdaf729fc09

09 Sep 2024 11:40AM UTC coverage: 100.0%. Remained the same
4c42dc7e-c078-4dd0-a5de-abdaf729fc09

push

circleci

web-flow
Merge pull request #187 from ckeditor/ci/3756

Other (generator): Replaced Karma with Vitest as the testing framework in the generated package.

Other (tools): Removed support for the `--coverage` (`-c`) and `--source-map` (`-s`) flags.

Other (tools): Removed `test` script from the tools, because unit tests in the generated package are executed now directly by Vitest.

MINOR BREAKING CHANGE (generator): The generated package no longer uses Karma as the test runner. Instead, Vitest is used.

MINOR BREAKING CHANGE (tools): The `test` script is removed, because unit tests in the generated package are executed directly by Vitest. Hence, the previous custom support for the `--coverage` (`-c`) and `--source-map` (`-s`) flags is no longer needed and has been also removed. The `yarn run test` (or `npm run test`) script is still available in the generated package, but it executes Vitest. See [CLI flags](https://vitest.dev/guide/cli.html) supported in Vitest.

120 of 120 branches covered (100.0%)

Branch coverage included in aggregate %.

393 of 393 relevant lines covered (100.0%)

9.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/packages/ckeditor5-package-generator/lib/utils/copy-files.js
1
/**
2
 * @license Copyright (c) 2020-2024, CKSource Holding sp. z o.o. All rights reserved.
3
 * For licensing, see LICENSE.md.
4
 */
5

6
'use strict';
7

8
const chalk = require( 'chalk' );
13✔
9
const fs = require( 'fs' );
13✔
10
const glob = require( 'glob' );
13✔
11
const mkdirp = require( 'mkdirp' );
13✔
12
const path = require( 'path' );
13✔
13
const { template } = require( 'lodash' );
13✔
14

15
const TEMPLATE_PATH = path.join( __dirname, '..', 'templates' );
13✔
16

17
/**
18
 * If the package name is not valid, prints the error and exits the process.
19
 *
20
 * @param {Logger} logger
21
 * @param {Object} options
22
 * @param {String} options.packageName
23
 * @param {FormattedNames} options.formattedNames
24
 * @param {String} options.directoryPath
25
 * @param {String} options.packageManager
26
 * @param {String} options.programmingLanguage
27
 * @param {Object} options.packageVersions
28
 * @param {String} options.installationMethodOfPackage
29
 * @param {String} options.validatedGlobalName
30
 */
31
module.exports = function copyFiles( logger, options ) {
13✔
32
        logger.process( 'Copying files...' );
12✔
33

34
        const supportsLegacyMethods = options.installationMethodOfPackage !== 'current';
12✔
35
        const templatePatternToCopy = `${ options.programmingLanguage }${ supportsLegacyMethods ? '-legacy' : '' }/**/*`;
12✔
36

37
        const templateGlobs = [
12✔
38
                'common/**/*',
39
                templatePatternToCopy
40
        ];
41

42
        const templatesToCopy = templateGlobs.flatMap( globPattern => {
12✔
43
                return glob.sync( globPattern, {
24✔
44
                        cwd: TEMPLATE_PATH,
45
                        dot: true,
46
                        nodir: true
47
                } );
48
        } );
49

50
        for ( const templatePath of templatesToCopy ) {
12✔
51
                logger.verboseInfo( `* Copying "${ chalk.gray( templatePath ) }"...` );
50✔
52

53
                const data = {
50✔
54
                        cliSeparator: options.packageManager === 'npm' ? '-- ' : '',
50✔
55
                        now: new Date(),
56
                        ...options
57
                };
58

59
                copyTemplate( templatePath, options.directoryPath, data );
50✔
60
        }
61
};
62

63
/**
64
 * Copies all files into the package directory. If any file has any template placeholders, they are filled.
65
 *
66
 * @param {String} templatePath The relative path to the "templates/" directory of the file to copy.
67
 * @param {String} packagePath The destination directory where the new package is created.
68
 * @param {Object} data The data to fill in the template file.
69
 */
70
function copyTemplate( templatePath, packagePath, data ) {
71
        const rawFile = fs.readFileSync( path.join( TEMPLATE_PATH, templatePath ), 'utf-8' );
50✔
72
        const filledFile = template( rawFile )( data );
50✔
73

74
        const processedTemplatePath = templatePath
50✔
75
                // Remove sub-directory inside templates to merge results into one directory.
76
                .replace( /^(?:common|js|ts|js-legacy|ts-legacy)(?:\\|\/)/, '' )
77
                // We use the ".txt" file extension to circumvent syntax errors in templates and npm not publishing the ".gitignore" file.
78
                .replace( /\.txt$/, '' )
79
                // Replace placeholder filenames with the class name.
80
                .replace( /_PLACEHOLDER_/, data.formattedNames.plugin.lowerCaseMerged );
81

82
        const destinationPath = path.join( packagePath, processedTemplatePath );
50✔
83

84
        // Make sure that the destination directory exists.
85
        mkdirp.sync( path.dirname( destinationPath ) );
50✔
86
        fs.writeFileSync( destinationPath, filledFile );
50✔
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc