create-astro 0.8.0 → 0.9.0

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.
Files changed (3) hide show
  1. package/dist/index.js +32 -15
  2. package/package.json +14 -11
  3. package/LICENSE +0 -34
package/dist/index.js CHANGED
@@ -38,6 +38,9 @@ function mkdirp(dir) {
38
38
  throw e;
39
39
  }
40
40
  }
41
+ function isEmpty(dirPath) {
42
+ return !fs.existsSync(dirPath) || fs.readdirSync(dirPath).length === 0;
43
+ }
41
44
  const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
42
45
  const POSTPROCESS_FILES = ["package.json", "astro.config.mjs", "CHANGELOG.md"];
43
46
  async function main() {
@@ -48,22 +51,36 @@ ${bold("Welcome to Astro!")} ${gray(`(create-astro v${version})`)}`);
48
51
  `);
49
52
  let spinner = ora({ color: "green", text: "Prepare for liftoff." });
50
53
  spinner.succeed();
51
- const cwd = args["_"][2] || ".";
52
- if (fs.existsSync(cwd)) {
53
- if (fs.readdirSync(cwd).length > 0) {
54
- const response = await prompts({
55
- type: "confirm",
56
- name: "forceOverwrite",
57
- message: "Directory not empty. Continue [force overwrite]?",
58
- initial: false
59
- });
60
- if (!response.forceOverwrite) {
61
- process.exit(1);
62
- }
63
- mkdirp(cwd);
54
+ let cwd = args["_"][2];
55
+ if (cwd && isEmpty(cwd)) {
56
+ let acknowledgeProjectDir = ora({
57
+ color: "green",
58
+ text: `Using ${bold(cwd)} as project directory.`
59
+ });
60
+ acknowledgeProjectDir.succeed();
61
+ }
62
+ if (!cwd || !isEmpty(cwd)) {
63
+ const notEmptyMsg = (dirPath) => `"${bold(dirPath)}" is not empty. Please clear contents or choose a different path.`;
64
+ if (!isEmpty(cwd)) {
65
+ let rejectProjectDir = ora({ color: "red", text: notEmptyMsg(cwd) });
66
+ rejectProjectDir.fail();
64
67
  }
65
- } else {
66
- mkdirp(cwd);
68
+ const dirResponse = await prompts({
69
+ type: "text",
70
+ name: "directory",
71
+ message: "Where would you like to create your app?",
72
+ initial: "./my-astro-site",
73
+ validate(value) {
74
+ if (!isEmpty(value)) {
75
+ return notEmptyMsg(value);
76
+ }
77
+ return true;
78
+ }
79
+ });
80
+ cwd = dirResponse.directory;
81
+ }
82
+ if (!cwd) {
83
+ process.exit(1);
67
84
  }
68
85
  const options = await prompts([
69
86
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -17,6 +17,12 @@
17
17
  "bin": {
18
18
  "create-astro": "./create-astro.mjs"
19
19
  },
20
+ "scripts": {
21
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc",
22
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
23
+ "dev": "astro-scripts dev \"src/**/*.ts\"",
24
+ "test": "mocha --exit --timeout 20000"
25
+ },
20
26
  "files": [
21
27
  "dist",
22
28
  "create-astro.js"
@@ -32,18 +38,15 @@
32
38
  "yargs-parser": "^21.0.1"
33
39
  },
34
40
  "devDependencies": {
41
+ "@types/chai": "^4.3.1",
42
+ "@types/mocha": "^9.1.0",
35
43
  "@types/yargs-parser": "^21.0.0",
36
- "astro-scripts": "0.0.2",
44
+ "astro-scripts": "workspace:*",
45
+ "chai": "^4.3.6",
46
+ "mocha": "^9.2.2",
37
47
  "uvu": "^0.5.3"
38
48
  },
39
49
  "engines": {
40
50
  "node": "^14.15.0 || >=16.0.0"
41
- },
42
- "scripts": {
43
- "build": "astro-scripts build \"src/**/*.ts\" && tsc",
44
- "build:ci": "astro-scripts build \"src/**/*.ts\"",
45
- "dev": "astro-scripts dev \"src/**/*.ts\"",
46
- "test": "rm -rf test/fixtures && mkdir test/fixtures && node --unhandled-rejections=strict test/create-astro.test.js"
47
- },
48
- "readme": "# create-astro\n\n## Scaffolding for Astro projects\n\n**With NPM:**\n\n```bash\nnpm init astro\n```\n\n**With Yarn:**\n\n```bash\nyarn create astro\n```\n\n`create-astro` automatically runs in _interactive_ mode, but you can also specify your project name and template with command line arguments.\n\n```bash\n# npm 6.x\nnpm init astro my-astro-project --template starter\n\n# npm 7+, extra double-dash is needed:\nnpm init astro my-astro-project -- --template starter\n\n# yarn\nyarn create astro my-astro-project --template starter\n```\n[Check out the full list][examples] of example starter templates, available on GitHub.\n\nYou can also use any GitHub repo as a template:\n\n```bash\nnpm init astro my-astro-project -- --template cassidoo/shopify-react-astro\n```\n\n### CLI Flags\n\nMay be provided in place of prompts\n\n| Name | Description |\n|:-------------|:----------------------------------------------------|\n| `--template` | Specify the template name ([list][examples]) |\n| `--commit` | Specify a specific Git commit or branch to use from this repo (by default, `main` branch of this repo will be used) |\n\n### Debugging\n\nTo debug `create-astro`, you can use the `--verbose` flag which will log the output of degit and some more information about the command, this can be useful when you encounter an error and want to report it.\n\n```bash\n# npm 6.x\nnpm init astro my-astro-project --verbose\n\n# npm 7+, extra double-dash is needed:\nnpm init astro my-astro-project -- --verbose\n\n# yarn\nyarn create astro my-astro-project --verbose\n```\n\n[examples]: https://github.com/withastro/astro/tree/main/examples\n"
49
- }
51
+ }
52
+ }
package/LICENSE DELETED
@@ -1,34 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Fred K. Schott
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
-
24
- """
25
- This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
-
27
- Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
28
-
29
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30
-
31
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
-
33
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
- """