Skip to content

Commit edff488

Browse files
committed
test: fix github reference and clean up files
1 parent 6d66c60 commit edff488

File tree

7 files changed

+41
-61
lines changed

7 files changed

+41
-61
lines changed

packages/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@
8080
"type": "git",
8181
"url": "https://github.com/timlrx/pliny"
8282
}
83-
}
83+
}

packages/cli/src/commands/new.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export class New extends Command {
4848
static flags = {
4949
help: Flags.help({ char: 'h' }),
5050
template: Flags.string({
51-
description: 'Pick your new app template. Options: minimal, blog.',
52-
options: ['minimal, blog'],
51+
description: 'Pick your new app template. Options: starter-blog.',
52+
options: ['starter-blog'],
5353
}),
5454
npm: Flags.boolean({
5555
description: 'Use npm as the package manager',
@@ -81,7 +81,7 @@ export class New extends Command {
8181
private async installTemplate(flags: Flags, args: Record<string, any>): Promise<void> {
8282
const name = args.name
8383
// Can revert to `starter/${args.template}` to support more starter templates in the future
84-
const template = `${args.template}`
84+
const template = `${this.template}`
8585
let cmd
8686
// Should run no-install regardless of flag and do a post-install
8787
const opts = ['--example', REPO_ROOT, '--example-path', template, name]
@@ -147,21 +147,22 @@ export class New extends Command {
147147

148148
private async determineTemplate(flags: Flags): Promise<void> {
149149
if (flags.template) {
150-
return
150+
this.template = flags.template as Template
151+
} else {
152+
const choices: Array<{ name: Template; message?: string }> = [
153+
{ name: 'starter-blog', message: 'Default starter blog template with tailwind' },
154+
{ name: 'starter-doc', message: 'Documentation template (TODO, WIP)' },
155+
]
156+
const { template } = (await this.enquirer.prompt({
157+
type: 'select',
158+
name: 'template',
159+
message: 'Pick your new app template',
160+
initial: 0,
161+
choices,
162+
})) as { template: Template }
163+
164+
this.template = template
151165
}
152-
const choices: Array<{ name: Template; message?: string }> = [
153-
{ name: 'starter-blog', message: 'Default starter blog template with tailwind' },
154-
{ name: 'starter-doc', message: 'Documentation template (TODO, WIP)' },
155-
]
156-
const { template } = (await this.enquirer.prompt({
157-
type: 'select',
158-
name: 'template',
159-
message: 'Pick your new app template',
160-
initial: 0,
161-
choices,
162-
})) as { template: Template }
163-
164-
this.template = template
165166
}
166167

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

172173
await this.determineLanguage(flags)
173174
// Currently, there's only one starter template - disable option
174-
// await this.determineTemplate(flags)
175+
await this.determineTemplate(flags)
175176
await this.determinePkgManagerToInstallDeps(flags)
176177
await this.installTemplate(flags, args)
177178
const { pkgManager, template } = this

packages/cli/test/commands/install.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('`install` command', () => {
2020
it('properly parses remote installer args', () => {
2121
const normalizePath = Install.prototype.normalizeRecipePath
2222
expect(normalizePath('test-installer')).toEqual({
23-
path: 'https://github.com/timlrx/pliny',
23+
path: 'https://github.com/timlrx/pliny/',
2424
subdirectory: 'recipes/test-installer',
2525
location: RecipeLocation.Remote,
2626
})

packages/cli/test/commands/new.skip-test.ts packages/cli/test/commands/new.test.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ describe('`new` command', () => {
4949
stdout.stop()
5050
})
5151

52-
// jest.setTimeout(200 * 1000)
53-
5452
async function whileStayingInCWD(task: () => PromiseLike<void>) {
5553
const oldCWD = process.cwd()
5654
await task()
@@ -71,23 +69,26 @@ describe('`new` command', () => {
7169
}
7270

7371
async function usingTempDir(fn: (...args: any[]) => any, options?: any) {
74-
const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
72+
// const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
73+
const folder = path.join(__dirname, 'tmp')
7574
await fs.mkdirp(folder, options)
76-
try {
77-
await fn(folder)
78-
} finally {
79-
await fs.remove(folder)
80-
}
75+
await fn(folder)
76+
// try {
77+
// await fn(folder)
78+
// } finally {
79+
// await fs.remove(folder)
80+
// }
8181
}
82-
82+
// node packages/cli/bin/run new /home/timlrx/pliny/packages/cli/test/commands/tmp --template=starter-blog --ts
8383
async function withNewApp(
8484
flags: string[],
8585
test: (dirName: string, packageJson: any) => Promise<void> | void
8686
) {
8787
await usingTempDir(async (tempDir) => {
8888
// await whileStayingInCWD(() => New.run([tempDir, '--skip-install', ...flags]))
8989
// TODO: Revert to the above line after skip-install option is enabled on create-next-app
90-
await whileStayingInCWD(() => New.run([tempDir, ...flags]))
90+
process.chdir(tempDir)
91+
await New.run([tempDir, ...flags])
9192

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

9899
await test(tempDir, packageJson)
99100

100-
rimraf.sync(tempDir)
101+
// rimraf.sync(tempDir)
101102
})
102103
}
103104

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

117118
files.forEach((file) => expect(fs.existsSync(path.join(dirName, file))).toBeTruthy())
118119
})
119-
}, 100000)
120+
}, 1000000)
120121

121122
// test('pins Blitz to the current version', async () =>
122123
// await withNewApp([], async (_dirName, packageJson) => {

recipes/add-blog/test/info.txt

-22
This file was deleted.

recipes/add-blog/test/install.test.ts recipes/add-blog/test/install-recipe.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('install recipe', () => {
2020

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

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

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

5252
test('copy over files with correct substitutions for js app', async () => {
53-
await withNewApp({ ContentDir: 'content', ContentName: 'dog' }, (dirName, packageJson) => {
53+
await withNewApp(['ContentName=dog', 'ContentDir=content', '--yes'], (dirName, packageJson) => {
5454
const files = ['content/dog/sample.mdx', 'pages/dog/index.js', 'pages/dog/[...slug].js']
5555
files.forEach((file) => {
5656
expect(fs.existsSync(path.resolve(dirName, file))).toBeTruthy()
5757
})
5858
})
59-
})
59+
}, 10000)
6060
})

vitest-exclude-recipe.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { configDefaults, defineConfig } from 'vitest/config'
22

33
export default defineConfig({
44
test: {
5-
exclude: [...configDefaults.exclude, '**/install.test.ts', '**/install-recipe.test.ts'],
5+
exclude: [...configDefaults.exclude, '**/new.test.ts', '**/install-recipe.test.ts'],
66
},
77
})

0 commit comments

Comments
 (0)