create-webiny-project 0.0.0-mt-1
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/CHANGELOG.md +1808 -0
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/bin.js +49 -0
- package/index.js +94 -0
- package/package.json +39 -0
- package/utils/checkProjectName.js +22 -0
- package/utils/createProject.js +314 -0
- package/utils/getPackageJson.js +5 -0
- package/utils/getPackageVersion.js +24 -0
- package/utils/getYarnVersion.js +10 -0
- package/utils/verifyConfig.js +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# create-webiny-project
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/create-webiny-project)
|
|
4
|
+
[](https://www.npmjs.com/package/create-webiny-project)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
A tool for setting up a new Webiny project.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
#### Simple:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npx create-webiny-project@beta my-test-project --tag beta
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### Advanced:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npx create-webiny-project@beta my-test-project
|
|
22
|
+
--tag beta --no-interactive
|
|
23
|
+
--assign-to-yarnrc '{"npmRegistryServer":"http://localhost:4873","unsafeHttpWhitelist":["localhost"]}'
|
|
24
|
+
--template-options '{"region":"eu-central-1","vpc":false}'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This usage is more ideal for CI/CD environments, where interactivity is not available.
|
|
28
|
+
|
|
29
|
+
But do note that this is probably more useful to us, Webiny developers, than for actual Webiny projects. This is simply because in real project's CI/CD pipelines, users would simply start off by cloning the project from their private repository, and not create a new one with the above command.
|
|
30
|
+
|
|
31
|
+
## Development Notes
|
|
32
|
+
|
|
33
|
+
Testing this, and related packages (like [cwp-template-aws](./../cwp-template-aws)) is a bit complicated, because in order to get the best results, it's recommended to test everything with packages published to a real NPM.
|
|
34
|
+
|
|
35
|
+
But of course, publishing to NPM just to test something is not ideal, and that's why, we use [Verdaccio](https://verdaccio.org/) instead, which is, basically, an NPM-like service you can run locally. So, instead of publishing packages to NPM, you publish them to Verdaccio, which is much cleaner, because everything stays on your laptop.
|
|
36
|
+
|
|
37
|
+
#### Usage
|
|
38
|
+
|
|
39
|
+
So, you've made some changes, and now you'd like to see the `create-webiny-project` in action.
|
|
40
|
+
|
|
41
|
+
The following steps show how to do it.
|
|
42
|
+
|
|
43
|
+
#### 1. Start Verdaccio
|
|
44
|
+
|
|
45
|
+
Start by running the `yarn verdaccio:start` command, which will, as the script name itself suggests, spin up Verdaccio locally.
|
|
46
|
+
|
|
47
|
+
> All of the files uploaded to Verdaccio service will be stored in the `.verdaccio` folder, located in your project root.
|
|
48
|
+
|
|
49
|
+
#### 2. Set default NPM registry
|
|
50
|
+
|
|
51
|
+
Once you have Verdaccio up and running, you'll also need to change the default NPM registry. Meaning, when you run `npx create-webiny-project ...`, you want it to start fetching packages from Verdaccio, not real NPM. Verdaccio runs on localhost, on port 4873, so, in your terminal, run the following command:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
npm config set registry http://localhost:4873
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Note that this will only help you with `npx`, but won't help you when a new project foundation is created, and the dependencies start to get pulled. This is because we're using yarn2, which actually doesn't respect the values that were written by the `npm config set ...` command we just executed.
|
|
58
|
+
|
|
59
|
+
It's super important that, when you're testing your npx project, you also pass the following argument:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
--assign-to-yarnrc '{"npmRegistryServer":"http://localhost:4873","unsafeHttpWhitelist":["localhost"]}'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This will set the necessary values in yarn2 config file, which will be located in your newly created project. But don't worry about it right now, this will be revisited in step 4.
|
|
66
|
+
|
|
67
|
+
> Yarn2 projects don't rely on global configurations and is not installed globally, but on per-project basis. This allows having multiple versions of yarn2, for different projects.
|
|
68
|
+
|
|
69
|
+
#### 3. Version and publish packages
|
|
70
|
+
|
|
71
|
+
Commit (no need to push it if you don't want to) all of the code changes, and execute the following command:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
yarn lerna:version:verdaccio
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This will increment the version of all packages in the repository, create a tag, and do some other preparations that are needed before we start publishing. Note that it will also create a new commit, which MUST NOT be pushed to your remote origin. If you happen to do it by accident, you'll need to revert the changes and push those.
|
|
78
|
+
|
|
79
|
+
Once that's done, you run the following command:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
yarn lerna:publish:verdaccio
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This will publish the packages to Verdaccio. Once it's done, you can start testing.
|
|
86
|
+
|
|
87
|
+
> You can also execute both commands immediately with:
|
|
88
|
+
> ```
|
|
89
|
+
> yarn lerna:version:verdaccio && yarn lerna:publish:verdaccio
|
|
90
|
+
> ```
|
|
91
|
+
|
|
92
|
+
#### 4. Test
|
|
93
|
+
|
|
94
|
+
Test your changes with the following command:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
npx create-webiny-project@next my-test-project --tag next --assign-to-yarnrc '{"npmRegistryServer":"http://localhost:4873","unsafeHttpWhitelist":["localhost"]}'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This should create a project, with all of the packages pulled from Verdaccio.
|
|
101
|
+
|
|
102
|
+
#### 5. Additional testing
|
|
103
|
+
|
|
104
|
+
If, while testing, you've spotted an error or something that needs to be improved, you should revert the `lerna:version:verdaccio` commit that was made in your repo and start over, by adding your changes, and repeating the step 3.
|
|
105
|
+
|
|
106
|
+
To revert the version commit, you can run `git reset HEAD~ && git reset --hard HEAD`.
|
|
107
|
+
To restart Verdaccio, you can delete the `.verdaccio` folder created in your project root, stop the existing Verdaccio server (just CMD+C in terminal), and start it again with `yarn verdaccio:start`.
|
|
108
|
+
|
|
109
|
+
##### Why not just make another commit, and repeat step 3?
|
|
110
|
+
|
|
111
|
+
The thing is, you will make your commits, and then another `lerna:version:verdaccio` commit, and so on. So, after a while, you'll end up having a mix of your own commits and `lerna:version:verdaccio` commits, and you still need to remove all of the `lerna:version:verdaccio` commits in the end.
|
|
112
|
+
|
|
113
|
+
> If you come up with a better way to do this, feel free to let us know.
|
|
114
|
+
|
|
115
|
+
#### 6. Cleanup
|
|
116
|
+
|
|
117
|
+
Once you're done, do the following:
|
|
118
|
+
|
|
119
|
+
1. Undo all commits created with `lerna:version:verdaccio`.
|
|
120
|
+
2. Remove created tags. List all tags with `git tag -l "v5*"` and delete a tag with `git tag -d "v5.0.0-next.5"`.
|
|
121
|
+
3. Reset NPM registry with `npm config set registry https://registry.npmjs.org/`
|
|
122
|
+
4. Remove `.verdaccio` folder
|
|
123
|
+
|
|
124
|
+
### Commands Cheat Sheet
|
|
125
|
+
|
|
126
|
+
| Description | Command |
|
|
127
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
128
|
+
| Remove `.verdaccio` folder | `rm -rf .verdaccio` |
|
|
129
|
+
| List all v5\* tags | `git tag -l "v5*"` |
|
|
130
|
+
| Remove specific tag | `git tag -d "v5.0.0-next.5"` |
|
|
131
|
+
| Set Verdaccio as the NPM registry | `npm config set registry http://localhost:4873` |
|
|
132
|
+
| Reset NPM registry | `npm config set registry https://registry.npmjs.org/` |
|
|
133
|
+
| Start Verdaccio | `yarn verdaccio:start` |
|
|
134
|
+
| Version and publish to Verdaccio | `yarn lerna:version:verdaccio && yarn lerna:publish:verdaccio` |
|
|
135
|
+
| Create a new Webiny project | `npx create-webiny-project@next my-test-project --tag next --assign-to-yarnrc '{"npmRegistryServer":"http://localhost:4873","unsafeHttpWhitelist":["localhost"]}'` |
|
|
136
|
+
| Revert versioning commit | `git reset HEAD~ && git reset --hard HEAD` |
|
|
137
|
+
|
|
138
|
+
## Troubleshooting
|
|
139
|
+
|
|
140
|
+
#### I made a new release to Verdaccio, but I still receive old code.
|
|
141
|
+
|
|
142
|
+
This is probably because of one of the Yarn package caching mechanisms.
|
|
143
|
+
|
|
144
|
+
Yarn has two levels of cache - local and shared.
|
|
145
|
+
|
|
146
|
+
When you install a package, it gets cached in the local cache folder (located in your project), and in the shared cache folder. This makes it much faster when you're working on a couple of projects on your local machine, and you're pulling the same package in each. If the package doesn't exist in local cache, it will be pulled from shared cache.
|
|
147
|
+
|
|
148
|
+
On Windows, the shared cache folder should be located in: `C:\Users\{USER-NAME}\AppData\Local\Yarn`.
|
|
149
|
+
On Linux/Mac, the shared cache folder should be located in: `/Users/adrian/Library/Caches/Yarn`.
|
|
150
|
+
|
|
151
|
+
In these folders, most probably, you'll also have the `\Berry\cache` folder. But, there were also cases where this folder did not exist.
|
|
152
|
+
|
|
153
|
+
Deleting the mentioned cache folders should help with the issue of still receiving old packages in your testing sessions.
|
|
154
|
+
|
|
155
|
+
With all of this being said, you can also try the [following command](https://yarnpkg.com/features/offline-cache#cleaning-the-cache):
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
yarn cache clean --mirror
|
|
159
|
+
````
|
package/bin.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const semver = require("semver");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const getYarnVersion = require("./utils/getYarnVersion");
|
|
7
|
+
const verifyConfig = require("./utils/verifyConfig");
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const nodeVersion = process.versions.node;
|
|
11
|
+
if (!semver.satisfies(nodeVersion, "^12 || ^14")) {
|
|
12
|
+
console.error(
|
|
13
|
+
chalk.red(
|
|
14
|
+
[
|
|
15
|
+
`You are running Node.js ${nodeVersion}, but Webiny requires version 12 or 14.`,
|
|
16
|
+
`Please switch to one of the two versions and try again.`,
|
|
17
|
+
"For more information, please visit https://docs.webiny.com/docs/tutorials/install-webiny#prerequisites."
|
|
18
|
+
].join(" ")
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const yarnVersion = await getYarnVersion();
|
|
26
|
+
if (!semver.satisfies(yarnVersion, "^1.22.0 || ^2 || ^3")) {
|
|
27
|
+
console.error(
|
|
28
|
+
chalk.red(
|
|
29
|
+
[
|
|
30
|
+
`Webiny requires yarn@^1.22.0 or higher.`,
|
|
31
|
+
`Please visit https://yarnpkg.com/ to install ${chalk.green("yarn")}.`
|
|
32
|
+
].join("\n")
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error(
|
|
39
|
+
chalk.red(`Webiny depends on "yarn" and its built-in support for workspaces.`)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(`Please visit https://yarnpkg.com/ to install ${chalk.green("yarn")}.`);
|
|
43
|
+
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await verifyConfig();
|
|
48
|
+
require("./index");
|
|
49
|
+
})();
|
package/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const yargs = require("yargs");
|
|
3
|
+
const packageJson = require("./package.json");
|
|
4
|
+
const createProject = require("./utils/createProject");
|
|
5
|
+
|
|
6
|
+
process.on("unhandledRejection", err => {
|
|
7
|
+
throw err;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
yargs
|
|
11
|
+
.usage("Usage: create-webiny-project <project-name> [options]")
|
|
12
|
+
.version(packageJson.version)
|
|
13
|
+
.demandCommand(1)
|
|
14
|
+
.help()
|
|
15
|
+
.alias("help", "h")
|
|
16
|
+
.scriptName("create-webiny-project")
|
|
17
|
+
.fail(function (msg, err) {
|
|
18
|
+
if (msg) {
|
|
19
|
+
console.log(msg);
|
|
20
|
+
}
|
|
21
|
+
if (err) {
|
|
22
|
+
console.log(err);
|
|
23
|
+
}
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// noinspection BadExpressionStatementJS
|
|
28
|
+
yargs.command(
|
|
29
|
+
"$0 <project-name> [options]",
|
|
30
|
+
"Name of application and template to use",
|
|
31
|
+
yargs => {
|
|
32
|
+
yargs.positional("project-name", {
|
|
33
|
+
describe: "Project name"
|
|
34
|
+
});
|
|
35
|
+
yargs.option("force", {
|
|
36
|
+
describe: "All project creation within an existing folder",
|
|
37
|
+
default: false,
|
|
38
|
+
type: "boolean",
|
|
39
|
+
demandOption: false
|
|
40
|
+
});
|
|
41
|
+
yargs.option("template", {
|
|
42
|
+
describe: `Name of template to use, if no template is provided it will default to "aws" template`,
|
|
43
|
+
alias: "t",
|
|
44
|
+
type: "string",
|
|
45
|
+
default: "aws",
|
|
46
|
+
demandOption: false
|
|
47
|
+
});
|
|
48
|
+
yargs.option("template-options", {
|
|
49
|
+
describe: `A JSON containing template-specific options (usually used in non-interactive environments)`,
|
|
50
|
+
default: null,
|
|
51
|
+
type: "string",
|
|
52
|
+
demandOption: false
|
|
53
|
+
});
|
|
54
|
+
yargs.option("assign-to-yarnrc", {
|
|
55
|
+
describe: `A JSON containing additional options that will be assigned into the "yarnrc.yml" configuration file`,
|
|
56
|
+
default: null,
|
|
57
|
+
type: "string",
|
|
58
|
+
demandOption: false
|
|
59
|
+
});
|
|
60
|
+
yargs.option("tag", {
|
|
61
|
+
describe: "NPM tag to use for @webiny packages",
|
|
62
|
+
type: "string",
|
|
63
|
+
default: "latest",
|
|
64
|
+
demandOption: false
|
|
65
|
+
});
|
|
66
|
+
yargs.option("interactive", {
|
|
67
|
+
describe: "Enable interactive mode for all commands",
|
|
68
|
+
default: true,
|
|
69
|
+
type: "boolean",
|
|
70
|
+
demandOption: false
|
|
71
|
+
});
|
|
72
|
+
yargs.option("log", {
|
|
73
|
+
describe:
|
|
74
|
+
"Creates a log file to see output of installation. Defaults to creating cwp-logs.txt in current directory",
|
|
75
|
+
alias: "l",
|
|
76
|
+
default: "cwp-logs.txt",
|
|
77
|
+
type: "string",
|
|
78
|
+
demandOption: false
|
|
79
|
+
});
|
|
80
|
+
yargs.option("cleanup", {
|
|
81
|
+
describe: "If an error occurs upon project creation, deletes all generated files",
|
|
82
|
+
alias: "c",
|
|
83
|
+
default: true,
|
|
84
|
+
type: "boolean",
|
|
85
|
+
demandOption: false
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
yargs.example("$0 <project-name>");
|
|
89
|
+
yargs.example("$0 <project-name> --template=aws");
|
|
90
|
+
yargs.example("$0 <project-name> --template=../path/to/template");
|
|
91
|
+
yargs.example("$0 <project-name> --log=./my-logs.txt");
|
|
92
|
+
},
|
|
93
|
+
argv => createProject(argv)
|
|
94
|
+
).argv;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-webiny-project",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"description": "Webiny project bootstrap tool.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"bin": "./bin.js",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Webiny"
|
|
12
|
+
],
|
|
13
|
+
"author": "Webiny Ltd.",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@webiny/telemetry": "0.0.0-mt-1",
|
|
17
|
+
"chalk": "4.1.0",
|
|
18
|
+
"execa": "4.1.0",
|
|
19
|
+
"find-up": "5.0.0",
|
|
20
|
+
"fs-extra": "9.0.1",
|
|
21
|
+
"js-yaml": "3.14.1",
|
|
22
|
+
"listr": "0.14.3",
|
|
23
|
+
"load-json-file": "6.2.0",
|
|
24
|
+
"node-fetch": "2.6.1",
|
|
25
|
+
"os": "0.1.1",
|
|
26
|
+
"p-retry": "4.2.0",
|
|
27
|
+
"rimraf": "3.0.2",
|
|
28
|
+
"semver": "7.3.4",
|
|
29
|
+
"uuid": "8.3.2",
|
|
30
|
+
"validate-npm-package-name": "3.0.0",
|
|
31
|
+
"write-json-file": "4.3.0",
|
|
32
|
+
"yargs": "15.4.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"directory": "."
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { red, green } = require("chalk");
|
|
2
|
+
const validateProjectName = require("validate-npm-package-name");
|
|
3
|
+
|
|
4
|
+
module.exports = projectName => {
|
|
5
|
+
const validationResult = validateProjectName(projectName);
|
|
6
|
+
if (!validationResult.validForNewPackages) {
|
|
7
|
+
console.error(
|
|
8
|
+
red(
|
|
9
|
+
`Cannot create a project named ${green(
|
|
10
|
+
`"${projectName}"`
|
|
11
|
+
)} because of npm naming restrictions:\n`
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
[...(validationResult.errors || []), ...(validationResult.warnings || [])].forEach(
|
|
15
|
+
error => {
|
|
16
|
+
console.error(red(` * ${error}`));
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
console.error(red("\nPlease choose a different project name."));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
};
|