From f67ed441f4bf19951bd67a90035b89b0ab41f8c7 Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 15:09:35 +1000 Subject: [PATCH 01/13] Update TS Example to suit new guidance --- example-apps/typescript/.gitignore | 1 + example-apps/typescript/README.md | 18 ------------------ example-apps/typescript/index.js | 2 +- example-apps/typescript/package.json | 16 ++++++---------- example-apps/typescript/src/creates/movie.ts | 11 +++-------- example-apps/typescript/src/index.ts | 16 ++++++---------- .../typescript/src/test/creates.test.ts | 3 +-- .../typescript/src/test/triggers.test.ts | 5 ++--- example-apps/typescript/src/triggers/movie.ts | 7 ++++--- example-apps/typescript/tsconfig.json | 18 +++++++++++------- 10 files changed, 35 insertions(+), 62 deletions(-) diff --git a/example-apps/typescript/.gitignore b/example-apps/typescript/.gitignore index 32dd95d8b..ae6ff4e5e 100644 --- a/example-apps/typescript/.gitignore +++ b/example-apps/typescript/.gitignore @@ -31,6 +31,7 @@ bower_components # Compiled binary addons (https://nodejs.org/api/addons.html) build/ +dist/ # Dependency directories node_modules/ diff --git a/example-apps/typescript/README.md b/example-apps/typescript/README.md index 162f536de..48041dfbf 100644 --- a/example-apps/typescript/README.md +++ b/example-apps/typescript/README.md @@ -22,21 +22,3 @@ zapier push ``` Find out more on the latest docs: https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md. - -# The "typescript" Template - -This example is mainly a proof-of-concept for using features not yet available -in Node. - -In `package.json`, we've define some commonly-used scripts: - -```bash -# Watch and compile as you edit code -npm run watch - -# There's also a non-watch compile command -npm run build - -# To push to Zapier, make sure you compile first -npm run build && zapier push -``` diff --git a/example-apps/typescript/index.js b/example-apps/typescript/index.js index 4d5e21a46..aaa66797e 100644 --- a/example-apps/typescript/index.js +++ b/example-apps/typescript/index.js @@ -1 +1 @@ -module.exports = require('./lib').default; +module.exports = require('./dist').default; diff --git a/example-apps/typescript/package.json b/example-apps/typescript/package.json index 0eb991c1d..24033400e 100644 --- a/example-apps/typescript/package.json +++ b/example-apps/typescript/package.json @@ -2,24 +2,20 @@ "name": "typescript", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "dist/index.js", "scripts": { - "test": "npm run build && jest --testTimeout 10000 --rootDir ./lib/test", + "test": "vitest", "build": "npm run clean && tsc", - "clean": "rimraf ./lib ./build", - "watch": "npm run clean && tsc --watch", + "clean": "rimraf ./dist ./build", "_zapier-build": "npm run build" }, "dependencies": { "zapier-platform-core": "15.12.0" }, "devDependencies": { - "jest": "^25.5.3", - "@types/jest": "^25.2.1", - "@types/node": "^13.13.5", - "@types/node-fetch": "^2.6.11", - "rimraf": "^3.0.2", - "typescript": "^5.5.3" + "rimraf": "^6.0.1", + "typescript": "^5.5.4", + "vitest": "^2.0.5" }, "private": true } diff --git a/example-apps/typescript/src/creates/movie.ts b/example-apps/typescript/src/creates/movie.ts index efbaffb6c..79b7bec56 100644 --- a/example-apps/typescript/src/creates/movie.ts +++ b/example-apps/typescript/src/creates/movie.ts @@ -1,11 +1,6 @@ -import { Bundle, ZObject } from 'zapier-platform-core'; +import { Create, PerformFunction } from 'zapier-platform-core'; -// You can optionally add add the shape of the inputData in bundle, which will pass that -// info down into the function and tests -const perform = async ( - z: ZObject, - bundle: Bundle<{ title: string; year: number }> -) => { +const perform: PerformFunction = async (z, bundle) => { const response = await z.request({ method: 'POST', url: 'https://auth-json-server.zapier-staging.com/movies', @@ -37,4 +32,4 @@ export default { title: 'example', }, }, -}; +} satisfies Create; diff --git a/example-apps/typescript/src/index.ts b/example-apps/typescript/src/index.ts index ba40ba97f..29e9365bd 100644 --- a/example-apps/typescript/src/index.ts +++ b/example-apps/typescript/src/index.ts @@ -1,24 +1,20 @@ -import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core'; +import type { App, BeforeRequestMiddleware } from 'zapier-platform-core'; import MovieCreate from './creates/movie'; import MovieTrigger from './triggers/movie'; import { version as platformVersion } from 'zapier-platform-core'; -const { version } = require('../package.json'); +import packageJson from '../package.json'; -const addApiKeyHeader = ( - req: HttpRequestOptions, - z: ZObject, - bundle: Bundle -) => { +const addApiKeyHeader: BeforeRequestMiddleware = (req, z, bundle) => { // Hard-coded api key just to demo. DON'T do auth like this for your production app! - req.headers = req.headers || {}; + req.headers = req.headers ?? {}; req.headers['X-Api-Key'] = 'secret'; return req; }; export default { - version, + version: packageJson.version, platformVersion, beforeRequest: [addApiKeyHeader], @@ -30,4 +26,4 @@ export default { creates: { [MovieCreate.key]: MovieCreate, }, -}; +} satisfies App; diff --git a/example-apps/typescript/src/test/creates.test.ts b/example-apps/typescript/src/test/creates.test.ts index 5a0d6fb19..e133d7d60 100644 --- a/example-apps/typescript/src/test/creates.test.ts +++ b/example-apps/typescript/src/test/creates.test.ts @@ -1,6 +1,5 @@ -/* globals describe, expect, test */ - import { createAppTester, tools } from 'zapier-platform-core'; +import { describe, test, expect } from 'vitest'; import App from '../index'; diff --git a/example-apps/typescript/src/test/triggers.test.ts b/example-apps/typescript/src/test/triggers.test.ts index 147aeafdc..462eaf131 100644 --- a/example-apps/typescript/src/test/triggers.test.ts +++ b/example-apps/typescript/src/test/triggers.test.ts @@ -1,6 +1,5 @@ -/* globals describe, expect, test */ - -import { Bundle, createAppTester, tools } from 'zapier-platform-core'; +import { createAppTester, tools } from 'zapier-platform-core'; +import { describe, test, expect } from 'vitest'; import App from '../index'; diff --git a/example-apps/typescript/src/triggers/movie.ts b/example-apps/typescript/src/triggers/movie.ts index 66eaf4268..eaaa2ad3d 100644 --- a/example-apps/typescript/src/triggers/movie.ts +++ b/example-apps/typescript/src/triggers/movie.ts @@ -1,6 +1,6 @@ -import { Bundle, ZObject } from 'zapier-platform-core'; +import { PerformFunction, Trigger } from 'zapier-platform-core'; -const perform = async (z: ZObject, bundle: Bundle) => { +const perform: PerformFunction = async (z, bundle) => { const response = await z.request( 'https://auth-json-server.zapier-staging.com/movies' ); @@ -17,10 +17,11 @@ export default { }, operation: { + type: 'polling', perform, sample: { id: '1', title: 'example', }, }, -}; +} satisfies Trigger; diff --git a/example-apps/typescript/tsconfig.json b/example-apps/typescript/tsconfig.json index 6460365c8..b984a0df6 100644 --- a/example-apps/typescript/tsconfig.json +++ b/example-apps/typescript/tsconfig.json @@ -1,12 +1,16 @@ { "compilerOptions": { "target": "ESNext", - "module": "commonjs", - "moduleResolution": "node", - "lib": ["esnext"], - "outDir": "./lib", + "module": "CommonJS", + "moduleResolution": "Node", + "resolveJsonModule": true, + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "outDir": "./dist", "rootDir": "./src", - "strict": true, - "skipLibCheck": true - } + "strict": true + }, + "include": ["./src/**/*.ts"], + "exclude": ["./**/*.test.ts"] } From dc99b89d8e501c1e918ec83894b17db3b7eaee0e Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 16:32:13 +1000 Subject: [PATCH 02/13] Update TS Generated example to suit new guidance --- .../cli/src/generators/templates/gitignore | 1 + .../generators/templates/typescript/README.md | 27 ++++++++++++------- .../templates/typescript/src/creates/movie.ts | 11 +++----- .../templates/typescript/src/index.ts | 16 +++++------ .../typescript/src/test/creates.test.ts | 3 +-- .../typescript/src/test/triggers.test.ts | 5 ++-- .../typescript/src/triggers/movie.ts | 7 ++--- .../templates/typescript/tsconfig.json | 17 +++++++----- 8 files changed, 45 insertions(+), 42 deletions(-) diff --git a/packages/cli/src/generators/templates/gitignore b/packages/cli/src/generators/templates/gitignore index 32dd95d8b..ae6ff4e5e 100644 --- a/packages/cli/src/generators/templates/gitignore +++ b/packages/cli/src/generators/templates/gitignore @@ -31,6 +31,7 @@ bower_components # Compiled binary addons (https://nodejs.org/api/addons.html) build/ +dist/ # Dependency directories node_modules/ diff --git a/packages/cli/src/generators/templates/typescript/README.md b/packages/cli/src/generators/templates/typescript/README.md index d28ea3e1b..48041dfbf 100644 --- a/packages/cli/src/generators/templates/typescript/README.md +++ b/packages/cli/src/generators/templates/typescript/README.md @@ -1,17 +1,24 @@ -# The "typescript" Template +# typescript -This example is mainly a proof-of-concept for using features not yet available -in Node. +This Zapier integration project is generated by the `zapier init` CLI command. -In `package.json`, we've define some commonly-used scripts: +These are what you normally do next: ```bash -# Watch and compile as you edit code -npm run watch +# Install dependencies +npm install # or you can use yarn -# There's also a non-watch compile command -npm run build +# Run tests +zapier test -# To push to Zapier, make sure you compile first -npm run build && zapier push +# Register the integration on Zapier if you haven't +zapier register "App Title" + +# Or you can link to an existing integration on Zapier +zapier link + +# Push it to Zapier +zapier push ``` + +Find out more on the latest docs: https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md. diff --git a/packages/cli/src/generators/templates/typescript/src/creates/movie.ts b/packages/cli/src/generators/templates/typescript/src/creates/movie.ts index efbaffb6c..79b7bec56 100644 --- a/packages/cli/src/generators/templates/typescript/src/creates/movie.ts +++ b/packages/cli/src/generators/templates/typescript/src/creates/movie.ts @@ -1,11 +1,6 @@ -import { Bundle, ZObject } from 'zapier-platform-core'; +import { Create, PerformFunction } from 'zapier-platform-core'; -// You can optionally add add the shape of the inputData in bundle, which will pass that -// info down into the function and tests -const perform = async ( - z: ZObject, - bundle: Bundle<{ title: string; year: number }> -) => { +const perform: PerformFunction = async (z, bundle) => { const response = await z.request({ method: 'POST', url: 'https://auth-json-server.zapier-staging.com/movies', @@ -37,4 +32,4 @@ export default { title: 'example', }, }, -}; +} satisfies Create; diff --git a/packages/cli/src/generators/templates/typescript/src/index.ts b/packages/cli/src/generators/templates/typescript/src/index.ts index ba40ba97f..29e9365bd 100644 --- a/packages/cli/src/generators/templates/typescript/src/index.ts +++ b/packages/cli/src/generators/templates/typescript/src/index.ts @@ -1,24 +1,20 @@ -import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core'; +import type { App, BeforeRequestMiddleware } from 'zapier-platform-core'; import MovieCreate from './creates/movie'; import MovieTrigger from './triggers/movie'; import { version as platformVersion } from 'zapier-platform-core'; -const { version } = require('../package.json'); +import packageJson from '../package.json'; -const addApiKeyHeader = ( - req: HttpRequestOptions, - z: ZObject, - bundle: Bundle -) => { +const addApiKeyHeader: BeforeRequestMiddleware = (req, z, bundle) => { // Hard-coded api key just to demo. DON'T do auth like this for your production app! - req.headers = req.headers || {}; + req.headers = req.headers ?? {}; req.headers['X-Api-Key'] = 'secret'; return req; }; export default { - version, + version: packageJson.version, platformVersion, beforeRequest: [addApiKeyHeader], @@ -30,4 +26,4 @@ export default { creates: { [MovieCreate.key]: MovieCreate, }, -}; +} satisfies App; diff --git a/packages/cli/src/generators/templates/typescript/src/test/creates.test.ts b/packages/cli/src/generators/templates/typescript/src/test/creates.test.ts index 5a0d6fb19..e133d7d60 100644 --- a/packages/cli/src/generators/templates/typescript/src/test/creates.test.ts +++ b/packages/cli/src/generators/templates/typescript/src/test/creates.test.ts @@ -1,6 +1,5 @@ -/* globals describe, expect, test */ - import { createAppTester, tools } from 'zapier-platform-core'; +import { describe, test, expect } from 'vitest'; import App from '../index'; diff --git a/packages/cli/src/generators/templates/typescript/src/test/triggers.test.ts b/packages/cli/src/generators/templates/typescript/src/test/triggers.test.ts index 147aeafdc..462eaf131 100644 --- a/packages/cli/src/generators/templates/typescript/src/test/triggers.test.ts +++ b/packages/cli/src/generators/templates/typescript/src/test/triggers.test.ts @@ -1,6 +1,5 @@ -/* globals describe, expect, test */ - -import { Bundle, createAppTester, tools } from 'zapier-platform-core'; +import { createAppTester, tools } from 'zapier-platform-core'; +import { describe, test, expect } from 'vitest'; import App from '../index'; diff --git a/packages/cli/src/generators/templates/typescript/src/triggers/movie.ts b/packages/cli/src/generators/templates/typescript/src/triggers/movie.ts index 66eaf4268..eaaa2ad3d 100644 --- a/packages/cli/src/generators/templates/typescript/src/triggers/movie.ts +++ b/packages/cli/src/generators/templates/typescript/src/triggers/movie.ts @@ -1,6 +1,6 @@ -import { Bundle, ZObject } from 'zapier-platform-core'; +import { PerformFunction, Trigger } from 'zapier-platform-core'; -const perform = async (z: ZObject, bundle: Bundle) => { +const perform: PerformFunction = async (z, bundle) => { const response = await z.request( 'https://auth-json-server.zapier-staging.com/movies' ); @@ -17,10 +17,11 @@ export default { }, operation: { + type: 'polling', perform, sample: { id: '1', title: 'example', }, }, -}; +} satisfies Trigger; diff --git a/packages/cli/src/generators/templates/typescript/tsconfig.json b/packages/cli/src/generators/templates/typescript/tsconfig.json index db63256e8..b984a0df6 100644 --- a/packages/cli/src/generators/templates/typescript/tsconfig.json +++ b/packages/cli/src/generators/templates/typescript/tsconfig.json @@ -1,11 +1,16 @@ { "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "moduleResolution": "node", - "lib": ["esnext"], - "outDir": "./lib", + "target": "ESNext", + "module": "CommonJS", + "moduleResolution": "Node", + "resolveJsonModule": true, + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "outDir": "./dist", "rootDir": "./src", "strict": true - } + }, + "include": ["./src/**/*.ts"], + "exclude": ["./**/*.test.ts"] } From d95424094bd1907d2bb0cd2b50ba39a4651fd93a Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 16:58:38 +1000 Subject: [PATCH 03/13] Update TS template's package.json --- packages/cli/src/generators/index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/generators/index.js b/packages/cli/src/generators/index.js index 3ab1a66b6..6eeb90396 100644 --- a/packages/cli/src/generators/index.js +++ b/packages/cli/src/generators/index.js @@ -130,17 +130,15 @@ const writeForStandaloneTemplate = (gen) => { }, typescript: { scripts: { + test: 'vitest', + clean: 'rimraf ./dist ./build', build: 'npm run clean && tsc', - clean: 'rimraf ./lib ./build', - watch: 'npm run clean && tsc --watch', - test: 'npm run build && jest --testTimeout 10000 --rootDir ./lib/test', + '_zapier-build': 'npm run build', }, devDependencies: { - '@types/jest': '^26.0.23', - '@types/node': '^14', - '@types/node-fetch': '^2.6.11', - rimraf: '^3.0.2', - typescript: '5.5.3', + rimraf: '^6.0.1', + typescript: '5.5.4', + vitest: '^2.0.5', }, }, }[gen.options.template]; From 41297cc6c3bd75181b62fc0cabc3717b732ac52e Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 17:04:37 +1000 Subject: [PATCH 04/13] Bump rimraf version down to support old Node versions --- example-apps/typescript/package.json | 2 +- packages/cli/src/generators/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example-apps/typescript/package.json b/example-apps/typescript/package.json index 24033400e..4a6298763 100644 --- a/example-apps/typescript/package.json +++ b/example-apps/typescript/package.json @@ -13,7 +13,7 @@ "zapier-platform-core": "15.12.0" }, "devDependencies": { - "rimraf": "^6.0.1", + "rimraf": "^5.0.10", "typescript": "^5.5.4", "vitest": "^2.0.5" }, diff --git a/packages/cli/src/generators/index.js b/packages/cli/src/generators/index.js index 6eeb90396..9602a4686 100644 --- a/packages/cli/src/generators/index.js +++ b/packages/cli/src/generators/index.js @@ -136,7 +136,7 @@ const writeForStandaloneTemplate = (gen) => { '_zapier-build': 'npm run build', }, devDependencies: { - rimraf: '^6.0.1', + rimraf: '^5.0.10', typescript: '5.5.4', vitest: '^2.0.5', }, From 083e1b03a1f6ce76598e6c443d5f3928f230f979 Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 17:16:02 +1000 Subject: [PATCH 05/13] Fix tests to look at dist not lib --- packages/cli/src/tests/utils/build.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/tests/utils/build.js b/packages/cli/src/tests/utils/build.js index 86c104500..4ac011336 100644 --- a/packages/cli/src/tests/utils/build.js +++ b/packages/cli/src/tests/utils/build.js @@ -64,8 +64,8 @@ describe('build (runs slowly)', function () { return build.listFiles(tmpDir).then((dumbPaths) => { // check that way more than the required package files are grabbed dumbPaths.should.containEql('index.js'); - dumbPaths.should.containEql('lib/index.js'); - dumbPaths.should.containEql('lib/triggers/movie.js'); + dumbPaths.should.containEql('dist/index.js'); + dumbPaths.should.containEql('dist/triggers/movie.js'); dumbPaths.should.containEql('src/index.ts'); dumbPaths.should.containEql('src/triggers/movie.ts'); From 9fda85d1c94505f45b2cb706b49858ac4e36380e Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 17:22:19 +1000 Subject: [PATCH 06/13] Remove more lib checks (in favour of dist/ --- packages/cli/src/tests/utils/build.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/tests/utils/build.js b/packages/cli/src/tests/utils/build.js index 4ac011336..89b242a4d 100644 --- a/packages/cli/src/tests/utils/build.js +++ b/packages/cli/src/tests/utils/build.js @@ -51,8 +51,8 @@ describe('build (runs slowly)', function () { // check that only the required lodash files are grabbed smartPaths.should.containEql('index.js'); - smartPaths.should.containEql('lib/index.js'); - smartPaths.should.containEql('lib/triggers/movie.js'); + smartPaths.should.containEql('dist/index.js'); + smartPaths.should.containEql('dist/triggers/movie.js'); smartPaths.filter((p) => p.endsWith('.ts')).length.should.equal(0); smartPaths.should.not.containEql('tsconfig.json'); @@ -307,7 +307,7 @@ describe('build (runs slowly)', function () { await build.maybeRunBuildScript({ cwd: tmpDir }); - const buildExists = await fs.pathExists(path.join(tmpDir, 'lib')); + const buildExists = await fs.pathExists(path.join(tmpDir, 'dist')); should.equal(buildExists, true); }); }); From 4f6a8972787eca6f9985ce2b98dc2130fe261725 Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Mon, 19 Aug 2024 17:22:32 +1000 Subject: [PATCH 07/13] Lower required file amount --- packages/cli/src/tests/utils/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/tests/utils/build.js b/packages/cli/src/tests/utils/build.js index 89b242a4d..4137f45ac 100644 --- a/packages/cli/src/tests/utils/build.js +++ b/packages/cli/src/tests/utils/build.js @@ -71,7 +71,7 @@ describe('build (runs slowly)', function () { dumbPaths.should.containEql('src/triggers/movie.ts'); dumbPaths.should.containEql('tsconfig.json'); - dumbPaths.length.should.be.within(5000, 15000); + dumbPaths.length.should.be.within(3000, 10000); }); }); From abeac307ee5d24a2ecf35504a510906230df84ed Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Tue, 20 Aug 2024 08:40:36 +1000 Subject: [PATCH 08/13] Revert ?? to || because of browserfy --- example-apps/typescript/src/index.ts | 2 +- packages/cli/src/generators/templates/typescript/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example-apps/typescript/src/index.ts b/example-apps/typescript/src/index.ts index 29e9365bd..63c421255 100644 --- a/example-apps/typescript/src/index.ts +++ b/example-apps/typescript/src/index.ts @@ -8,7 +8,7 @@ import packageJson from '../package.json'; const addApiKeyHeader: BeforeRequestMiddleware = (req, z, bundle) => { // Hard-coded api key just to demo. DON'T do auth like this for your production app! - req.headers = req.headers ?? {}; + req.headers = req.headers || {}; req.headers['X-Api-Key'] = 'secret'; return req; }; diff --git a/packages/cli/src/generators/templates/typescript/src/index.ts b/packages/cli/src/generators/templates/typescript/src/index.ts index 29e9365bd..63c421255 100644 --- a/packages/cli/src/generators/templates/typescript/src/index.ts +++ b/packages/cli/src/generators/templates/typescript/src/index.ts @@ -8,7 +8,7 @@ import packageJson from '../package.json'; const addApiKeyHeader: BeforeRequestMiddleware = (req, z, bundle) => { // Hard-coded api key just to demo. DON'T do auth like this for your production app! - req.headers = req.headers ?? {}; + req.headers = req.headers || {}; req.headers['X-Api-Key'] = 'secret'; return req; }; From 7e25a70a8c478be4868e7f370eaaebd4e982c8db Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Fri, 4 Oct 2024 15:26:25 +1000 Subject: [PATCH 09/13] Split out TS template generation to remove Jest --- packages/cli/src/generators/index.js | 50 +++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/generators/index.js b/packages/cli/src/generators/index.js index 9602a4686..4a8dfe9b8 100644 --- a/packages/cli/src/generators/index.js +++ b/packages/cli/src/generators/index.js @@ -56,6 +56,31 @@ const writeGenericPackageJson = (gen, packageJsonExtension) => { ); }; +const writeTypeScriptPackageJson = (gen, packageJsonExtension) => { + gen.fs.writeJSON( + gen.destinationPath('package.json'), + merge( + { + name: gen.options.packageName, + version: '1.0.0', + description: '', + main: 'src/index.js', + scripts: { + test: 'vitest', + }, + dependencies: { + [PLATFORM_PACKAGE]: PACKAGE_VERSION, + }, + devDependencies: { + vitest: '^2.1.2', + }, + private: true, + }, + packageJsonExtension + ) + ); +}; + const writeGenericIndex = (gen, hasAuth) => { gen.fs.copyTpl( gen.templatePath('index.template.js'), @@ -116,7 +141,6 @@ const writeForMinimalTemplate = (gen) => { // example directory const writeForStandaloneTemplate = (gen) => { writeGitignore(gen); - writeGenericReadme(gen); appendReadme(gen); @@ -128,6 +152,22 @@ const writeForStandaloneTemplate = (gen) => { 'form-data': '4.0.0', }, }, + }[gen.options.template]; + + writeGenericPackageJson(gen, packageJsonExtension); + + gen.fs.copy( + gen.templatePath(gen.options.template, '**', '*.{js,json,ts}'), + gen.destinationPath() + ); +}; + +const writeForStandaloneTypeScriptTemplate = (gen) => { + writeGitignore(gen); + writeGenericReadme(gen); + appendReadme(gen); + + const packageJsonExtension = { typescript: { scripts: { test: 'vitest', @@ -137,13 +177,13 @@ const writeForStandaloneTemplate = (gen) => { }, devDependencies: { rimraf: '^5.0.10', - typescript: '5.5.4', - vitest: '^2.0.5', + typescript: '5.6.2', + vitest: '^2.1.2', }, }, }[gen.options.template]; - writeGenericPackageJson(gen, packageJsonExtension); + writeTypeScriptPackageJson(gen, packageJsonExtension); gen.fs.copy( gen.templatePath(gen.options.template, '**', '*.{js,json,ts}'), @@ -163,7 +203,7 @@ const TEMPLATE_ROUTES = { oauth2: writeForAuthTemplate, 'search-or-create': writeForStandaloneTemplate, 'session-auth': writeForAuthTemplate, - typescript: writeForStandaloneTemplate, + typescript: writeForStandaloneTypeScriptTemplate, }; const TEMPLATE_CHOICES = Object.keys(TEMPLATE_ROUTES); From cd7cbda4559b4353d240b92fe095abbaad8d9191 Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Fri, 4 Oct 2024 15:27:37 +1000 Subject: [PATCH 10/13] Fix incorrect ./dist dir in TS template --- packages/cli/src/generators/templates/typescript/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/generators/templates/typescript/index.js b/packages/cli/src/generators/templates/typescript/index.js index 4d5e21a46..aaa66797e 100644 --- a/packages/cli/src/generators/templates/typescript/index.js +++ b/packages/cli/src/generators/templates/typescript/index.js @@ -1 +1 @@ -module.exports = require('./lib').default; +module.exports = require('./dist').default; From c8cefa7c8bc4a4836163b7bd5b267765b41d8225 Mon Sep 17 00:00:00 2001 From: Thomas Cranny Date: Fri, 4 Oct 2024 15:41:12 +1000 Subject: [PATCH 11/13] Depuplicate typescript README contents --- .../generators/templates/typescript/README.md | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/packages/cli/src/generators/templates/typescript/README.md b/packages/cli/src/generators/templates/typescript/README.md index 48041dfbf..50404c9c9 100644 --- a/packages/cli/src/generators/templates/typescript/README.md +++ b/packages/cli/src/generators/templates/typescript/README.md @@ -1,24 +1,3 @@ -# typescript +# TypeScript Template -This Zapier integration project is generated by the `zapier init` CLI command. - -These are what you normally do next: - -```bash -# Install dependencies -npm install # or you can use yarn - -# Run tests -zapier test - -# Register the integration on Zapier if you haven't -zapier register "App Title" - -# Or you can link to an existing integration on Zapier -zapier link - -# Push it to Zapier -zapier push -``` - -Find out more on the latest docs: https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md. +An TypeScript template for Zapier Integrations. From c0c5de564bd388544b9565387bb17e9654757ecb Mon Sep 17 00:00:00 2001 From: Chang-Hung Liang Date: Fri, 4 Oct 2024 18:30:50 +0800 Subject: [PATCH 12/13] Remove Node.js 16 from CI --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 648e72883..c73715e46 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -83,7 +83,7 @@ jobs: - ubuntu-latest # TODO: Fix tests on Windows # - windows-latest - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -108,7 +108,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -142,7 +142,7 @@ jobs: - ubuntu-latest # TODO: Fix tests on Windows # - windows-latest - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 From ae3e34d5c2edddee3aaaf521310356ef4e1ffaaa Mon Sep 17 00:00:00 2001 From: Chang-Hung Liang Date: Fri, 4 Oct 2024 18:39:11 +0800 Subject: [PATCH 13/13] Upgrade mock-fs --- packages/core/package.json | 2 +- yarn.lock | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 3f29f4895..3c266dcf5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -61,7 +61,7 @@ "aws-sdk": "^2.1397.0", "dicer": "^0.3.1", "fs-extra": "^11.1.1", - "mock-fs": "^5.2.0", + "mock-fs": "^5.3.0", "nock": "^13.5.4", "tsd": "^0.31.1" }, diff --git a/yarn.lock b/yarn.lock index 42822da27..22b74c215 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8331,6 +8331,11 @@ mock-fs@^5.2.0: resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-5.2.0.tgz#3502a9499c84c0a1218ee4bf92ae5bf2ea9b2b5e" integrity sha512-2dF2R6YMSZbpip1V1WHKGLNjr/k48uQClqMVb5H3MOvwc9qhYis3/IWbj02qIg/Y8MDXKFF4c5v0rxx2o6xTZw== +mock-fs@^5.3.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-5.3.0.tgz#7dfc95ce5528aff8e10fa117161b91d8129e0e9e" + integrity sha512-IMvz1X+RF7vf+ur7qUenXMR7/FSKSIqS3HqFHXcyNI7G0FbpFO8L5lfsUJhl+bhK1AiulVHWKUSxebWauPA+xQ== + mock-stdin@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/mock-stdin/-/mock-stdin-1.0.0.tgz#efcfaf4b18077e14541742fd758b9cae4e5365ea"