async function main(target, options) {
    const targetDir = target ? path_1.default.join(CWD, target) : CWD;
    options.target = targetDir;
    await fs_extra_1.default.ensureDir(targetDir);
    const packagePath = options.source
        ? path_1.default.join(CWD, options.source)
        : await downloadPackageAsync(targetDir);
    const files = await getFilesAsync(packagePath);
    const data = await askForSubstitutionDataAsync(targetDir, options);
    // Iterate through all template files.
    for (const file of files) {
        const renderedRelativePath = ejs_1.default.render(file.replace(/^\$/, ''), data, {
            openDelimiter: '{',
            closeDelimiter: '}',
            escape: (value) => value.replace('.', path_1.default.sep),
        });
        const fromPath = path_1.default.join(packagePath, file);
        const toPath = path_1.default.join(targetDir, renderedRelativePath);
        const template = await fs_extra_1.default.readFile(fromPath, { encoding: 'utf8' });
        const renderedContent = ejs_1.default.render(template, data);
        await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' });
    }
    if (!options.source) {
        // Files in the downloaded tarball are wrapped in `package` dir.
        // We should remove it after all.
        await fs_extra_1.default.remove(packagePath);
    }
    if (!options.withReadme) {
        await fs_extra_1.default.remove(path_1.default.join(targetDir, 'README.md'));
    }
    if (!options.withChangelog) {
        await fs_extra_1.default.remove(path_1.default.join(targetDir, 'CHANGELOG.md'));
    }
    // Build TypeScript files.
    await (0, spawn_async_1.default)('npm', ['run', 'build'], {
        cwd: targetDir,
    });
}
/**
 * The main function of the command.
 *
 * @param target Path to the directory where to create the module. Defaults to current working dir.
 * @param command An object from `commander`.
 */
The main function of the command.
@param target Path to the directory where to create the module. Defaults to current working dir.
@param command An object from `commander`.
The main function of the command . @param target Path to the directory where to create the module . Defaults to current working dir . @param command An object from ` commander ` .
async function main(target, options) {
    const targetDir = target ? path_1.default.join(CWD, target) : CWD;
    options.target = targetDir;
    await fs_extra_1.default.ensureDir(targetDir);
    const packagePath = options.source
        ? path_1.default.join(CWD, options.source)
        : await downloadPackageAsync(targetDir);
    const files = await getFilesAsync(packagePath);
    const data = await askForSubstitutionDataAsync(targetDir, options);
    for (const file of files) {
        const renderedRelativePath = ejs_1.default.render(file.replace(/^\$/, ''), data, {
            openDelimiter: '{',
            closeDelimiter: '}',
            escape: (value) => value.replace('.', path_1.default.sep),
        });
        const fromPath = path_1.default.join(packagePath, file);
        const toPath = path_1.default.join(targetDir, renderedRelativePath);
        const template = await fs_extra_1.default.readFile(fromPath, { encoding: 'utf8' });
        const renderedContent = ejs_1.default.render(template, data);
        await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' });
    }
    if (!options.source) {
        await fs_extra_1.default.remove(packagePath);
    }
    if (!options.withReadme) {
        await fs_extra_1.default.remove(path_1.default.join(targetDir, 'README.md'));
    }
    if (!options.withChangelog) {
        await fs_extra_1.default.remove(path_1.default.join(targetDir, 'CHANGELOG.md'));
    }
    await (0, spawn_async_1.default)('npm', ['run', 'build'], {
        cwd: targetDir,
    });
}
async function main ( target , options ) { const targetDir = target ? path_1 . default . join ( CWD , target ) : CWD ; options . target = targetDir ; await fs_extra_1 . default . ensureDir ( targetDir ) ; const packagePath = options . source ? path_1 . default . join ( CWD , options . source ) : await downloadPackageAsync ( targetDir ) ; const files = await getFilesAsync ( packagePath ) ; const data = await askForSubstitutionDataAsync ( targetDir , options ) ; for ( const file of files ) { const renderedRelativePath = ejs_1 . default . render ( file . replace ( / ^\$ / , '' ) , data , { openDelimiter : '{' , closeDelimiter : '}' , escape : ( value ) => value . replace ( '.' , path_1 . default . sep ) , } ) ; const fromPath = path_1 . default . join ( packagePath , file ) ; const toPath = path_1 . default . join ( targetDir , renderedRelativePath ) ; const template = await fs_extra_1 . default . readFile ( fromPath , { encoding : 'utf8' } ) ; const renderedContent = ejs_1 . default . render ( template , data ) ; await fs_extra_1 . default . outputFile ( toPath , renderedContent , { encoding : 'utf8' } ) ; } if ( ! options . source ) { await fs_extra_1 . default . remove ( packagePath ) ; } if ( ! options . withReadme ) { await fs_extra_1 . default . remove ( path_1 . default . join ( targetDir , 'README.md' ) ) ; } if ( ! options . withChangelog ) { await fs_extra_1 . default . remove ( path_1 . default . join ( targetDir , 'CHANGELOG.md' ) ) ; } await ( 0 , spawn_async_1 . default ) ( 'npm' , [ 'run' , 'build' ] , { cwd : targetDir , } ) ; }
The main function of the command.
The main function of the command .
// Iterate through all template files. // Files in the downloaded tarball are wrapped in `package` dir. // We should remove it after all. // Build TypeScript files.