1 | const chalk = require('chalk')
|
2 | const path = require('path')
|
3 | const fs = require('fs-extra')
|
4 | const upToDate = require('./up-to-date')
|
5 | const { indent } = require('./indent-bullet')
|
6 | const indent2 = indent.bind(null, 2)
|
7 | const getSnippetVersion = require('../snippets/get-version')
|
8 |
|
9 | const chownSnip = 'sudo chown -R `whoami` ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/CodeSnippets'
|
10 | const lsSnip = 'ls -ld ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/CodeSnippets'
|
11 | const noSnip = 'Your Animate CC snippets folder does not exist'
|
12 | const checkACC = 'Ensure your Animate CC is up to date'
|
13 | const getSnip = `Download and install snippets with the following command:
|
14 | ${chalk.italic.gray('blink snippets')}`
|
15 | const logSnipPerm = `Check permissions with the following command:
|
16 | ${chalk.italic.gray(lsSnip)}`
|
17 | const snipPermFix = `If the user shows as 'root' and/or not your username, try the following:
|
18 | ${chalk.italic.gray(chownSnip)}
|
19 | The permissions should match "drwxrwxrwx"`
|
20 | const snipPermissions = 'Check permissions for the blink snippets directory'
|
21 | const permFormat = `Output should resemble the following:
|
22 | [permissions] [links] [user] ...`
|
23 | const noSnipJson = 'Cannot locate or access the version of blink snippets'
|
24 | const oldSnip = 'You are using an older version of blink snippets'
|
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 snippetPath = path.join(accConfigPath, 'CodeSnippets')
|
31 | try {
|
32 | await fs.access(snippetPath, fs.constants.R_OK | fs.constants.W_OK)
|
33 | try {
|
34 | const snippetVersion = await getSnippetVersion(path.join(snippetPath, 'CodeSnippets.xml'))
|
35 | if (/DEV$/.test(snippetVersion)) {
|
36 | details.push(chalk`You are using blink snippets dev version ${snippetVersion} {yellow (prod is ${pkg.blinkSnippetsVersion})}`)
|
37 | } else if (upToDate(snippetVersion.slice(1), pkg.blinkSnippetsVersion.slice(1))) {
|
38 | details.push(chalk`You are using blink snippets version ${snippetVersion} {green (up to date)}`)
|
39 | } else {
|
40 | details.push(chalk`You are using blink snippets version ${snippetVersion} {red (not up to date)}`)
|
41 | warnings.push(`${oldSnip}\n${indent2(getSnip)}`)
|
42 | }
|
43 | } catch (err) {
|
44 | warnings.push(`${noSnipJson}\n${indent2(getSnip)}`)
|
45 | }
|
46 | } catch (err) {
|
47 | if (err.code === 'ENOENT') warnings.push(`${noSnip}\n${indent2(checkACC)}\n${indent2(getSnip)}\n${indent2(logSnipPerm)}`)
|
48 | else if (err.code === 'EACCES') warnings.push(`${snipPermissions}\n${indent2(`${logSnipPerm}\n${permFormat}\n${snipPermFix}`)}`)
|
49 | else warnings.push(`${snipPermissions}\n${indent2(logSnipPerm)}`)
|
50 | }
|
51 | return { warnings, details }
|
52 | }
|