create-astro 1.0.1-next.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  **With NPM:**
6
6
 
7
7
  ```bash
8
- npm init astro
8
+ npm create astro@latest
9
9
  ```
10
10
 
11
11
  **With Yarn:**
@@ -18,10 +18,10 @@ yarn create astro
18
18
 
19
19
  ```bash
20
20
  # npm 6.x
21
- npm init astro my-astro-project --template starter
21
+ npm create astro@latest my-astro-project --template starter
22
22
 
23
23
  # npm 7+, extra double-dash is needed:
24
- npm init astro my-astro-project -- --template starter
24
+ npm create astro@latest my-astro-project -- --template starter
25
25
 
26
26
  # yarn
27
27
  yarn create astro my-astro-project --template starter
@@ -31,7 +31,7 @@ yarn create astro my-astro-project --template starter
31
31
  You can also use any GitHub repo as a template:
32
32
 
33
33
  ```bash
34
- npm init astro my-astro-project -- --template cassidoo/shopify-react-astro
34
+ npm create astro@latest my-astro-project -- --template cassidoo/shopify-react-astro
35
35
  ```
36
36
 
37
37
  ### CLI Flags
@@ -49,10 +49,10 @@ To debug `create-astro`, you can use the `--verbose` flag which will log the out
49
49
 
50
50
  ```bash
51
51
  # npm 6.x
52
- npm init astro my-astro-project --verbose
52
+ npm create astro@latest my-astro-project --verbose
53
53
 
54
54
  # npm 7+, extra double-dash is needed:
55
- npm init astro my-astro-project -- --verbose
55
+ npm create astro@latest my-astro-project -- --verbose
56
56
 
57
57
  # yarn
58
58
  yarn create astro my-astro-project --verbose
package/dist/index.js CHANGED
@@ -34,6 +34,40 @@ function mkdirp(dir) {
34
34
  function isEmpty(dirPath) {
35
35
  return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
36
36
  }
37
+ const VALID_PROJECT_DIRECTORY_SAFE_LIST = [
38
+ ".DS_Store",
39
+ ".git",
40
+ ".gitattributes",
41
+ ".gitignore",
42
+ ".gitlab-ci.yml",
43
+ ".hg",
44
+ ".hgcheck",
45
+ ".hgignore",
46
+ ".idea",
47
+ ".npmignore",
48
+ ".travis.yml",
49
+ ".yarn",
50
+ ".yarnrc.yml",
51
+ "docs",
52
+ "LICENSE",
53
+ "mkdocs.yml",
54
+ "Thumbs.db",
55
+ /\.iml$/,
56
+ /^npm-debug\.log/,
57
+ /^yarn-debug\.log/,
58
+ /^yarn-error\.log/
59
+ ];
60
+ function isValidProjectDirectory(dirPath) {
61
+ if (!fs.existsSync(dirPath)) {
62
+ return true;
63
+ }
64
+ const conflicts = fs.readdirSync(dirPath).filter((content) => {
65
+ return !VALID_PROJECT_DIRECTORY_SAFE_LIST.some((safeContent) => {
66
+ return typeof safeContent === "string" ? content === safeContent : safeContent.test(content);
67
+ });
68
+ });
69
+ return conflicts.length === 0;
70
+ }
37
71
  const { version } = JSON.parse(
38
72
  fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
39
73
  );
@@ -47,16 +81,16 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
47
81
  console.log(`Lets walk through setting up your new Astro project.
48
82
  `);
49
83
  let cwd = args["_"][2];
50
- if (cwd && isEmpty(cwd)) {
84
+ if (cwd && isValidProjectDirectory(cwd)) {
51
85
  let acknowledgeProjectDir = ora({
52
86
  color: "green",
53
87
  text: `Using ${bold(cwd)} as project directory.`
54
88
  });
55
89
  acknowledgeProjectDir.succeed();
56
90
  }
57
- if (!cwd || !isEmpty(cwd)) {
91
+ if (!cwd || !isValidProjectDirectory(cwd)) {
58
92
  const notEmptyMsg = (dirPath) => `"${bold(dirPath)}" is not empty!`;
59
- if (!isEmpty(cwd)) {
93
+ if (!isValidProjectDirectory(cwd)) {
60
94
  let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
61
95
  rejectProjectDir.fail();
62
96
  }
@@ -67,7 +101,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
67
101
  message: "Where would you like to create your new project?",
68
102
  initial: "./my-astro-site",
69
103
  validate(value) {
70
- if (!isEmpty(value)) {
104
+ if (!isValidProjectDirectory(value)) {
71
105
  return notEmptyMsg(value);
72
106
  }
73
107
  return true;
@@ -97,7 +131,7 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
97
131
  let templateSpinner = await loadWithRocketGradient("Copying project files...");
98
132
  const hash = args.commit ? `#${args.commit}` : "";
99
133
  const isThirdParty = options.template.includes("/");
100
- const templateTarget = options.template.includes("/") ? options.template : `withastro/astro/examples/${options.template}#latest`;
134
+ const templateTarget = isThirdParty ? options.template : `withastro/astro/examples/${options.template}#latest`;
101
135
  const emitter = degit(`${templateTarget}${hash}`, {
102
136
  cache: false,
103
137
  force: true,
@@ -114,8 +148,10 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
114
148
  logger.debug(info.message);
115
149
  });
116
150
  await emitter.clone(cwd);
117
- if (isEmpty(cwd)) {
118
- fs.rmdirSync(cwd);
151
+ if (isValidProjectDirectory(cwd)) {
152
+ if (isEmpty(cwd)) {
153
+ fs.rmdirSync(cwd);
154
+ }
119
155
  throw new Error(`Error: The provided template (${cyan(options.template)}) does not exist`);
120
156
  }
121
157
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "1.0.1-next.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",