|
1 | 1 | #!/usr/bin/env node
|
2 |
| -import { resolve, join, basename } from 'path' |
3 |
| -import parseArgs from 'minimist' |
4 |
| -import { exists, writeFile, mkdir } from 'mz/fs' |
5 |
| -import mkdirp from 'mkdirp-then' |
| 2 | +console.log('`next init` is not supported anymore. These community projects provide the same functionality as `next init` with additional features: http://npmjs.com/next-init and http://npmjs.com/create-next-app.') |
6 | 3 |
|
7 |
| -const argv = parseArgs(process.argv.slice(2), { |
8 |
| - alias: { |
9 |
| - h: 'help' |
10 |
| - }, |
11 |
| - boolean: ['h'] |
12 |
| -}) |
13 |
| - |
14 |
| -if (argv.help) { |
15 |
| - console.log(` |
16 |
| - Description |
17 |
| - Scaffolds a simple project structure to get started quickly |
18 |
| -
|
19 |
| - Usage |
20 |
| - $ next init <dir> |
21 |
| -
|
22 |
| - If no directory is provided the current directory will be used. |
23 |
| -
|
24 |
| - Options |
25 |
| - --help, -h Displays this message |
26 |
| - `) |
27 |
| - |
28 |
| - process.exit(0) |
29 |
| -} |
30 |
| - |
31 |
| -const dir = resolve(argv._[0] || '.') |
32 |
| - |
33 |
| -if (basename(dir) === 'pages') { |
34 |
| - console.warn('Your root directory is named "pages". This looks suspicious. You probably want to go one directory up.') |
35 |
| - process.exit(1) |
36 |
| -} |
37 |
| - |
38 |
| -exists(dir) |
39 |
| -.then(async present => { |
40 |
| - if (!present) { |
41 |
| - await mkdirp(dir) |
42 |
| - } |
43 |
| - |
44 |
| - if (!await exists(join(dir, 'package.json'))) { |
45 |
| - await writeFile(join(dir, 'package.json'), basePackage.replace(/my-app/g, basename(dir))) |
46 |
| - } |
47 |
| - |
48 |
| - if (!await exists(join(dir, 'static'))) { |
49 |
| - await mkdir(join(dir, 'static')) |
50 |
| - } |
51 |
| - |
52 |
| - if (!await exists(join(dir, 'pages'))) { |
53 |
| - await mkdir(join(dir, 'pages')) |
54 |
| - await writeFile(join(dir, 'pages', 'index.js'), basePage) |
55 |
| - } |
56 |
| -}) |
57 |
| -.catch((err) => { |
58 |
| - console.error(err) |
59 |
| - process.exit(1) |
60 |
| -}) |
61 |
| - |
62 |
| -const basePackage = `{ |
63 |
| - "name": "my-app", |
64 |
| - "description": "", |
65 |
| - "dependencies": { |
66 |
| - "next": "latest", |
67 |
| - "react": "^15.4.2", |
68 |
| - "react-dom": "^15.4.2" |
69 |
| - }, |
70 |
| - "scripts": { |
71 |
| - "dev": "next", |
72 |
| - "build": "next build", |
73 |
| - "start": "next start" |
74 |
| - } |
75 |
| -}` |
76 |
| - |
77 |
| -const basePage = ` |
78 |
| -import Head from 'next/head' |
79 |
| -
|
80 |
| -export default () => ( |
81 |
| - <div> |
82 |
| - <Head> |
83 |
| - <meta name='viewport' content='width=device-width, initial-scale=1'/> |
84 |
| - </Head> |
85 |
| -
|
86 |
| - <img width='112' src='https://cloud.githubusercontent.com/assets/13041/19686250/971bf7f8-9ac0-11e6-975c-188defd82df1.png' alt='next.js' /> |
87 |
| -
|
88 |
| - <style jsx global>{\` |
89 |
| - html, body { |
90 |
| - height: 100% |
91 |
| - } |
92 |
| -
|
93 |
| - body { |
94 |
| - display: flex; |
95 |
| - align-items: center; |
96 |
| - justify-content: center; |
97 |
| - margin: 0; |
98 |
| - } |
99 |
| - \`}</style> |
100 |
| - </div> |
101 |
| -) |
102 |
| -` |
| 4 | +process.exit(0) |
0 commit comments