Skip to content

Commit

Permalink
Merge pull request #5 from sottar/add-options
Browse files Browse the repository at this point in the history
Add options
  • Loading branch information
sottar authored Feb 14, 2020
2 parents 7e5e216 + 476dc52 commit d80f902
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "nyarm",
"version": "0.0.6",
"version": "0.0.7",
"description": "😸 npm + yarn => nyarm 😸",
"main": "lib/nyarm.js",
"scripts": {
"prepare": "run-s clean build terser",
"build": "tsc",
"terser": "npx terser --compress --mangle --output lib/nyarm.js -- dist/index.js",
"terser": "npx terser --compress --mangle --output lib/nyarm.js -- dist/src/index.js",
"lint": "eslint src/*",
"clean": "run-p clean:dist clean:lib",
"clean:dist": "rimraf dist/*",
Expand Down
45 changes: 41 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,47 @@ const convertCommandToNpm = (command: string): string => {
return 'run';
};

((): void => {
const showVersion = async (): Promise<void> => {
const pkg = await import('../package.json');

console.log(`v${pkg.version}`);
};
const showHelp = (): void => {
console.log(
chalk.bold(`
nyarm read your current project and judge using npm or yarn.
you can use just nyarm command instead of npm or yarn command.`),
);
console.log(`
$ nyarm {install | add}
# npm project => npm install
# yarn project => yarn install
$ nyarm {install | add} foobar
# npm project => npm install foobar
# yarn project => yarn add foobar
$ nyarm {uninstall | remove} foobar
# npm project => npm uninstall foobar
# yarn project => yarn remove foobar
`);
};

(async (): Promise<void> => {
const options = process.argv.slice(3);
const command = process.argv[2];

switch (command) {
case '-v':
case '--version':
await showVersion();
return;
case '-h':
case '--help':
showHelp();
return;
}

const npmLockFile = 'package-lock.json';
const yarnLockFile = 'yarn.lock';
const isNpmExisted = fs.existsSync(npmLockFile);
Expand All @@ -55,9 +95,6 @@ const convertCommandToNpm = (command: string): string => {
process.exit(0);
}

const options = process.argv.slice(3);
const command = process.argv[2];

if (isNpmExisted) {
console.log(chalk.green('package-lock.json is found, use npm...'));

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"resolveJsonModule": true
}
}

0 comments on commit d80f902

Please sign in to comment.