1 | const chalk = require('chalk')
|
2 | const path = require('path')
|
3 | const fs = require('fs-extra')
|
4 | const fsOpts = { encoding: 'utf8' }
|
5 | const upToDate = require('./up-to-date')
|
6 | const { indent } = require('./indent-bullet')
|
7 | const indent2 = indent.bind(null, 2)
|
8 |
|
9 | const chownComp = 'sudo chown -R `whoami` ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/HTML5Components/blink-components-release'
|
10 | const lsComp = 'ls -ld ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/HTML5Components/blink-components-release'
|
11 | const noComp = 'Your Animate CC components folder does not exist'
|
12 | const checkACC = 'Ensure your Animate CC is up to date'
|
13 | const getComp = `Download and install components with the following command:
|
14 | ${chalk.italic.gray('blink components')}`
|
15 | const logCompPerm = `Check permissions with the following command:
|
16 | ${chalk.italic.gray(lsComp)}`
|
17 | const compPermFix = `If the user shows as 'root' and/or not your username, try the following:
|
18 | ${chalk.italic.gray(chownComp)}
|
19 | The permissions should match "drwxrwxrwx"`
|
20 | const compPermissions = 'Check permissions for the blink components directory'
|
21 | const permFormat = `Output should resemble the following:
|
22 | [permissions] [links] [user] ...`
|
23 | const noCompJson = 'Cannot locate or access the version of blink components'
|
24 | const oldComp = 'You are using an older version of blink components'
|
25 |
|
26 | module.exports = async ({ env, pkg }) => {
|
27 | const warnings = []
|
28 | const details = []
|
29 | const accConfigPath = `${env.home}/Library/Application Support/Adobe/Animate CC 2018/en_US/Configuration/`
|
30 | const componentPath = path.join(accConfigPath, 'HTML5Components/blink-components-release')
|
31 | try {
|
32 | await fs.access(componentPath, fs.constants.R_OK | fs.constants.W_OK)
|
33 | try {
|
34 | const data = await fs.readJson(path.join(componentPath, 'package.json'), fsOpts)
|
35 | if (upToDate(data.version, pkg.blinkComponentsVersion.slice(1))) {
|
36 | details.push(chalk`You are using blink components version ${data.version} {green (up to date)}`)
|
37 | } else {
|
38 | details.push(chalk`You are using blink components version ${data.version} {red (not up to date)}`)
|
39 | warnings.push(`${oldComp}\n${indent2(getComp)}`)
|
40 | }
|
41 | } catch (err) {
|
42 | warnings.push(`${noCompJson}\n${indent2(getComp)}`)
|
43 | }
|
44 | } catch (err) {
|
45 | if (err.code === 'ENOENT') warnings.push(`${noComp}\n${indent2(checkACC)}\n${indent2(getComp)}\n${indent2(logCompPerm)}`)
|
46 | else if (err.code === 'EACCES') warnings.push(`${compPermissions}\n${indent2(`${logCompPerm}\n${permFormat}\n${compPermFix}`)}`)
|
47 | else warnings.push(`${compPermissions}\n${indent2(logCompPerm)}`)
|
48 | }
|
49 | return { warnings, details }
|
50 | }
|