@makano/rew 1.2.33 → 1.2.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/rew/cli/cli.js +45 -36
  2. package/package.json +1 -1
@@ -5,7 +5,7 @@ const path = require('path');
5
5
  const { hideBin } = require('yargs/helpers');
6
6
  const { execSync } = require('child_process');
7
7
  const utils = require('./utils');
8
- const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
8
+ const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } = require('fs');
9
9
  const { log } = require('./log');
10
10
  const os = require('os');
11
11
  const crypto = require('crypto');
@@ -18,13 +18,22 @@ const colors = require('colors');
18
18
  const { req } = require('../misc/req');
19
19
  const { gen_key } = require('../misc/bin');
20
20
 
21
- if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH+'/repos.yaml')) {
21
+ if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
22
22
  mkdirSync(CONFIG_PATH, { recursive: true });
23
23
  utils.initFirst();
24
24
  }
25
25
 
26
26
  const npm_package_name = '@makano/rew';
27
27
 
28
+ function isFileArgument(file) {
29
+ try {
30
+ return existsSync(file) && statSync(file).isFile();
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ const isFileGiven = isFileArgument(hideBin(process.argv)[0]) || hideBin(process.argv)[0] == 'run';
28
37
  yargs(hideBin(process.argv))
29
38
  .command(
30
39
  '$0 <file>',
@@ -112,25 +121,25 @@ yargs(hideBin(process.argv))
112
121
  describe: 'Path of the app to run',
113
122
  type: 'string',
114
123
  })
115
- .option('dev', {
116
- describe: 'If your entry file is a .qrew, then just use the .coffee instead',
117
- type: 'boolean',
118
- })
119
- .option('entry', {
120
- alias: 'e',
121
- describe: 'Choose entry file from app.config.exec',
122
- type: 'string',
123
- })
124
- .option('build', {
125
- alias: 'b',
126
- describe: 'Builds to a .qrew before running',
127
- type: 'boolean',
128
- })
129
- .option('translate', {
130
- alias: 't',
131
- describe: 'Builds to a .js before running, only used when --build is passed',
132
- type: 'boolean',
133
- });
124
+ .option('dev', {
125
+ describe: 'If your entry file is a .qrew, then just use the .coffee instead',
126
+ type: 'boolean',
127
+ })
128
+ .option('entry', {
129
+ alias: 'e',
130
+ describe: 'Choose entry file from app.config.exec',
131
+ type: 'string',
132
+ })
133
+ .option('build', {
134
+ alias: 'b',
135
+ describe: 'Builds to a .qrew before running',
136
+ type: 'boolean',
137
+ })
138
+ .option('translate', {
139
+ alias: 't',
140
+ describe: 'Builds to a .js before running, only used when --build is passed',
141
+ type: 'boolean',
142
+ });
134
143
  },
135
144
  (argv) => {
136
145
  utils.runApp(argv.path, argv);
@@ -141,16 +150,16 @@ yargs(hideBin(process.argv))
141
150
  'Add secrets to the current path',
142
151
  (yargs) => {
143
152
  yargs
144
- .positional('command', {
145
- describe: 'Path of the app to run',
146
- type: 'string',
147
- })
148
- .option('file', {
149
- alias: 'f',
150
- describe: 'Set file name',
151
- type: 'string',
152
- default: 'secrets.qrew'
153
- })
153
+ .positional('command', {
154
+ describe: 'Path of the app to run',
155
+ type: 'string',
156
+ })
157
+ .option('file', {
158
+ alias: 'f',
159
+ describe: 'Set file name',
160
+ type: 'string',
161
+ default: 'secrets.qrew'
162
+ })
154
163
  },
155
164
  (argv) => {
156
165
  const appPath = findAppInfo(path.join(process.cwd(), 'app.yaml'));
@@ -225,7 +234,7 @@ yargs(hideBin(process.argv))
225
234
  });
226
235
  },
227
236
  async (argv) => {
228
- if(argv.requirements) utils.installReq(argv.path, argv);
237
+ if (argv.requirements) utils.installReq(argv.path, argv);
229
238
  else utils.installAppFrom(argv.path, argv);
230
239
  },
231
240
  )
@@ -254,9 +263,9 @@ yargs(hideBin(process.argv))
254
263
  async (argv) => {
255
264
  const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
256
265
  const getLatest = async () => {
257
- try{
266
+ try {
258
267
  return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
259
- } catch(e) {
268
+ } catch (e) {
260
269
  return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
261
270
  }
262
271
  }
@@ -265,7 +274,7 @@ yargs(hideBin(process.argv))
265
274
  const latest = await getLatest();
266
275
  const isLatest = latest === pkg.version;
267
276
  log(`Latest: ${pkg.name.cyan.bold}@${latest.yellow.bold}`.green.bold, isLatest ? ':end' : '');
268
- if(!isLatest){
277
+ if (!isLatest) {
269
278
  log(`There is an update available`.cyan.bold);
270
279
  log('Update With:'.yellow, `npm i -g ${npm_package_name}`.green.bold, ':end');
271
280
  }
@@ -326,4 +335,4 @@ yargs(hideBin(process.argv))
326
335
  utils.build(argv);
327
336
  },
328
337
  )
329
- .help().argv;
338
+ .help(!isFileGiven).argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.33",
3
+ "version": "1.2.34",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {