Skip to content

Commit

Permalink
Delegate types generation to extension package
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Sep 1, 2024
1 parent b48f0f8 commit b94c575
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 7 deletions.
7 changes: 7 additions & 0 deletions programs/cli/__spec__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ╚═════╝╚══════╝╚═╝

import path from 'path'
import fs from 'fs'
import {execFile} from 'child_process'
import {promisify} from 'util'

Expand All @@ -31,4 +32,10 @@ describe('CLI Commands', () => {
const {stdout} = await extensionProgram('--help')
expect(stdout).toContain('Usage:')
}, 30000)

it('should output the types/ folder by default', async () => {
await extensionProgram('')
const typesDirectory = path.resolve(__dirname, '..', 'dist', 'types')
expect(fs.existsSync(typesDirectory)).toBeTruthy()
})
})
19 changes: 19 additions & 0 deletions programs/cli/install_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

echo '►►► Generating client types/ folder'
static_files=(
"$(dirname "$0")/types"
)

for file in "${static_files[@]}"; do
if [ -e "$file" ]; then
# echo "Copying $file to $(dirname "$0")/dist/"
cp -r "$file" "$(dirname "$0")/dist/"
else
echo "File $file does not exist"
fi
done

echo '►►► All tasks completed'
3 changes: 2 additions & 1 deletion programs/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
},
"scripts": {
"watch": "yarn compile --watch",
"compile:types": "bash install_scripts.sh",
"compile:readme-files": "node ./scripts/copyMarkdownFilesToCli.js",
"compile:tailwind-config": "node ./scripts/copyTailwindConfig.js",
"compile:stylelint-config": "node ./scripts/copyStylelintConfig.js",
"compile:cli": "tsup-node ./cli.ts --format cjs --dts --target=node18",
"compile": "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config &&yarn compile:cli",
"compile": "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config && yarn compile:cli && yarn compile:types",
"clean": "rm -rf dist",
"test": "echo \"Note: no test specified\" && exit 0",
"test:cli": "jest __spec__/cli.spec.ts"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 15 additions & 3 deletions programs/create/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {ALL_TEMPLATES, DEFAULT_TEMPLATE} from '../../examples/data'
import {extensionCreate} from './dist/module'

function fileExists(templateName: string, filePath?: string): boolean {
const templatePath = path.resolve(__dirname, 'dist', 'test-template-' + templateName)
const templatePath = path.resolve(
__dirname,
'dist',
'test-template-' + templateName
)
return fs.existsSync(path.join(templatePath, filePath || ''))
}

Expand All @@ -24,7 +28,11 @@ async function removeDir(dirPath: string) {
async function removeAllTemplateFolders() {
await Promise.all(
ALL_TEMPLATES.map(async (template) => {
const templatePath = path.resolve(__dirname, 'dist', 'test-template-' + template.name)
const templatePath = path.resolve(
__dirname,
'dist',
'test-template-' + template.name
)

console.log('Removing template:', templatePath)

Expand Down Expand Up @@ -56,7 +64,11 @@ describe('extension create', () => {
it.each(ALL_TEMPLATES)(
`creates the "$name" extension template`,
async (template) => {
const templatePath = path.join(__dirname, 'dist', 'test-template-' + template.name)
const templatePath = path.join(
__dirname,
'dist',
'test-template-' + template.name
)

await extensionCreate(templatePath, {
template: template.name,
Expand Down
2 changes: 1 addition & 1 deletion programs/create/steps/generate-extension-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateExtensionTypes(
const typePath =
process.env.EXTENSION_ENV === 'development'
? path.resolve(process.cwd(), 'programs/develop/types')
: 'extension-develop/dist/types'
: 'extension/dist/types'

const fileContent = `\
// Required Extension.js types for TypeScript projects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function generateExtensionTypes(projectDir: string) {
const typePath =
process.env.EXTENSION_ENV === 'development'
? relativeTypePath
: `extension-develop/dist/types`
: `extension/dist/types`

const fileContent = `\
// Required Extension.js types for TypeScript projects.
Expand Down
1 change: 0 additions & 1 deletion programs/develop/install_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ echo '►►► Setting up client helper files'
static_files=(
"$(dirname "$0")/tailwind.config.js"
"$(dirname "$0")/stylelint.config.json"
"$(dirname "$0")/types"
"$(dirname "$0")/webpack/plugin-reload/extensions"
)

Expand Down

0 comments on commit b94c575

Please sign in to comment.