Skip to content

Commit

Permalink
feat(cli): set version to 1.0.0-alpha if new package.json initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 5, 2020
1 parent a887f17 commit 4fb2c10
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const { copyFileSync, existsSync, readdirSync } = require('fs');
const { copyFileSync, existsSync, readdirSync, writeFileSync } = require('fs');
const { execSync } = require('child_process');
const { resolve } = require('path');

Expand Down Expand Up @@ -28,6 +28,18 @@ const exec = command => execSync(command, execSyncOptions);
*/
const log = (...args) => console.log('INFO:', ...args);

/**
* Writes to file.
*
* @param {String} file
* @param {*} data
*/
const write = (file, data) =>
writeFileSync(
file,
(typeof data === 'string' ? data : JSON.stringify(data, null, 2)) + '\n'
);

process.on('exit', code => {
log(`Exiting with code: ${code}`);
});
Expand All @@ -46,6 +58,9 @@ if (existsSync(packageJsonPath)) {
} else {
log('`package.json` not found, initializing new package...');
exec('npm init --yes');
const packageJson = require(packageJsonPath);
packageJson.version = '1.0.0-alpha';
write(packageJsonPath, packageJson);
}

/**
Expand Down

0 comments on commit 4fb2c10

Please sign in to comment.