-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathindex.js
More file actions
130 lines (104 loc) · 4.29 KB
/
index.js
File metadata and controls
130 lines (104 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//eslint-disable-next-line import/no-unresolved
import { mkdirp } from '@sveltejs/kit/filesystem';
import fs from 'fs';
import parser from 'gitignore-parser';
import { bold, cyan, gray, green, red } from 'kleur/colors';
import path from 'path';
import prompts from 'prompts/lib/index';
import glob from 'tiny-glob/sync.js';
import gitignore_contents from '../template/.gitignore';
import add_css from './modifications/add_css';
import add_typescript from './modifications/add_typescript';
// import versions from './versions';
import { version } from '../package.json';
const disclaimer = `
█████████ ███████████ ███████ ███████████ ███
███░░░░░███░█░░░███░░░█ ███░░░░░███ ░░███░░░░░███░███
░███ ░░░ ░ ░███ ░ ███ ░░███ ░███ ░███░███
░░█████████ ░███ ░███ ░███ ░██████████ ░███
░░░░░░░░███ ░███ ░███ ░███ ░███░░░░░░ ░███
███ ░███ ░███ ░░███ ███ ░███ ░░░
░░█████████ █████ ░░░███████░ █████ ███
░░░░░░░░░ ░░░░░ ░░░░░░░ ░░░░░ ░░░
Pump the brakes! A little disclaimer...
svelte@next is not ready for use yet. It definitely can't
run your apps, and it might not run at all.
We haven't yet started accepting community contributions,
and we don't need people to start raising issues yet.
Given these warnings, please feel free to experiment, but
you're on your own for now. We'll have something to show
soon.
`;
async function main() {
console.log(gray(`\ncreate-svelte version ${version}`));
console.log(red(disclaimer));
const target = process.argv[2] || '.';
if (fs.existsSync(target)) {
if (fs.readdirSync(target).length > 0) {
const response = await prompts({
type: 'confirm',
name: 'value',
message: 'Directory not empty. Continue?',
initial: false
});
if (!response.value) {
process.exit(1);
}
}
} else {
mkdirp(target);
}
const cwd = path.join(__dirname, 'template');
const gitignore = parser.compile(gitignore_contents);
const files = glob('**/*', { cwd }).filter(gitignore.accepts);
files.forEach((file) => {
const src = path.join(cwd, file);
const dest = path.join(target, file);
if (fs.statSync(src).isDirectory()) {
mkdirp(dest);
} else {
fs.copyFileSync(src, dest);
}
});
fs.writeFileSync(path.join(target, '.gitignore'), gitignore_contents);
const name = path.basename(path.resolve(target));
const pkg_file = path.join(target, 'package.json');
const pkg_json = fs
.readFileSync(pkg_file, 'utf-8')
.replace('~TODO~', name)
.replace(/"(.+)": "workspace:.+"/g, (_m, name) => `"${name}": "next"`); // TODO ^${versions[name]}
fs.writeFileSync(pkg_file, pkg_json);
console.log(bold(green('✔ Copied project files')));
await prompt_modifications(target);
console.log('\nNext steps:');
let i = 1;
const relative = path.relative(process.cwd(), target);
if (relative !== '') {
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
}
console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, or yarn)`);
console.log(` ${i++}: ${bold(cyan('npm run dev -- --open'))}`);
console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
console.log('\nStuck? Visit us at https://svelte.dev/chat\n');
}
async function prompt_modifications(target) {
const ts_response = await prompts({
type: 'confirm',
name: 'value',
message: 'Use TypeScript in components?',
initial: false
});
await add_typescript(target, ts_response.value);
const css_response = await prompts({
type: 'select',
name: 'value',
message: 'What do you want to use for writing Styles in Svelte components?',
choices: [
{ title: 'CSS', value: 'css' },
{ title: 'Less', value: 'less' },
{ title: 'SCSS', value: 'scss' }
]
});
await add_css(target, css_response.value);
}
main();