-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 新增在安装之后,自动验证是否是已安装Chromium,如果没有,则自动安装
- Loading branch information
Showing
4 changed files
with
76 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const config = require('./config'); | ||
|
||
/** | ||
* check the chromium have been install in local or not | ||
* @returns {boolean} | ||
*/ | ||
module.exports = function() { | ||
const puppeteerModulePath = path.join(config.paths.root, 'node_modules', 'puppeteer'); | ||
const localChromiumPath = path.join(puppeteerModulePath, '.local-chromium'); | ||
|
||
let isExisted = false; | ||
|
||
try { | ||
const stat = fs.statSync(localChromiumPath); | ||
|
||
// 不是目录 | ||
if (!stat.isDirectory()) { | ||
throw null; | ||
} | ||
|
||
const files = fs.readdirSync(localChromiumPath); | ||
|
||
if (files.length <= 0) { | ||
throw null; | ||
} | ||
|
||
const firstFile = files[0]; | ||
|
||
const firstFileStat = fs.statSync(path.join(localChromiumPath, firstFile)); | ||
|
||
// 不是目录 | ||
if (!firstFileStat.isDirectory()) { | ||
throw null; | ||
} | ||
|
||
isExisted = true; | ||
} catch (err) {} | ||
|
||
return isExisted; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* 检查chromium是否正确下载 | ||
* 如果已下载,则跳过 | ||
* 如果未下载,则执行下载脚本 | ||
* */ | ||
|
||
const chalk = require('chalk'); | ||
|
||
console.info(`${chalk.blue('Checking Chromium')}...`); | ||
|
||
const path = require('path'); | ||
const config = require('../config'); | ||
const isChromiumExist = require('../isChromiumExist'); | ||
const puppeteerModulePath = path.join(config.paths.root, 'node_modules', 'puppeteer'); | ||
|
||
const existed = isChromiumExist(); | ||
|
||
if (existed) { | ||
console.info(`${chalk.green('Chromium exist...')}`); | ||
} else { | ||
console.info(`${chalk.red('Chromium not exist...')}`); | ||
console.info(`${chalk.blue('Chromium installing...')}`); | ||
// run install script | ||
require(path.join(puppeteerModulePath, 'install.js')); | ||
} |