diff --git a/.gitignore b/.gitignore index b4ed01bf..20ad0087 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ yarn-error.log .vscode packages/zcli-apps/tests/functional/mocks/*/tmp packages/**/dist +.DS_Store diff --git a/docs/apps.md b/docs/apps.md index 60aa171f..14b543d4 100644 --- a/docs/apps.md +++ b/docs/apps.md @@ -3,6 +3,17 @@ zcli apps commands helps with managing Zendesk apps workflow. +* [`zcli apps:bump [APPPATH]`](#zcli-appsbump-apppath) +* [`zcli apps:clean [APPPATH]`](#zcli-appsclean-apppath) +* [`zcli apps:create APPDIRECTORIES`](#zcli-appscreate-appdirectories) +* [`zcli apps:new`](#zcli-appsnew) +* [`zcli apps:package APPDIRECTORY`](#zcli-appspackage-appdirectory) +* [`zcli apps:server APPDIRECTORIES`](#zcli-appsserver-appdirectories) +* [`zcli apps:update APPDIRECTORIES`](#zcli-appsupdate-appdirectories) +* [`zcli apps:validate APPDIRECTORY`](#zcli-appsvalidate-appdirectory) + +## Configuration + NOTE: You can set your apps config/settings in `zcli.apps.config.json` at the root of your app directory ie ``` @@ -20,14 +31,12 @@ NOTE: You can set your apps config/settings in `zcli.apps.config.json` at the ro See [these mock apps](https://github.com/zendesk/zcli/tree/master/packages/zcli-apps/tests/functional/mocks) for more references of `zcli.apps.config.json`. -* [`zcli apps:bump [APPPATH]`](#zcli-appsbump-apppath) -* [`zcli apps:clean [APPPATH]`](#zcli-appsclean-apppath) -* [`zcli apps:create APPDIRECTORIES`](#zcli-appscreate-appdirectories) -* [`zcli apps:new`](#zcli-appsnew) -* [`zcli apps:package APPDIRECTORY`](#zcli-appspackage-appdirectory) -* [`zcli apps:server APPDIRECTORIES`](#zcli-appsserver-appdirectories) -* [`zcli apps:update APPDIRECTORIES`](#zcli-appsupdate-appdirectories) -* [`zcli apps:validate APPDIRECTORY`](#zcli-appsvalidate-appdirectory) +If you wish to specify files/folders to be ignored as part of the packaging process, create a .zcliignore file in your apps root directory. Patterns following the gitignore specification included in a .zcliignore file will be excluded from packaging when any of the following commands are executed: + +* zcli apps:package +* zcli apps:create +* zcli apps:update +* zcli apps:validate ## `zcli apps:bump [APPPATH]` diff --git a/packages/zcli-apps/src/lib/package.ts b/packages/zcli-apps/src/lib/package.ts index fb84810b..8243fc89 100644 --- a/packages/zcli-apps/src/lib/package.ts +++ b/packages/zcli-apps/src/lib/package.ts @@ -24,11 +24,19 @@ export const createAppPkg = async ( archive.pipe(output) - // ignore tmp dir + let archiveIgnore = ['tmp/**'] + + if (fs.pathExistsSync(`${appPath}/.zcliignore`)) { + archiveIgnore = archiveIgnore.concat(fs.readFileSync(`${appPath}/.zcliignore`).toString().replace(/\r\n/g, '\n').split('\n').filter((item) => { + return (item.trim().startsWith('#') ? null : item.trim()) + })) + } + archive.glob('**', { cwd: appPath, - ignore: ['tmp/**'] + ignore: archiveIgnore }) + await archive.finalize() if (!fs.pathExistsSync(pkgPath)) { diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/.zcliignore b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/.zcliignore new file mode 100644 index 00000000..c1da21d6 --- /dev/null +++ b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/.zcliignore @@ -0,0 +1,6 @@ +assets/logo-small.png +assets/iframe.html +assets/icon_nav_bar.svg +manifest.json +testFolder/ignoreFolder +testFolder/1gn0r3m3.jpg diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/icon_nav_bar.svg b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/icon_nav_bar.svg new file mode 100644 index 00000000..1ea73912 Binary files /dev/null and b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/icon_nav_bar.svg differ diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/icon_ticket_editor.svg b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/icon_ticket_editor.svg new file mode 100644 index 00000000..e69de29b diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/iframe.html b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/iframe.html new file mode 100644 index 00000000..8119fb7f --- /dev/null +++ b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/iframe.html @@ -0,0 +1 @@ +app 1 Iframe diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/logo-small.png b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/logo-small.png new file mode 100644 index 00000000..e69de29b diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/testFolder/1gn0r3m3.jpg b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/assets/testFolder/1gn0r3m3.jpg new file mode 100644 index 00000000..e69de29b diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/manifest.json b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/manifest.json new file mode 100644 index 00000000..d523e0de --- /dev/null +++ b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/manifest.json @@ -0,0 +1,18 @@ +{ + "name": "Test App 1", + "author": { + "name": "Zendesk", + "email": "support@zendesk.com", + "url": "https://help.zendesk.com" + }, + "defaultLocale": "en", + "private": true, + "location": { + "support": { + "ticket_editor": "assets/iframe.html", + "nav_bar": "assets/iframe.html" + } + }, + "version": "1.0", + "frameworkVersion": "2.0" +} diff --git a/packages/zcli-apps/tests/functional/mocks/single_product_ignore/zcli.apps.config.json b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/zcli.apps.config.json new file mode 100644 index 00000000..67bb252a --- /dev/null +++ b/packages/zcli-apps/tests/functional/mocks/single_product_ignore/zcli.apps.config.json @@ -0,0 +1 @@ +{"app_id":123456} diff --git a/packages/zcli-apps/tests/functional/package.test.ts b/packages/zcli-apps/tests/functional/package.test.ts index cc933923..31a2c4e7 100644 --- a/packages/zcli-apps/tests/functional/package.test.ts +++ b/packages/zcli-apps/tests/functional/package.test.ts @@ -1,5 +1,8 @@ import { expect, test } from '@oclif/test' import * as path from 'path' +import * as fs from 'fs' +import * as readline from 'readline' +import * as AdmZip from 'adm-zip' describe('package', function () { const appPath = path.join(__dirname, 'mocks/single_product_app') @@ -16,7 +19,7 @@ describe('package', function () { }) .stdout() .command(['apps:package', appPath]) - .it('should display success message package is created', ctx => { + .it('should display success message if package is created', ctx => { const pkgPath = path.join(path.relative(process.cwd(), appPath), 'tmp', 'app') expect(ctx.stdout).to.contain(`Package created at ${pkgPath}`) }) @@ -36,3 +39,53 @@ describe('package', function () { .catch(err => expect(err.message).to.contain('Error: invalid location')) .it('should display error message if package fails to create') }) + +describe('zcliignore', function () { + const appPath = path.join(__dirname, 'mocks/single_product_ignore') + const tmpPath = path.join(appPath, 'tmp') + + const file = readline.createInterface({ + input: fs.createReadStream(path.join(appPath, '.zcliignore')), + output: process.stdout, + terminal: false + }) + + const ignoreArr: string[] = [] // array that holds each line of the .ignore file + + file.on('line', (line) => { + ignoreArr.push(line) // add to array dynamically + }) + + after(async () => { + fs.readdir(tmpPath, (err, files) => { + if (err) throw err + + for (const file of files) { + fs.unlink(path.join(tmpPath, file), (err) => { + if (err) throw err + }) + } + }) + }) + + test + .env({ + ZENDESK_SUBDOMAIN: 'z3ntest', + ZENDESK_EMAIL: 'admin@z3ntest.com', + ZENDESK_PASSWORD: '123456' // the universal password + }) + .nock('https://z3ntest.zendesk.com', api => { + api + .post('/api/v2/apps/validate') + .reply(200) + }) + .stdout() + .command(['apps:package', appPath]) + .it('should not include certain files as specified in .zcliignore', async () => { + const packagePath = path.join(tmpPath, (fs.readdirSync(tmpPath).find(fn => fn.startsWith('app'))) + '') + const zip = new AdmZip(packagePath) + for (const zipEntry of zip.getEntries()) { + expect(ignoreArr.includes(zipEntry.name)).to.eq(false) + } + }) +}) diff --git a/packages/zcli-core/.DS_Store b/packages/zcli-core/.DS_Store deleted file mode 100644 index 4d976ee1..00000000 Binary files a/packages/zcli-core/.DS_Store and /dev/null differ diff --git a/packages/zcli-core/src/.DS_Store b/packages/zcli-core/src/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/packages/zcli-core/src/.DS_Store and /dev/null differ