@comet/create-app 1.5.0 → 1.12.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.
- package/README.md +9 -9
- package/lib/index.js +2 -1
- package/lib/scripts/create-app/amendCommitChanges.js +9 -0
- package/lib/scripts/create-app/createApp.js +17 -0
- package/lib/scripts/remove-showcase/removeShowcase.js +4 -11
- package/lib/scripts/remove-site/removeSite.js +2 -0
- package/lib/util/hasDependenciesInstalled.js +17 -0
- package/lib/util/runEslintFix.js +32 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -15,10 +15,11 @@ npx @comet/create-app <project-name>
|
|
|
15
15
|
|
|
16
16
|
The following arguments can be passed to customize the project setup:
|
|
17
17
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
18
|
+
- `project-name` (required): Specifies the name of the project. It will be used as the directory name for the project.
|
|
19
|
+
- `-ni` or `--no-install`: Disables the automatic installation of dependencies.
|
|
20
|
+
- `-v` or `--verbose`: Enables extra console logs for verbose output.
|
|
21
|
+
- `-V` or `--version`: Outputs the version number.
|
|
22
|
+
- `-h` or `--help`: Display help for the command.
|
|
22
23
|
|
|
23
24
|
Example usage with arguments:
|
|
24
25
|
|
|
@@ -26,14 +27,13 @@ Example usage with arguments:
|
|
|
26
27
|
npx @comet/create-app my-project -v
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
|
|
30
30
|
This command will create a new Comet app with the name "my-project" and enable verbose logging.
|
|
31
31
|
|
|
32
32
|
### Commands
|
|
33
33
|
|
|
34
34
|
The following commands can be used to customize the project setup:
|
|
35
35
|
|
|
36
|
-
-
|
|
36
|
+
- `remove-showcase`: Removes the showcase content from the project.
|
|
37
37
|
|
|
38
38
|
Example usage:
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ Example usage:
|
|
|
41
41
|
npx @comet/create-app remove-showcase
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
-
|
|
44
|
+
- `remove-site`: Removes the site from the project.
|
|
45
45
|
|
|
46
46
|
Example usage:
|
|
47
47
|
|
|
@@ -57,11 +57,11 @@ To test the script locally, run the following commands:
|
|
|
57
57
|
|
|
58
58
|
1. Start the development process:
|
|
59
59
|
```bash
|
|
60
|
-
|
|
60
|
+
npm start
|
|
61
61
|
```
|
|
62
62
|
2. Run the script:
|
|
63
63
|
```bash
|
|
64
64
|
node ./bin/index.js
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
Testing a close to production usage of the CLI can be done by calling `npm link` in the create-app/ directory. Then `npx @comet/create-app` can be used.
|
|
67
|
+
Testing a close to production usage of the CLI can be done by calling `npm link` in the create-app/ directory. Then `npx @comet/create-app` can be used.
|
package/lib/index.js
CHANGED
|
@@ -23,9 +23,10 @@ void (async () => {
|
|
|
23
23
|
program
|
|
24
24
|
.argument("<projectName>", "Sets the name of the project.")
|
|
25
25
|
.option("-v, --verbose", "Enables extra console logs for verbose output.")
|
|
26
|
+
.option("-ni, --no-install", "Disables the automatic installation of dependencies.")
|
|
26
27
|
.action((projectName, options) => {
|
|
27
28
|
if ((0, isValidProjectName_1.isValidProjectName)(projectName)) {
|
|
28
|
-
(0, createApp_1.createApp)({ projectName, verbose: options.verbose });
|
|
29
|
+
(0, createApp_1.createApp)({ projectName, verbose: options.verbose, install: options.install });
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
program.error("Please provide a valid project name.");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.amendCommitChanges = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
function amendCommitChanges() {
|
|
6
|
+
(0, child_process_1.execSync)("git add .");
|
|
7
|
+
(0, child_process_1.execSync)("git commit --amend --no-edit");
|
|
8
|
+
}
|
|
9
|
+
exports.amendCommitChanges = amendCommitChanges;
|
|
@@ -4,9 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createApp = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
7
8
|
const kleur_1 = __importDefault(require("kleur"));
|
|
9
|
+
const nanospinner_1 = require("nanospinner");
|
|
8
10
|
const process_1 = __importDefault(require("process"));
|
|
9
11
|
const replacePlaceholder_1 = require("../../util/replacePlaceholder");
|
|
12
|
+
const runEslintFix_1 = require("../../util/runEslintFix");
|
|
13
|
+
const amendCommitChanges_1 = require("./amendCommitChanges");
|
|
10
14
|
const cleanupReadme_1 = require("./cleanupReadme");
|
|
11
15
|
const cleanupWorkingDirectory_1 = require("./cleanupWorkingDirectory");
|
|
12
16
|
const createInitialGitCommit_1 = require("./createInitialGitCommit");
|
|
@@ -18,6 +22,19 @@ async function createApp(projectConfiguration) {
|
|
|
18
22
|
(0, cleanupWorkingDirectory_1.cleanupWorkingDirectory)(projectConfiguration.verbose);
|
|
19
23
|
(0, replacePlaceholder_1.replacePlaceholder)(projectConfiguration.projectName, projectConfiguration.verbose);
|
|
20
24
|
(0, createInitialGitCommit_1.createInitialGitCommit)();
|
|
25
|
+
if (projectConfiguration.install) {
|
|
26
|
+
const spinner = (0, nanospinner_1.createSpinner)("Installing project...").spin();
|
|
27
|
+
try {
|
|
28
|
+
(0, child_process_1.execSync)("sh ./install.sh");
|
|
29
|
+
spinner.success();
|
|
30
|
+
console.log("Installation completed successfully.");
|
|
31
|
+
(0, runEslintFix_1.runEslintFix)();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
spinner.error({ text: `An error occurred while installing the project: ${error}` });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
(0, amendCommitChanges_1.amendCommitChanges)();
|
|
21
38
|
console.log(`\n${kleur_1.default.white(`Success! Created '${projectConfiguration.projectName}' at '${process_1.default.cwd()}'.`)}`);
|
|
22
39
|
console.log(kleur_1.default.white(`Inside that directory, you can run several commands:\n`));
|
|
23
40
|
console.log(kleur_1.default.white(`nvm use\n`));
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.removeShowcaseContent = void 0;
|
|
7
|
-
const eslint_1 = require("eslint");
|
|
8
7
|
const fs_1 = require("fs");
|
|
9
8
|
const kleur_1 = __importDefault(require("kleur"));
|
|
10
9
|
const deleteFilesAndFolders_1 = require("../../util/deleteFilesAndFolders");
|
|
10
|
+
const runEslintFix_1 = require("../../util/runEslintFix");
|
|
11
11
|
async function removeFileContent() {
|
|
12
12
|
const contentToRemove = [
|
|
13
13
|
{
|
|
@@ -31,26 +31,18 @@ async function removeFileContent() {
|
|
|
31
31
|
replacements: ["MikroOrmModule.forFeature([Product]), "],
|
|
32
32
|
},
|
|
33
33
|
];
|
|
34
|
-
const eslint = new eslint_1.ESLint({
|
|
35
|
-
cwd: process.cwd(),
|
|
36
|
-
fix: true,
|
|
37
|
-
});
|
|
38
34
|
for (const content of contentToRemove) {
|
|
39
35
|
if (!(0, fs_1.existsSync)(content.file)) {
|
|
40
36
|
console.log(kleur_1.default.bgYellow(`File: ${content.file} does not exist!`));
|
|
41
37
|
console.log(kleur_1.default.bgYellow(`Skipping: ${content.file}...`));
|
|
42
38
|
continue;
|
|
43
39
|
}
|
|
44
|
-
let fileContent = (0, fs_1.readFileSync)(content.file).toString();
|
|
40
|
+
let fileContent = (0, fs_1.readFileSync)(content.file, "utf-8").toString();
|
|
45
41
|
for (const replacement of content.replacements) {
|
|
46
42
|
fileContent = fileContent.replaceAll(replacement, "");
|
|
47
43
|
}
|
|
48
44
|
try {
|
|
49
|
-
|
|
50
|
-
filePath: content.file,
|
|
51
|
-
});
|
|
52
|
-
const output = lintedFileContent[0] && lintedFileContent[0].output ? lintedFileContent[0].output : lintedFileContent[0].source;
|
|
53
|
-
(0, fs_1.writeFileSync)(content.file, output ?? fileContent);
|
|
45
|
+
(0, fs_1.writeFileSync)(content.file, fileContent);
|
|
54
46
|
}
|
|
55
47
|
catch (e) {
|
|
56
48
|
(0, fs_1.writeFileSync)(content.file, fileContent);
|
|
@@ -68,5 +60,6 @@ async function removeShowcaseContent() {
|
|
|
68
60
|
"api/src/db/migrations/Migration20220721123033.ts",
|
|
69
61
|
];
|
|
70
62
|
(0, deleteFilesAndFolders_1.deleteFilesAndFolders)(filesToRemove, false);
|
|
63
|
+
(0, runEslintFix_1.runEslintFix)();
|
|
71
64
|
}
|
|
72
65
|
exports.removeShowcaseContent = removeShowcaseContent;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.removeSite = void 0;
|
|
4
4
|
const deleteFilesAndFolders_1 = require("../../util/deleteFilesAndFolders");
|
|
5
5
|
const removeReferenceInFile_1 = require("../../util/removeReferenceInFile");
|
|
6
|
+
const runEslintFix_1 = require("../../util/runEslintFix");
|
|
6
7
|
function removeSiteReferences() {
|
|
7
8
|
(0, removeReferenceInFile_1.removeReferenceInFile)(".vscode/settings.json", /, "site"/g);
|
|
8
9
|
(0, removeReferenceInFile_1.removeReferenceInFile)(".env", /# site.*NEXT_PUBLIC_SITE_IS_PREVIEW=false\n\n/gms);
|
|
@@ -17,5 +18,6 @@ function removeSiteReferences() {
|
|
|
17
18
|
function removeSite() {
|
|
18
19
|
(0, deleteFilesAndFolders_1.deleteFilesAndFolders)(["site"], false);
|
|
19
20
|
removeSiteReferences();
|
|
21
|
+
(0, runEslintFix_1.runEslintFix)();
|
|
20
22
|
}
|
|
21
23
|
exports.removeSite = removeSite;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hasDependenciesInstalled = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
function hasDependenciesInstalled(microservice) {
|
|
9
|
+
const files = fs_1.default.readdirSync(`${process.cwd()}/${microservice}`);
|
|
10
|
+
if (!files.includes("package.json")) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const packageJson = fs_1.default.readFileSync(`${process.cwd()}/${microservice}/package.json`, "utf8");
|
|
14
|
+
return ((packageJson.includes("dependencies") || packageJson.includes("devDependencies")) &&
|
|
15
|
+
fs_1.default.existsSync(`${process.cwd()}/${microservice}/node_modules`));
|
|
16
|
+
}
|
|
17
|
+
exports.hasDependenciesInstalled = hasDependenciesInstalled;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runEslintFix = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const hasDependenciesInstalled_1 = require("./hasDependenciesInstalled");
|
|
10
|
+
function runEslintFix() {
|
|
11
|
+
const microservices = ["admin", "api", "site"];
|
|
12
|
+
for (const microservice of microservices) {
|
|
13
|
+
if (!fs_1.default.existsSync(microservice)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
else if (!(0, hasDependenciesInstalled_1.hasDependenciesInstalled)(microservice)) {
|
|
17
|
+
console.warn(`Cannot fix ESLint errors in ${microservice} because it has no dependencies installed`);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
if (microservice !== "api")
|
|
22
|
+
(0, child_process_1.execSync)(`npm --prefix ${microservice} run prelint`);
|
|
23
|
+
(0, child_process_1.execSync)(`npm run --prefix ${microservice} lint:eslint -- --fix`);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.error(`Failed to fix ESLint errors in ${microservice}. See original error below`);
|
|
27
|
+
console.error(err);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.runEslintFix = runEslintFix;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/create-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Command-line interface to create a new Comet application",
|
|
5
5
|
"homepage": "https://github.com/vivid-planet/comet-starter/tree/main/create-app#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
"prebuild": "npm run clean",
|
|
23
23
|
"build": "tsc --project tsconfig.json",
|
|
24
24
|
"clean": "rimraf lib",
|
|
25
|
-
"lint": "
|
|
26
|
-
"lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json --max-warnings 0 src/
|
|
25
|
+
"lint": "run-p lint:prettier lint:eslint lint:tsc",
|
|
26
|
+
"lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json --max-warnings 0 src/",
|
|
27
|
+
"lint:prettier": "npx prettier --check './**/*.{js,json,md,yml,yaml}'",
|
|
27
28
|
"lint:tsc": "tsc --project ./tsconfig.json",
|
|
28
29
|
"prepublishOnly": "npm run lint && npm run build",
|
|
29
30
|
"prestart": "npm run clean",
|
|
@@ -34,12 +35,14 @@
|
|
|
34
35
|
"eslint": "^8.0.0",
|
|
35
36
|
"glob": "^10.3.3",
|
|
36
37
|
"kleur": "^4.1.5",
|
|
38
|
+
"nanospinner": "^1.1.0",
|
|
37
39
|
"rimraf": "^5.0.1"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@comet/eslint-config": "^
|
|
42
|
+
"@comet/eslint-config": "^6.3.0",
|
|
41
43
|
"@tsconfig/node20": "^20.1.2",
|
|
42
44
|
"@types/node": "^20.0.0",
|
|
45
|
+
"npm-run-all": "^4.1.5",
|
|
43
46
|
"prettier": "^2.1.2",
|
|
44
47
|
"typescript": "~5.1.0"
|
|
45
48
|
},
|