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

ckeditor / ckeditor5-package-generator / 983

pending completion
983

cron

travis-ci-com

web-flow
Merge pull request #134 from ckeditor/ci/2269

Internal: Use `ckeditor5-dev-ci-notify-travis-status` script from new package `ckeditor5-dev-ci`.

111 of 111 branches covered (100.0%)

Branch coverage included in aggregate %.

412 of 412 relevant lines covered (100.0%)

8.13 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-2022, 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' );
11✔
9
const fs = require( 'fs' );
11✔
10
const glob = require( 'glob' );
11✔
11
const mkdirp = require( 'mkdirp' );
11✔
12
const path = require( 'path' );
11✔
13
const template = require( 'lodash.template' );
11✔
14

15
const TEMPLATE_PATH = path.join( __dirname, '..', 'templates' );
11✔
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} 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
 */
29
module.exports = function copyFiles( logger, options ) {
11✔
30
        logger.process( 'Copying files...' );
10✔
31

32
        const templateGlobs = [
10✔
33
                'common/**/*',
34
                `${ options.programmingLanguage }/**/*`
35
        ];
36

37
        const templatesToCopy = templateGlobs.flatMap( globPattern => {
10✔
38
                return glob.sync( globPattern, {
20✔
39
                        cwd: TEMPLATE_PATH,
40
                        dot: true,
41
                        nodir: true
42
                } );
43
        } );
44

45
        for ( const templatePath of templatesToCopy ) {
10✔
46
                logger.verboseInfo( `* Copying "${ chalk.gray( templatePath ) }"...` );
42✔
47

48
                const data = {
42✔
49
                        cliSeparator: options.packageManager === 'npm' ? '-- ' : '',
42✔
50
                        now: new Date(),
51
                        ...options
52
                };
53

54
                copyTemplate( templatePath, options.directoryPath, data );
42✔
55
        }
56
};
57

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

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

77
        const destinationPath = path.join( packagePath, processedTemplatePath );
42✔
78

79
        // Make sure that the destination directory exists.
80
        mkdirp.sync( path.dirname( destinationPath ) );
42✔
81
        fs.writeFileSync( destinationPath, filledFile );
42✔
82
}
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