UNPKG

2.81 kBJavaScriptView Raw
1const chalk = require('chalk')
2const path = require('path')
3const fs = require('fs-extra')
4const upToDate = require('./up-to-date')
5const { indent } = require('./indent-bullet')
6const indent2 = indent.bind(null, 2)
7const getSnippetVersion = require('../snippets/get-version')
8
9const chownSnip = 'sudo chown -R `whoami` ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/CodeSnippets'
10const lsSnip = 'ls -ld ~/Library/"Application Support"/Adobe/"Animate CC 2018"/en_US/Configuration/CodeSnippets'
11const noSnip = 'Your Animate CC snippets folder does not exist'
12const checkACC = 'Ensure your Animate CC is up to date'
13const getSnip = `Download and install snippets with the following command:
14 ${chalk.italic.gray('blink snippets')}`
15const logSnipPerm = `Check permissions with the following command:
16 ${chalk.italic.gray(lsSnip)}`
17const snipPermFix = `If the user shows as 'root' and/or not your username, try the following:
18 ${chalk.italic.gray(chownSnip)}
19The permissions should match "drwxrwxrwx"`
20const snipPermissions = 'Check permissions for the blink snippets directory'
21const permFormat = `Output should resemble the following:
22[permissions] [links] [user] ...`
23const noSnipJson = 'Cannot locate or access the version of blink snippets'
24const oldSnip = 'You are using an older version of blink snippets'
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 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}