UNPKG

2.68 kBJavaScriptView Raw
1const chalk = require('chalk')
2const path = require('path')
3const fs = require('fs-extra')
4const fsOpts = { encoding: 'utf8' }
5const upToDate = require('./up-to-date')
6const { indent } = require('./indent-bullet')
7const indent2 = indent.bind(null, 2)
8
9const chownComp = 'sudo chown -R `whoami` ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/HTML5Components/blink-components-release'
10const lsComp = 'ls -ld ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/HTML5Components/blink-components-release'
11const noComp = 'Your Animate CC components folder does not exist'
12const checkACC = 'Ensure your Animate CC is up to date'
13const getComp = `Download and install components with the following command:
14 ${chalk.italic.gray('blink components')}`
15const logCompPerm = `Check permissions with the following command:
16 ${chalk.italic.gray(lsComp)}`
17const compPermFix = `If the user shows as 'root' and/or not your username, try the following:
18 ${chalk.italic.gray(chownComp)}
19The permissions should match "drwxrwxrwx"`
20const compPermissions = 'Check permissions for the blink components directory'
21const permFormat = `Output should resemble the following:
22[permissions] [links] [user] ...`
23const noCompJson = 'Cannot locate or access the version of blink components'
24const oldComp = 'You are using an older version of blink components'
25
26module.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}