Skip to content

Commit e29064e

Browse files
gksanderZimChristine
authored andcommitted
create-spectacle: README/gitignore templates (FormidableLabs#1200)
* README/gitignore templates * Add changeset
1 parent efb058e commit e29064e

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

.changeset/hip-trains-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-spectacle': minor
3+
---
4+
5+
Add README and .gitignore to generated projects

packages/create-spectacle/src/cli.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,15 @@ const main = async () => {
170170
}
171171

172172
clearInterval(progressInterval);
173+
const atLocation =
174+
type === 'onepage'
175+
? `at ${fileOptions.snakeCaseName}.html`
176+
: `in ${fileOptions.snakeCaseName}/`;
173177
logUpdate(
174178
chalk.whiteBright.bgGreen.bold(` \u2714 `),
175-
chalk.green.bold(`A new ${type} deck named ${name} was created.\n`)
179+
chalk.green.bold(
180+
`A new ${type} deck named ${name} was created ${atLocation}.\n`
181+
)
176182
);
177183
};
178184

packages/create-spectacle/src/templates/file-writers.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'path';
2-
import { existsSync } from 'fs';
32
import { mkdir, writeFile, rm } from 'fs/promises';
43
import { htmlTemplate } from './html';
54
import { onePageTemplate } from './one-page';
@@ -8,6 +7,8 @@ import { babelTemplate } from './babel';
87
import { packageTemplate } from './package';
98
import { indexTemplate } from './index';
109
import { tsconfigTemplate } from './tsconfig';
10+
import { gitignoreTemplate } from './gitignore';
11+
import { readmeTemplate } from './readme';
1112

1213
export type FileOptions = {
1314
snakeCaseName: string;
@@ -27,46 +28,52 @@ export const writeWebpackProjectFiles = async ({
2728
spectacleVersion
2829
}: FileOptions) => {
2930
const outPath = path.resolve(process.cwd(), snakeCaseName);
31+
const pathFor = (file: string) => path.join(outPath, file);
3032

3133
await rm(outPath, { recursive: true, force: true });
3234

33-
if (existsSync(outPath)) {
34-
throw new Error(`Directory named ${snakeCaseName} already exists.`);
35-
}
3635
await mkdir(outPath, { recursive: true });
37-
await writeFile(`${snakeCaseName}/index.html`, htmlTemplate({ name, lang }));
36+
await writeFile(pathFor('index.html'), htmlTemplate({ name, lang }));
3837
await writeFile(
39-
`${snakeCaseName}/webpack.config.js`,
38+
pathFor('webpack.config.js'),
4039
webpackTemplate({ port, usesTypeScript: enableTypeScriptSupport })
4140
);
4241
await writeFile(
43-
`${snakeCaseName}/.babelrc`,
42+
pathFor('.babelrc'),
4443
babelTemplate({ enableTypeScriptSupport })
4544
);
4645
await writeFile(
47-
`${snakeCaseName}/package.json`,
46+
pathFor('package.json'),
4847
packageTemplate({
4948
usesTypeScript: enableTypeScriptSupport,
5049
name: snakeCaseName,
5150
spectacleVersion
5251
})
5352
);
5453
await writeFile(
55-
`${snakeCaseName}/index.${enableTypeScriptSupport ? 'tsx' : 'jsx'}`,
54+
pathFor(`index.${enableTypeScriptSupport ? 'tsx' : 'jsx'}`),
5655
indexTemplate({
5756
usesTypeScript: enableTypeScriptSupport,
5857
name
5958
})
6059
);
60+
await writeFile(pathFor('.gitignore'), gitignoreTemplate());
61+
await writeFile(
62+
pathFor('README.md'),
63+
readmeTemplate({ name, enableTypeScriptSupport })
64+
);
6165

6266
enableTypeScriptSupport &&
63-
(await writeFile(`${snakeCaseName}/tsconfig.json`, tsconfigTemplate()));
67+
(await writeFile(pathFor('tsconfig.json'), tsconfigTemplate()));
6468
};
6569

6670
export const writeOnePageHTMLFile = async ({
6771
snakeCaseName,
6872
name,
6973
lang
7074
}: FileOptions) => {
71-
await writeFile(`${snakeCaseName}.html`, onePageTemplate({ name, lang }));
75+
await writeFile(
76+
path.resolve(process.cwd(), `${snakeCaseName}.html`),
77+
onePageTemplate({ name, lang })
78+
);
7279
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const gitignoreTemplate = () =>
2+
`
3+
# Deps
4+
node_modules
5+
6+
# Logs
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
pnpm-debug.log*
11+
lerna-debug.log*
12+
13+
# Editor/FS configs
14+
.vscode
15+
.idea
16+
.DS_Store
17+
18+
# Build artifacts
19+
dist
20+
`.trim();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
type ReadmeTemplateOptions = {
2+
name: string;
3+
enableTypeScriptSupport: boolean;
4+
};
5+
6+
export const readmeTemplate = ({
7+
name,
8+
enableTypeScriptSupport
9+
}: ReadmeTemplateOptions) =>
10+
`
11+
# ${name}
12+
13+
Made with ❤️ and [Spectacle](https://github.com/FormidableLabs/spectacle/).
14+
15+
## Running your presentation
16+
17+
- Run \`yarn install\` (or \`npm install\` or \`pnpm install\`) to install dependencies.
18+
- Run \`yarn start\` (or \`npm start\` or \`pnpm start\`) to start the presentation.
19+
- Edit \`index.${
20+
enableTypeScriptSupport ? 'tsx' : 'jsx'
21+
}\` to add your presentation content.
22+
23+
## Building you presentation
24+
25+
To build your presentation for a production deploy, run \`yarn build\` (or \`npm build\` or \`pnpm build\`).
26+
27+
The build artifacts will be placed in the \`dist\` directory. If you'd like to change this location, edit \`output.path\` in \`webpack.config.js\`.
28+
`.trim();

0 commit comments

Comments
 (0)