|
1 | 1 | #!/usr/bin/env node
|
2 |
| -'use strict'; |
3 |
| -const yargs_parser = require('yargs-parser'); |
4 |
| -const path = require('path'); |
5 |
| -const chalk = require('chalk'); |
6 |
| -const ora = require('ora'); |
7 |
| -const { extract } = require('pacote'); |
8 |
| -const fs = require('fs-extra'); |
9 |
| -const os = require('os'); |
10 |
| -const packageName = 'html5-boilerplate'; |
| 2 | +"use strict"; |
| 3 | +const yargs_parser = require("yargs-parser"); |
| 4 | +const path = require("path"); |
| 5 | +const chalk = require("chalk"); |
| 6 | +const ora = require("ora"); |
| 7 | +const { extract } = require("pacote"); |
| 8 | +const fs = require("fs-extra"); |
| 9 | +const os = require("os"); |
| 10 | +const packageName = "html5-boilerplate"; |
11 | 11 | const tempDir = os.tmpdir() + `/${packageName}-staging`;
|
12 |
| -const elapsed = require('elapsed-time-logger'); |
| 12 | +const elapsed = require("elapsed-time-logger"); |
13 | 13 |
|
14 | 14 | module.exports = async () => {
|
15 |
| - const argv = yargs_parser(process.argv.slice(2), { alias: { release: ['r'] } }); |
| 15 | + const argv = yargs_parser(process.argv.slice(2), { |
| 16 | + alias: { release: ["r"] }, |
| 17 | + }); |
16 | 18 | const timer = elapsed.start();
|
17 |
| - const version = argv['release'] || 'latest'; |
18 |
| - const targetDir = path.resolve(argv['_'][0] || './'); |
| 19 | + const version = argv["release"] || "latest"; |
| 20 | + const targetDir = path.resolve(argv["_"][0] || "./"); |
19 | 21 | const spinner = ora(`Downloading ${packageName} version '${version}' to ${targetDir}`).start();
|
20 | 22 | await fs.ensureDir(tempDir);
|
21 | 23 | try {
|
22 |
| - const { from: nameWithVersion } = await extract(packageName + '@' + version, tempDir, {}); |
| 24 | + const { from: nameWithVersion } = await extract(packageName + "@" + version, tempDir, {}); |
23 | 25 | spinner.text = `${nameWithVersion} copied to ${targetDir} in ${timer.get()}. Have fun!`;
|
24 | 26 | } catch (err) {
|
25 | 27 | await fs.remove(tempDir);
|
26 |
| - if (err.code === 'ETARGET') { |
| 28 | + if (err.code === "ETARGET") { |
27 | 29 | spinner.fail(chalk.red(`version '${err.wanted}' not found in npm registry\navailable versions:`));
|
28 |
| - console.log(err.versions.reverse().join(' | ')); |
| 30 | + console.log(err.versions.reverse().join(" | ")); |
29 | 31 | process.exit(1);
|
30 | 32 | } /* istanbul ignore next */ else {
|
31 |
| - spinner.fail('Unexpected error'); |
| 33 | + spinner.fail("Unexpected error"); |
32 | 34 | console.error(err);
|
33 | 35 | process.exit(-1);
|
34 | 36 | }
|
35 | 37 | return;
|
36 | 38 | }
|
37 |
| - await fs.copy(tempDir + '/dist', targetDir); |
| 39 | + await fs.copy(tempDir + "/dist", targetDir); |
38 | 40 | await fs.remove(tempDir);
|
39 | 41 | spinner.succeed();
|
40 | 42 | return;
|
|
0 commit comments