Skip to content

Commit

Permalink
test: fix github reference and clean up files
Browse files Browse the repository at this point in the history
  • Loading branch information
timlrx committed May 22, 2022
1 parent 6d66c60 commit edff488
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
"type": "git",
"url": "https://github.com/timlrx/pliny"
}
}
}
37 changes: 19 additions & 18 deletions packages/cli/src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class New extends Command {
static flags = {
help: Flags.help({ char: 'h' }),
template: Flags.string({
description: 'Pick your new app template. Options: minimal, blog.',
options: ['minimal, blog'],
description: 'Pick your new app template. Options: starter-blog.',
options: ['starter-blog'],
}),
npm: Flags.boolean({
description: 'Use npm as the package manager',
Expand Down Expand Up @@ -81,7 +81,7 @@ export class New extends Command {
private async installTemplate(flags: Flags, args: Record<string, any>): Promise<void> {
const name = args.name
// Can revert to `starter/${args.template}` to support more starter templates in the future
const template = `${args.template}`
const template = `${this.template}`
let cmd
// Should run no-install regardless of flag and do a post-install
const opts = ['--example', REPO_ROOT, '--example-path', template, name]
Expand Down Expand Up @@ -147,21 +147,22 @@ export class New extends Command {

private async determineTemplate(flags: Flags): Promise<void> {
if (flags.template) {
return
this.template = flags.template as Template
} else {
const choices: Array<{ name: Template; message?: string }> = [
{ name: 'starter-blog', message: 'Default starter blog template with tailwind' },
{ name: 'starter-doc', message: 'Documentation template (TODO, WIP)' },
]
const { template } = (await this.enquirer.prompt({
type: 'select',
name: 'template',
message: 'Pick your new app template',
initial: 0,
choices,
})) as { template: Template }

this.template = template
}
const choices: Array<{ name: Template; message?: string }> = [
{ name: 'starter-blog', message: 'Default starter blog template with tailwind' },
{ name: 'starter-doc', message: 'Documentation template (TODO, WIP)' },
]
const { template } = (await this.enquirer.prompt({
type: 'select',
name: 'template',
message: 'Pick your new app template',
initial: 0,
choices,
})) as { template: Template }

this.template = template
}

async run() {
Expand All @@ -171,7 +172,7 @@ export class New extends Command {

await this.determineLanguage(flags)
// Currently, there's only one starter template - disable option
// await this.determineTemplate(flags)
await this.determineTemplate(flags)
await this.determinePkgManagerToInstallDeps(flags)
await this.installTemplate(flags, args)
const { pkgManager, template } = this
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/commands/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('`install` command', () => {
it('properly parses remote installer args', () => {
const normalizePath = Install.prototype.normalizeRecipePath
expect(normalizePath('test-installer')).toEqual({
path: 'https://github.com/timlrx/pliny',
path: 'https://github.com/timlrx/pliny/',
subdirectory: 'recipes/test-installer',
location: RecipeLocation.Remote,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ describe('`new` command', () => {
stdout.stop()
})

// jest.setTimeout(200 * 1000)

async function whileStayingInCWD(task: () => PromiseLike<void>) {
const oldCWD = process.cwd()
await task()
Expand All @@ -71,23 +69,26 @@ describe('`new` command', () => {
}

async function usingTempDir(fn: (...args: any[]) => any, options?: any) {
const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
// const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
const folder = path.join(__dirname, 'tmp')
await fs.mkdirp(folder, options)
try {
await fn(folder)
} finally {
await fs.remove(folder)
}
await fn(folder)
// try {
// await fn(folder)
// } finally {
// await fs.remove(folder)
// }
}

// node packages/cli/bin/run new /home/timlrx/pliny/packages/cli/test/commands/tmp --template=starter-blog --ts
async function withNewApp(
flags: string[],
test: (dirName: string, packageJson: any) => Promise<void> | void
) {
await usingTempDir(async (tempDir) => {
// await whileStayingInCWD(() => New.run([tempDir, '--skip-install', ...flags]))
// TODO: Revert to the above line after skip-install option is enabled on create-next-app
await whileStayingInCWD(() => New.run([tempDir, ...flags]))
process.chdir(tempDir)
await New.run([tempDir, ...flags])

const packageJsonFile = fs.readFileSync(path.join(tempDir, 'package.json'), {
encoding: 'utf8',
Expand All @@ -97,12 +98,12 @@ describe('`new` command', () => {

await test(tempDir, packageJson)

rimraf.sync(tempDir)
// rimraf.sync(tempDir)
})
}

test('generate typescript application', async () => {
await withNewApp(['--ts'], (dirName, packageJson) => {
await withNewApp(['--template=starter-blog', '--ts'], (dirName, packageJson) => {
const files = [
'package.json',
'pages/index.tsx',
Expand All @@ -116,7 +117,7 @@ describe('`new` command', () => {

files.forEach((file) => expect(fs.existsSync(path.join(dirName, file))).toBeTruthy())
})
}, 100000)
}, 1000000)

// test('pins Blitz to the current version', async () =>
// await withNewApp([], async (_dirName, packageJson) => {
Expand Down
22 changes: 0 additions & 22 deletions recipes/add-blog/test/info.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('install recipe', () => {

async function usingTempDir(fn: (...args: any[]) => any, options?: any) {
// const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
const folder = path.join(__dirname, 'do-not-delete')
const folder = path.join(__dirname, 'tmp')
await fs.mkdirp(folder, options)
// await fn(folder)
try {
Expand All @@ -31,13 +31,13 @@ describe('install recipe', () => {
}

async function withNewApp(
args: RecipeCLIArgs,
args: string[],
test: (dirName: string, packageJson: any) => Promise<void> | void
) {
await usingTempDir(async (tempDir) => {
fs.copySync(path.join(__dirname, '__fixtures__/sample-next-js-app'), `${tempDir}`)
process.chdir(tempDir)
await Install.run([recipeDir, 'ContentName=dog', 'ContentDir=content', '--yes'])
await Install.run([recipeDir, ...args])

const packageJsonFile = fs.readFileSync(path.join(tempDir, 'package.json'), {
encoding: 'utf8',
Expand All @@ -50,11 +50,11 @@ describe('install recipe', () => {
}

test('copy over files with correct substitutions for js app', async () => {
await withNewApp({ ContentDir: 'content', ContentName: 'dog' }, (dirName, packageJson) => {
await withNewApp(['ContentName=dog', 'ContentDir=content', '--yes'], (dirName, packageJson) => {
const files = ['content/dog/sample.mdx', 'pages/dog/index.js', 'pages/dog/[...slug].js']
files.forEach((file) => {
expect(fs.existsSync(path.resolve(dirName, file))).toBeTruthy()
})
})
})
}, 10000)
})
2 changes: 1 addition & 1 deletion vitest-exclude-recipe.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { configDefaults, defineConfig } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/install.test.ts', '**/install-recipe.test.ts'],
exclude: [...configDefaults.exclude, '**/new.test.ts', '**/install-recipe.test.ts'],
},
})

0 comments on commit edff488

Please sign in to comment.