Skip to content

Commit

Permalink
uses the app name as folder name for generation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopiraccini committed Dec 1, 2023
1 parent 8dda711 commit dcf201d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/main/generate.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { stat } from 'node:fs/promises'
import { stat, mkdir } from 'node:fs/promises'
import { join, resolve } from 'node:path'
import { getPkgManager } from './lib/get-package-manager.mjs'
import { importOrLocal } from './lib/import-or-local.mjs'
import errors from './errors.mjs'
import split from 'split2'

export const prepareFolder = async (path, tempNames, logger) => {
export const prepareFolder = async (path, tempNames, logger, appName = 'appName') => {
const s = await stat(path)
if (!s.isDirectory()) {
logger.error({ path }, `Path ${path} is not a directory`)
throw new Error(`Path ${path} is not a directory`)
}
const newFolder = join(resolve(path), appName)
await mkdir(newFolder)

const pkgManager = await getPkgManager()
const templateVariables = {}
try {
for (const name of tempNames) {
const template = await importOrLocal({
pkgManager,
projectDir: path,
projectDir: newFolder,
pkg: name,
logger
})
Expand Down Expand Up @@ -49,8 +52,9 @@ export const prepareFolder = async (path, tempNames, logger) => {
// }
// ]
// ]
export const createApp = async (projectDir, { projectName, services, entrypoint, port, logLevel, typescript, createGitHubRepository, installGitHubAction }, logger) => {
export const createApp = async (dir, { projectName, services, entrypoint, port, logLevel, typescript, createGitHubRepository, installGitHubAction }, logger) => {
const { execa } = await import('execa')
const projectDir = join(dir, projectName)

if (!services || services.length === 0) {
logger.error('No services to create')
Expand Down
6 changes: 3 additions & 3 deletions test/main/prepare-folder.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ beforeEach(() => {

test('Installs no templates or plugins', async () => {
const appDir = await mkdtemp(join(tmpdir(), 'plat-app-test-create'))
await prepareFolder(appDir, [], [], logger)
await prepareFolder(appDir, [], logger, 'test-app')
expect(logger.errors.length).toBe(0)
})

test('Install in non-existent folder', async () => {
try {
await prepareFolder('testnonexitent', [], logger)
await prepareFolder('testnonexitent', [], logger, 'test-app')
throw new Error('Should have thrown an error')
} catch (err) {
expect(err).toBeInstanceOf(Error)
Expand All @@ -53,7 +53,7 @@ test('Install a non-existent template', async () => {

test('Install one @platformatic/service template', async () => {
const appDir = await mkdtemp(join(tmpdir(), 'plat-app-test-create'))
await prepareFolder(appDir, ['@platformatic/service'], logger)
await prepareFolder(appDir, ['@platformatic/service'], logger, 'test-app')
expect(logger.infos[0][0].name).toEqual('@platformatic/service')
expect(logger.errors.length).toBe(0)
}, 30000)

0 comments on commit dcf201d

Please sign in to comment.