Skip to content

Commit

Permalink
Revert "Revert "Zcli package ignore" (#144)"
Browse files Browse the repository at this point in the history
This reverts commit 625ca70.
  • Loading branch information
etanxing authored Nov 10, 2022
1 parent 625ca70 commit 75e859c
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ yarn-error.log
.vscode
packages/zcli-apps/tests/functional/mocks/*/tmp
packages/**/dist
.DS_Store
25 changes: 17 additions & 8 deletions docs/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand All @@ -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]`

Expand Down
12 changes: 10 additions & 2 deletions packages/zcli-apps/src/lib/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
assets/logo-small.png
assets/iframe.html
assets/icon_nav_bar.svg
manifest.json
testFolder/ignoreFolder
testFolder/1gn0r3m3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app 1 Iframe
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Test App 1",
"author": {
"name": "Zendesk",
"email": "[email protected]",
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"app_id":123456}
55 changes: 54 additions & 1 deletion packages/zcli-apps/tests/functional/package.test.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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}`)
})
Expand All @@ -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: '[email protected]',
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)
}
})
})
Binary file removed packages/zcli-core/.DS_Store
Binary file not shown.
Binary file removed packages/zcli-core/src/.DS_Store
Binary file not shown.

0 comments on commit 75e859c

Please sign in to comment.