|
1 | 1 | #!/usr/bin/env node |
2 | 2 | const chalk = require('chalk'); |
3 | | -const fs = require('fs'); |
| 3 | +const fs = require('fs-extra'); |
4 | 4 | const os = require('os'); |
| 5 | +const path = require('path'); |
5 | 6 | const argv = require('minimist')(process.argv.slice(2)); |
6 | 7 | const execa = require('execa'); |
7 | | -const rimraf = require('rimraf'); |
8 | 8 | const open = require('open'); |
9 | 9 | const { explore } = require('source-map-explorer'); |
10 | 10 | const pkgJSON = JSON.parse(fs.readFileSync('./package.json')); |
@@ -36,24 +36,25 @@ function getEntryPoint() { |
36 | 36 | } |
37 | 37 |
|
38 | 38 | // Get (default) arguments |
39 | | -const baseDir = os.tmpdir() + '/react-native-bundle-visualizer'; |
40 | | -const tmpDir = baseDir + '/' + getAppName(); |
| 39 | +const baseDir = path.join(os.tmpdir(), 'react-native-bundle-visualizer'); |
| 40 | +const tmpDir = path.join(baseDir, getAppName()); |
| 41 | +const outDir = path.join(tmpDir, 'output'); |
41 | 42 | const entryFile = argv['entry-file'] || getEntryPoint(); |
42 | 43 | const platform = argv.platform || 'ios'; |
43 | 44 | const expoTarget = argv.expo || ''; |
44 | 45 | const dev = argv.dev || false; |
45 | 46 | const verbose = argv.verbose || false; |
46 | 47 | const resetCache = argv['reset-cache'] || false; |
47 | 48 | const bundleOutput = |
48 | | - argv['bundle-output'] || tmpDir + '/' + platform + '.bundle'; |
| 49 | + argv['bundle-output'] || path.join(tmpDir, platform + '.bundle'); |
49 | 50 | const bundleOutputSourceMap = bundleOutput + '.map'; |
50 | 51 | const format = argv.format || 'html'; |
51 | | -const bundleOutputExplorerFile = tmpDir + '/output/explorer.' + format; |
| 52 | +const bundleOutputExplorerFile = path.join(outDir, 'explorer.' + format); |
52 | 53 | const onlyMapped = !!argv['only-mapped'] || false; |
53 | 54 |
|
54 | 55 | // Make sure the temp dir exists |
55 | | -if (!fs.existsSync(baseDir)) fs.mkdirSync(baseDir); |
56 | | -if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir); |
| 56 | +fs.ensureDirSync(baseDir); |
| 57 | +fs.ensureDirSync(tmpDir); |
57 | 58 |
|
58 | 59 | // Try to obtain the previous file size |
59 | 60 | let prevBundleSize; |
@@ -84,7 +85,7 @@ if (resetCache) { |
84 | 85 | if (expoTarget) { |
85 | 86 | process.env.EXPO_TARGET = expoTarget; |
86 | 87 | commands.push('--config'); |
87 | | - commands.push(__dirname + '/expo-metro.config.js'); |
| 88 | + commands.push(path.join(__dirname, 'expo-metro.config.js')); |
88 | 89 | } |
89 | 90 |
|
90 | 91 | const bundlePromise = execa('./node_modules/.bin/react-native', commands); |
@@ -122,7 +123,7 @@ bundlePromise |
122 | 123 | ); |
123 | 124 |
|
124 | 125 | // Make sure the explorer output dir is removed |
125 | | - if (fs.existsSync(tmpDir + '/output')) rimraf.sync(tmpDir + '/output'); |
| 126 | + fs.removeSync(outDir); |
126 | 127 | return explore( |
127 | 128 | { |
128 | 129 | code: bundleOutput, |
|
0 commit comments