Skip to content

Commit

Permalink
Add {{{pkg.version}}} variable for target path
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Oct 4, 2022
1 parent d66cfa0 commit 48b6911
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

// Imports
import { copyFile } from '../dist/copy-file.js';
import chalk from 'chalk';
import log from 'fancy-log';
import chalk from 'chalk';
import fs from 'fs';
import log from 'fancy-log';

// Parameters
const validFlags = ['cd', 'folder', 'quiet'];
Expand All @@ -37,6 +38,10 @@ const source = params[0];
const target = params[1];
const mode = { folder: 'folder' in flagMap, quiet: 'quiet' in flagMap };

// Utilities
const getPackageVersion = () => !fs.existsSync('package.json') ? 'ERROR' :
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version;

// Reporting
const printReport = (result) => {
const name = chalk.gray('copy-file');
Expand All @@ -60,7 +65,7 @@ if (error)
const targetKey = mode.folder ? 'targetFolder' : 'targetFile';
const options = {
cd: flagMap.cd ?? null,
[targetKey]: target,
[targetKey]: target.replace(/{{{pkg.version}}}/, getPackageVersion),
};
const result = copyFile.cp(source, options);
if (!mode.quiet)
Expand Down

0 comments on commit 48b6911

Please sign in to comment.