Repository: teleporthq/teleport-code-generators (ts)

Issue:
Publishers - Unnecessary "projectName" property in the publishers factory params interface
All the available publishers extend a base interface that currently has two properties: `project` and `projectName`.

```typescript
export interface PublisherFactoryParams {
  project?: GeneratedFolder
  projectName?: string
}
```

It was expected that all the properties from this interface will be use through all the publishers. The `projectName` is only used in the `teleport-publisher-zip` package, so I'm thinking that it can be extracted from this interface and made available only from the disk publisher.

We should have in the zip publisher a getter and a setter for this property.


Pull request description:
refactor: Removed the "projectName" property from the publisher inter…
fixes #254

Patch:
diff --git a/.gitignore b/.gitignore
index 3a7cc136..679ddb76 100755
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,4 @@ node_modules/
 
 .changelog
 
-examples/project-exporters/yarn.lock
-
-packages/teleport-project-packer-test/src/config.json
\ No newline at end of file
+examples/project-exporters/yarn.lock
\ No newline at end of file
diff --git a/README.md b/README.md
index 281e8d04..9972e53c 100755
--- a/README.md
+++ b/README.md
@@ -352,18 +352,9 @@ yarn test
 yarn test:coverage
 ```
 
-Furthermore, there's a `private` package inside the lerna folder called `teleport-project-packer-test`. That packages can be used to **test** the code/file generation process with any flavor of project/component generator. In order to give it a spin you will have to run:
-
+Furthermore, there's a `private` package inside the lerna folder called `teleport-project-packer-test`. That packages can be used to **test** the code/file generation process with any flavor of project/component generator. In order to give it a spin:
 ```
 cd packages/teleport-project-packer-test
-cp config.example.json config.json
-
-```
-
-You will have to replace the placeholder with [your own github token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line).
-Then you can run it with:
-
-```
 npm start
 ```
 This version of the packer uses the UIDLs from the `examples/uidl-sample`. If the process runs successfully, you will see the responoses from the project packer in the format: `{ success: true, payload: 'dist' }`. The task uses the `teleport-publisher-disk` package and generates four different project files in the `dist` folder.
diff --git a/packages/teleport-publisher-zip/src/index.ts b/packages/teleport-publisher-zip/src/index.ts
index 6234a167..64b753bb 100644
--- a/packages/teleport-publisher-zip/src/index.ts
+++ b/packages/teleport-publisher-zip/src/index.ts
@@ -11,18 +11,20 @@ declare type ZipPublisherResponse = string | Buffer | Blob
 
 export interface ZipFactoryParams extends PublisherFactoryParams {
   outputPath?: string
+  outputZipName?: string
 }
 
 export interface ZipPublisher extends Publisher<ZipFactoryParams, ZipPublisherResponse> {
   getOutputPath: () => string
   setOutputPath: (path: string) => void
+  getOutputZipName: () => string
+  setOutputZipName: (name: string) => void
 }
 
 export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher> = (
   params: ZipFactoryParams = {}
 ): ZipPublisher => {
-  const { projectName } = params
-  let { project, outputPath } = params
+  let { project, outputPath, outputZipName } = params
 
   const getProject = () => project
   const setProject = (projectToSet: GeneratedFolder) => {
@@ -34,18 +36,26 @@ export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher
     outputPath = path
   }
 
+  const getOutputZipName = () => outputZipName
+  const setOutputZipName = (name: string) => {
+    outputZipName = name
+  }
+
   const publish = async (options: ZipFactoryParams = {}) => {
-    const projectOutputPath = options.outputPath || outputPath
     const projectToPublish = options.project || project
     if (!projectToPublish) {
       return { success: false, payload: NO_PROJECT_UIDL }
     }
 
+    const projectOutputPath = options.outputPath || outputPath
+    const projectOutputZipName = options.outputZipName || outputZipName
+
     try {
       const zipContent = await generateProjectZip(projectToPublish)
 
       if (projectOutputPath && isNodeProcess()) {
-        await writeZipToDisk(projectOutputPath, zipContent, projectName || projectToPublish.name)
+        const zipName = projectOutputZipName || projectToPublish.name
+        await writeZipToDisk(projectOutputPath, zipContent, zipName)
       }
       return { success: true, payload: zipContent }
     } catch (error) {
@@ -59,6 +69,8 @@ export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher
     setProject,
     getOutputPath,
     setOutputPath,
+    getOutputZipName,
+    setOutputZipName,
   }
 }
 
diff --git a/packages/teleport-types/src/generators.ts b/packages/teleport-types/src/generators.ts
index 1ebae254..ccf5db83 100644
--- a/packages/teleport-types/src/generators.ts
+++ b/packages/teleport-types/src/generators.ts
@@ -184,7 +184,7 @@ export type GenerateComponentFunction = (
 /**
  * Interfaces used in the publishers
  */
-export type PublisherFactory<T, U> = (configuration?: Partial<T & PublisherFactoryParams>) => U
+export type PublisherFactory<T, U> = (configuration?: Partial<T>) => U
 
 export interface Publisher<T, U> {
   publish: (options?: T) => Promise<PublisherResponse<U>>
@@ -194,7 +194,6 @@ export interface Publisher<T, U> {
 
 export interface PublisherFactoryParams {
   project?: GeneratedFolder
-  projectName?: string
 }
 export interface PublisherResponse<T> {
   success: boolean


Test patch:
diff --git a/packages/teleport-project-packer-test/src/config.example.json b/packages/teleport-project-packer-test/src/config.example.json
deleted file mode 100644
index ca26f88d..00000000
--- a/packages/teleport-project-packer-test/src/config.example.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-    "token": "<your-token-here>"
-}
\ No newline at end of file
diff --git a/packages/teleport-project-packer-test/src/index.ts b/packages/teleport-project-packer-test/src/index.ts
index 3a1b60a5..d5b5b243 100644
--- a/packages/teleport-project-packer-test/src/index.ts
+++ b/packages/teleport-project-packer-test/src/index.ts
@@ -8,8 +8,6 @@ import vueNuxtGenerator from '@teleporthq/teleport-project-generator-vue-nuxt'
 import { createDiskPublisher } from '@teleporthq/teleport-publisher-disk'
 import { ProjectUIDL, RemoteTemplateDefinition } from '@teleporthq/teleport-types'
 
-import config from './config.json'
-
 import {
   GITHUB_TEMPLATE_OWNER,
   REACT_BASIC_GITHUB_PROJECT,
@@ -45,8 +43,9 @@ const publisher = createDiskPublisher({
 const packProject = async (projectType: string) => {
   const remoteTemplate = templates[projectType] as RemoteTemplateDefinition
 
+  // fill in with your github token - https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line
   remoteTemplate.auth = {
-    token: config.token,
+    token: '<your-token-here>',
   }
 
   projectPacker.setPublisher(publisher)
diff --git a/packages/teleport-publisher-zip/__tests__/index.ts b/packages/teleport-publisher-zip/__tests__/index.ts
index 4991c844..680f28c3 100644
--- a/packages/teleport-publisher-zip/__tests__/index.ts
+++ b/packages/teleport-publisher-zip/__tests__/index.ts
@@ -4,9 +4,11 @@ import JSZip from 'jszip'
 
 import { createZipPublisher } from '../src'
 
-import project from './project-files.json'
 import { NO_PROJECT_UIDL } from '../src/errors'
 
+// @ts-ignore
+import project from './project-files.json'
+
 const projectPath = join(__dirname, 'disk-project')
 
 afterAll(() => {
@@ -40,6 +42,15 @@ describe('teleport publisher zip', () => {
     expect(publisherPath).toBe(path)
   })
 
+  it('should set output zip file name', () => {
+    const publisher = createZipPublisher()
+    const zipName = 'zip-name'
+    publisher.setOutputZipName(zipName)
+
+    const publisherZipName = publisher.getOutputZipName()
+    expect(publisherZipName).toBe(zipName)
+  })
+
   it('should fail if no project is provided', async () => {
     const publisher = createZipPublisher()
 
@@ -57,11 +68,12 @@ describe('teleport publisher zip', () => {
 
   it('should generate project and write the zip to disk if output is provided', async () => {
     const publisher = createZipPublisher({ project, outputPath: projectPath })
+    const zipName = 'zip-name'
 
-    const { success, payload } = await publisher.publish()
+    const { success, payload } = await publisher.publish({ outputZipName: zipName })
     expect(success).toBeTruthy()
 
-    const zipPath = join(projectPath, `${project.name}.zip`)
+    const zipPath = join(projectPath, `${zipName}.zip`)
     const zipFileExists = existsSync(zipPath)
     expect(zipFileExists).toBeTruthy()
 
@@ -86,6 +98,17 @@ describe('teleport publisher zip', () => {
   })
 })
 
+it('should generate project and write the zip to disk having the project name as follback for zip name', async () => {
+  const publisher = createZipPublisher({ project, outputPath: projectPath })
+
+  const { success } = await publisher.publish()
+  expect(success).toBeTruthy()
+
+  const zipPath = join(projectPath, `${project.name}.zip`)
+  const zipFileExists = existsSync(zipPath)
+  expect(zipFileExists).toBeTruthy()
+})
+
 const removeDirectory = (dirPath: string): void => {
   if (!existsSync(dirPath)) {
     return