Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zcli package ignore #142

Merged
merged 18 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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).filter(fn => fn.startsWith('app')) + ''))
max1adam marked this conversation as resolved.
Show resolved Hide resolved
const zip = new AdmZip(packagePath)
for (const zipEntry of zip.getEntries()) {
expect(ignoreArr.includes(zipEntry.name)).to.eq(false)
}
})
})
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4382,6 +4382,11 @@ ignore@^5.1.1, ignore@^5.1.8, ignore@^5.2.0:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==

immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==

import-fresh@^3.0.0, import-fresh@^3.2.1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
Expand Down Expand Up @@ -4905,6 +4910,16 @@ jsonparse@^1.2.0, jsonparse@^1.3.1:
array-includes "^3.1.5"
object.assign "^4.1.2"

jszip@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2"
integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
dependencies:
lie "~3.3.0"
pako "~1.0.2"
readable-stream "~2.3.6"
setimmediate "^1.0.5"

just-diff-apply@^5.2.0:
version "5.3.1"
resolved "https://registry.yarnpkg.com/just-diff-apply/-/just-diff-apply-5.3.1.tgz#30f40809ffed55ad76dccf73fa9b85a76964c867"
Expand Down Expand Up @@ -5007,6 +5022,13 @@ libnpmpublish@^4.0.0:
semver "^7.1.3"
ssri "^8.0.1"

lie@~3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==
dependencies:
immediate "~3.0.5"

lines-and-columns@^1.1.6:
version "1.2.4"
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
Expand Down Expand Up @@ -6213,6 +6235,11 @@ pacote@^13.0.3, pacote@^13.0.5, pacote@^13.4.1:
ssri "^9.0.0"
tar "^6.1.11"

pako@~1.0.2:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==

parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
Expand Down Expand Up @@ -6958,6 +6985,11 @@ set-blocking@^2.0.0:
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==

setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
Expand Down