create-payload-app 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/cli.js +0 -0
- package/dist/index.js +14 -26
- package/dist/lib/create-project.js +220 -0
- package/dist/lib/create-project.test.js +137 -0
- package/dist/lib/generate-secret.js +48 -0
- package/dist/lib/get-db-connection.js +71 -0
- package/dist/lib/parse-language.js +79 -0
- package/dist/lib/parse-project-name.js +71 -0
- package/dist/lib/parse-template.js +85 -0
- package/dist/lib/templates.js +6 -2
- package/dist/lib/write-common-files.js +118 -0
- package/dist/lib/write-env-file.js +75 -0
- package/dist/main.js +40 -45
- package/dist/templates/README.template.md +7 -0
- package/dist/templates/js-blank/package.json +1 -1
- package/dist/templates/js-blog/package.json +1 -1
- package/dist/templates/js-todo/package.json +1 -1
- package/dist/templates/ts-blank/package.json +1 -1
- package/dist/templates/ts-blog/package.json +1 -1
- package/dist/templates/ts-todo/package.json +2 -3
- package/dist/utils/log.js +3 -3
- package/dist/utils/messages.js +1 -1
- package/package.json +21 -6
@@ -0,0 +1,71 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (_) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.parseProjectName = void 0;
|
43
|
+
var prompts_1 = __importDefault(require("prompts"));
|
44
|
+
function parseProjectName(args) {
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
46
|
+
var response;
|
47
|
+
return __generator(this, function (_a) {
|
48
|
+
switch (_a.label) {
|
49
|
+
case 0:
|
50
|
+
if (args['--name'])
|
51
|
+
return [2 /*return*/, args['--name']];
|
52
|
+
if (args._[0])
|
53
|
+
return [2 /*return*/, args._[0]];
|
54
|
+
return [4 /*yield*/, (0, prompts_1.default)({
|
55
|
+
type: 'text',
|
56
|
+
name: 'value',
|
57
|
+
message: 'Project name?',
|
58
|
+
validate: function (value) { return value.length; },
|
59
|
+
}, {
|
60
|
+
onCancel: function () {
|
61
|
+
process.exit(0);
|
62
|
+
},
|
63
|
+
})];
|
64
|
+
case 1:
|
65
|
+
response = _a.sent();
|
66
|
+
return [2 /*return*/, response.value];
|
67
|
+
}
|
68
|
+
});
|
69
|
+
});
|
70
|
+
}
|
71
|
+
exports.parseProjectName = parseProjectName;
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (_) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.parseTemplate = void 0;
|
43
|
+
var prompts_1 = __importDefault(require("prompts"));
|
44
|
+
function parseTemplate(args, validTemplates, language) {
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
46
|
+
var templateName_1, template_1, filteredTemplates, response, template;
|
47
|
+
return __generator(this, function (_a) {
|
48
|
+
switch (_a.label) {
|
49
|
+
case 0:
|
50
|
+
if (args['--template']) {
|
51
|
+
templateName_1 = args['--template'];
|
52
|
+
template_1 = validTemplates.find(function (t) { return t.name === templateName_1; });
|
53
|
+
if (!template_1)
|
54
|
+
throw new Error('Invalid template given');
|
55
|
+
return [2 /*return*/, template_1];
|
56
|
+
}
|
57
|
+
filteredTemplates = validTemplates
|
58
|
+
.filter(function (d) { return d.name.startsWith(language); })
|
59
|
+
.map(function (t) { return t.name.replace("".concat(language, "-"), ''); });
|
60
|
+
return [4 /*yield*/, (0, prompts_1.default)({
|
61
|
+
type: 'select',
|
62
|
+
name: 'value',
|
63
|
+
message: 'Choose project template',
|
64
|
+
choices: filteredTemplates.map(function (p) {
|
65
|
+
return { title: p, value: "".concat(language, "-").concat(p) };
|
66
|
+
}),
|
67
|
+
validate: function (value) { return value.length; },
|
68
|
+
}, {
|
69
|
+
onCancel: function () {
|
70
|
+
process.exit(0);
|
71
|
+
},
|
72
|
+
})
|
73
|
+
// const template = `${language}-${response.value}`
|
74
|
+
];
|
75
|
+
case 1:
|
76
|
+
response = _a.sent();
|
77
|
+
template = validTemplates.find(function (t) { return t.name === response.value; });
|
78
|
+
if (!template)
|
79
|
+
throw new Error('Template is undefined');
|
80
|
+
return [2 /*return*/, template];
|
81
|
+
}
|
82
|
+
});
|
83
|
+
});
|
84
|
+
}
|
85
|
+
exports.parseTemplate = parseTemplate;
|
package/dist/lib/templates.js
CHANGED
@@ -69,7 +69,11 @@ function getValidTemplates() {
|
|
69
69
|
templateDir = path_1.default.resolve(__dirname, '../templates');
|
70
70
|
dirs = getDirectories(templateDir);
|
71
71
|
templates = dirs.map(function (name) {
|
72
|
-
return {
|
72
|
+
return {
|
73
|
+
name: name,
|
74
|
+
type: 'static',
|
75
|
+
language: name.startsWith('js-') ? 'javascript' : 'typescript',
|
76
|
+
};
|
73
77
|
});
|
74
78
|
return [2 /*return*/, templates];
|
75
79
|
});
|
@@ -78,6 +82,6 @@ function getValidTemplates() {
|
|
78
82
|
exports.getValidTemplates = getValidTemplates;
|
79
83
|
function getDirectories(dir) {
|
80
84
|
return fs_1.default.readdirSync(dir).filter(function (file) {
|
81
|
-
return fs_1.default.statSync(dir
|
85
|
+
return fs_1.default.statSync("".concat(dir, "/").concat(file)).isDirectory();
|
82
86
|
});
|
83
87
|
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (_) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.writeCommonFiles = void 0;
|
43
|
+
var path_1 = __importDefault(require("path"));
|
44
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
45
|
+
var handlebars_1 = __importDefault(require("handlebars"));
|
46
|
+
function writeCommonFiles(projectDir, template, packageManager) {
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
48
|
+
var commonFilesDir, npmrc, npmrcDest, gi, giDest, packageJsonTemplate, packageJson, nodemon, nodemonDest, readmeTemplate, readme, tsconfig, tsconfigDest, dockerComposeTemplate, dockerCompose;
|
49
|
+
return __generator(this, function (_a) {
|
50
|
+
switch (_a.label) {
|
51
|
+
case 0:
|
52
|
+
commonFilesDir = path_1.default.resolve(__dirname, 'common-files');
|
53
|
+
npmrc = path_1.default.resolve(commonFilesDir, 'npmrc.template');
|
54
|
+
npmrcDest = path_1.default.resolve(projectDir, '.npmrc');
|
55
|
+
return [4 /*yield*/, fs_extra_1.default.copy(npmrc, npmrcDest)
|
56
|
+
// .gitignore
|
57
|
+
];
|
58
|
+
case 1:
|
59
|
+
_a.sent();
|
60
|
+
gi = path_1.default.resolve(commonFilesDir, 'gitignore.template');
|
61
|
+
giDest = path_1.default.resolve(projectDir, '.gitignore');
|
62
|
+
return [4 /*yield*/, fs_extra_1.default.copy(gi, giDest)
|
63
|
+
// package.json
|
64
|
+
];
|
65
|
+
case 2:
|
66
|
+
_a.sent();
|
67
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, template.language, 'package.template.json'), 'utf8')];
|
68
|
+
case 3:
|
69
|
+
packageJsonTemplate = _a.sent();
|
70
|
+
packageJson = handlebars_1.default.compile(packageJsonTemplate)({
|
71
|
+
templateName: template.name,
|
72
|
+
});
|
73
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'package.json'), packageJson)
|
74
|
+
// nodemon.json
|
75
|
+
];
|
76
|
+
case 4:
|
77
|
+
_a.sent();
|
78
|
+
nodemon = path_1.default.resolve(commonFilesDir, template.language, 'nodemon.json');
|
79
|
+
nodemonDest = path_1.default.resolve(projectDir, 'nodemon.json');
|
80
|
+
return [4 /*yield*/, fs_extra_1.default.copy(nodemon, nodemonDest)
|
81
|
+
// README.md
|
82
|
+
];
|
83
|
+
case 5:
|
84
|
+
_a.sent();
|
85
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'README.template.md'), 'utf8')];
|
86
|
+
case 6:
|
87
|
+
readmeTemplate = _a.sent();
|
88
|
+
readme = handlebars_1.default.compile(readmeTemplate)({
|
89
|
+
projectName: path_1.default.basename(projectDir),
|
90
|
+
templateName: template.name,
|
91
|
+
});
|
92
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'README.md'), readme)
|
93
|
+
// tsconfig.json
|
94
|
+
];
|
95
|
+
case 7:
|
96
|
+
_a.sent();
|
97
|
+
if (!(template.language === 'typescript')) return [3 /*break*/, 9];
|
98
|
+
tsconfig = path_1.default.resolve(commonFilesDir, template.language, 'tsconfig.json');
|
99
|
+
tsconfigDest = path_1.default.resolve(projectDir, 'tsconfig.json');
|
100
|
+
return [4 /*yield*/, fs_extra_1.default.copy(tsconfig, tsconfigDest)];
|
101
|
+
case 8:
|
102
|
+
_a.sent();
|
103
|
+
_a.label = 9;
|
104
|
+
case 9: return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'docker-compose.template.yml'), 'utf8')];
|
105
|
+
case 10:
|
106
|
+
dockerComposeTemplate = _a.sent();
|
107
|
+
dockerCompose = handlebars_1.default.compile(dockerComposeTemplate)(packageManager === 'yarn'
|
108
|
+
? { installCmd: 'yarn install', devCmd: 'yarn dev' }
|
109
|
+
: { installCmd: 'npm install', devCmd: 'npm run dev' });
|
110
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'docker-compose.yml'), dockerCompose)];
|
111
|
+
case 11:
|
112
|
+
_a.sent();
|
113
|
+
return [2 /*return*/];
|
114
|
+
}
|
115
|
+
});
|
116
|
+
});
|
117
|
+
}
|
118
|
+
exports.writeCommonFiles = writeCommonFiles;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (_) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.writeEnvFile = void 0;
|
43
|
+
var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
|
44
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
45
|
+
var log_1 = require("../utils/log");
|
46
|
+
function writeEnvFile(projectName, databaseUri, payloadSecret) {
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
48
|
+
var content, projectDir, err_1;
|
49
|
+
return __generator(this, function (_a) {
|
50
|
+
switch (_a.label) {
|
51
|
+
case 0:
|
52
|
+
content = "MONGODB_URI=".concat(databaseUri, "\nPAYLOAD_SECRET=").concat(payloadSecret);
|
53
|
+
_a.label = 1;
|
54
|
+
case 1:
|
55
|
+
_a.trys.push([1, 3, , 4]);
|
56
|
+
projectDir = "./".concat((0, slugify_1.default)(projectName));
|
57
|
+
return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(projectDir, "/.env"), content)];
|
58
|
+
case 2:
|
59
|
+
_a.sent();
|
60
|
+
(0, log_1.success)('.env file created');
|
61
|
+
return [3 /*break*/, 4];
|
62
|
+
case 3:
|
63
|
+
err_1 = _a.sent();
|
64
|
+
(0, log_1.error)('Unable to write .env file');
|
65
|
+
if (err_1 instanceof Error) {
|
66
|
+
(0, log_1.error)(err_1.message);
|
67
|
+
}
|
68
|
+
process.exit(1);
|
69
|
+
return [3 /*break*/, 4];
|
70
|
+
case 4: return [2 /*return*/];
|
71
|
+
}
|
72
|
+
});
|
73
|
+
});
|
74
|
+
}
|
75
|
+
exports.writeEnvFile = writeEnvFile;
|
package/dist/main.js
CHANGED
@@ -43,19 +43,19 @@ exports.Main = void 0;
|
|
43
43
|
var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
|
44
44
|
var arg_1 = __importDefault(require("arg"));
|
45
45
|
var command_exists_1 = __importDefault(require("command-exists"));
|
46
|
-
var
|
47
|
-
var
|
48
|
-
var
|
49
|
-
var
|
50
|
-
var
|
51
|
-
var
|
46
|
+
var create_project_1 = require("./lib/create-project");
|
47
|
+
var get_db_connection_1 = require("./lib/get-db-connection");
|
48
|
+
var generate_secret_1 = require("./lib/generate-secret");
|
49
|
+
var parse_language_1 = require("./lib/parse-language");
|
50
|
+
var parse_project_name_1 = require("./lib/parse-project-name");
|
51
|
+
var parse_template_1 = require("./lib/parse-template");
|
52
52
|
var templates_1 = require("./lib/templates");
|
53
|
-
var
|
53
|
+
var write_env_file_1 = require("./lib/write-env-file");
|
54
54
|
var log_1 = require("./utils/log");
|
55
55
|
var messages_1 = require("./utils/messages");
|
56
|
-
var usage_1 = require("./utils/usage");
|
57
56
|
var Main = /** @class */ (function () {
|
58
57
|
function Main() {
|
58
|
+
// @ts-expect-error bad typings
|
59
59
|
this.args = (0, arg_1.default)({
|
60
60
|
'--help': Boolean,
|
61
61
|
'--name': String,
|
@@ -73,75 +73,72 @@ var Main = /** @class */ (function () {
|
|
73
73
|
}
|
74
74
|
Main.prototype.init = function () {
|
75
75
|
return __awaiter(this, void 0, void 0, function () {
|
76
|
-
var _a, _b, templateArg, valid, _c, _d, projectName, language, validTemplates, template, databaseUri, payloadSecret, projectDir, packageManager,
|
77
|
-
return __generator(this, function (
|
78
|
-
switch (
|
76
|
+
var _a, _b, templateArg, valid, _c, _d, projectName, language, validTemplates, template, databaseUri, payloadSecret, projectDir, packageManager, error_1;
|
77
|
+
return __generator(this, function (_e) {
|
78
|
+
switch (_e.label) {
|
79
79
|
case 0:
|
80
|
-
|
80
|
+
_e.trys.push([0, 16, , 17]);
|
81
81
|
if (!this.args['--help']) return [3 /*break*/, 2];
|
82
82
|
_b = (_a = console).log;
|
83
83
|
return [4 /*yield*/, (0, messages_1.helpMessage)()];
|
84
84
|
case 1:
|
85
|
-
_b.apply(_a, [
|
85
|
+
_b.apply(_a, [_e.sent()]);
|
86
86
|
process.exit(0);
|
87
|
-
|
87
|
+
_e.label = 2;
|
88
88
|
case 2:
|
89
89
|
templateArg = this.args['--template'];
|
90
90
|
if (!templateArg) return [3 /*break*/, 5];
|
91
91
|
return [4 /*yield*/, (0, templates_1.validateTemplate)(templateArg)];
|
92
92
|
case 3:
|
93
|
-
valid =
|
93
|
+
valid = _e.sent();
|
94
94
|
if (!!valid) return [3 /*break*/, 5];
|
95
95
|
_d = (_c = console).log;
|
96
96
|
return [4 /*yield*/, (0, messages_1.helpMessage)()];
|
97
97
|
case 4:
|
98
|
-
_d.apply(_c, [
|
98
|
+
_d.apply(_c, [_e.sent()]);
|
99
99
|
process.exit(1);
|
100
|
-
|
100
|
+
_e.label = 5;
|
101
101
|
case 5:
|
102
102
|
console.log(messages_1.welcomeMessage);
|
103
|
-
return [4 /*yield*/, (0,
|
103
|
+
return [4 /*yield*/, (0, parse_project_name_1.parseProjectName)(this.args)];
|
104
104
|
case 6:
|
105
|
-
projectName =
|
106
|
-
return [4 /*yield*/, (0,
|
105
|
+
projectName = _e.sent();
|
106
|
+
return [4 /*yield*/, (0, parse_language_1.parseLanguage)(this.args)];
|
107
107
|
case 7:
|
108
|
-
language =
|
108
|
+
language = _e.sent();
|
109
109
|
return [4 /*yield*/, (0, templates_1.getValidTemplates)()];
|
110
110
|
case 8:
|
111
|
-
validTemplates =
|
112
|
-
return [4 /*yield*/, (0,
|
111
|
+
validTemplates = _e.sent();
|
112
|
+
return [4 /*yield*/, (0, parse_template_1.parseTemplate)(this.args, validTemplates, language)];
|
113
113
|
case 9:
|
114
|
-
template =
|
115
|
-
return [4 /*yield*/, (0,
|
114
|
+
template = _e.sent();
|
115
|
+
return [4 /*yield*/, (0, get_db_connection_1.getDatabaseConnection)(this.args, projectName)];
|
116
116
|
case 10:
|
117
|
-
databaseUri =
|
118
|
-
return [4 /*yield*/, (0,
|
117
|
+
databaseUri = _e.sent();
|
118
|
+
return [4 /*yield*/, (0, generate_secret_1.generateSecret)()];
|
119
119
|
case 11:
|
120
|
-
payloadSecret =
|
120
|
+
payloadSecret = _e.sent();
|
121
121
|
projectDir = "./".concat((0, slugify_1.default)(projectName));
|
122
122
|
return [4 /*yield*/, getPackageManager(this.args)];
|
123
123
|
case 12:
|
124
|
-
packageManager =
|
124
|
+
packageManager = _e.sent();
|
125
125
|
if (!!this.args['--dry-run']) return [3 /*break*/, 15];
|
126
|
-
return [4 /*yield*/, (0,
|
126
|
+
return [4 /*yield*/, (0, create_project_1.createProject)(this.args, projectDir, template, packageManager)];
|
127
127
|
case 13:
|
128
|
-
|
129
|
-
return [4 /*yield*/, (0,
|
128
|
+
_e.sent();
|
129
|
+
return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)(projectName, databaseUri, payloadSecret)];
|
130
130
|
case 14:
|
131
|
-
|
132
|
-
|
131
|
+
_e.sent();
|
132
|
+
_e.label = 15;
|
133
133
|
case 15:
|
134
134
|
(0, log_1.success)('Payload project successfully created');
|
135
|
-
|
136
|
-
return [
|
135
|
+
console.log((0, messages_1.successMessage)(projectDir, packageManager));
|
136
|
+
return [3 /*break*/, 17];
|
137
137
|
case 16:
|
138
|
-
|
139
|
-
return [3 /*break*/, 18];
|
140
|
-
case 17:
|
141
|
-
error_1 = _g.sent();
|
138
|
+
error_1 = _e.sent();
|
142
139
|
console.log(error_1);
|
143
|
-
return [3 /*break*/,
|
144
|
-
case
|
140
|
+
return [3 /*break*/, 17];
|
141
|
+
case 17: return [2 /*return*/];
|
145
142
|
}
|
146
143
|
});
|
147
144
|
});
|
@@ -169,9 +166,7 @@ function getPackageManager(args) {
|
|
169
166
|
error_2 = _a.sent();
|
170
167
|
packageManager = 'npm';
|
171
168
|
return [3 /*break*/, 4];
|
172
|
-
case 4:
|
173
|
-
(0, usage_1.setTags)({ package_manager: packageManager });
|
174
|
-
return [2 /*return*/, packageManager];
|
169
|
+
case 4: return [2 /*return*/, packageManager];
|
175
170
|
}
|
176
171
|
});
|
177
172
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"name": "payload-
|
2
|
+
"name": "payload-template-ts-todo",
|
3
3
|
"description": "Simple to-do list example",
|
4
4
|
"version": "1.0.0",
|
5
5
|
"main": "dist/server.js",
|
@@ -24,7 +24,6 @@
|
|
24
24
|
"cross-env": "^7.0.3",
|
25
25
|
"nodemon": "^2.0.6",
|
26
26
|
"ts-node": "^9.1.1",
|
27
|
-
"copyfiles": "^2.4.1"
|
28
|
-
"typescript": "^4.1.3"
|
27
|
+
"copyfiles": "^2.4.1"
|
29
28
|
}
|
30
29
|
}
|
package/dist/utils/log.js
CHANGED
@@ -7,7 +7,7 @@ exports.error = exports.info = exports.warning = exports.success = void 0;
|
|
7
7
|
var chalk_1 = __importDefault(require("chalk"));
|
8
8
|
var figures_1 = __importDefault(require("figures"));
|
9
9
|
var success = function (message) {
|
10
|
-
console.log(chalk_1.default.green(figures_1.default.tick)
|
10
|
+
console.log("".concat(chalk_1.default.green(figures_1.default.tick), " ").concat(chalk_1.default.bold(message)));
|
11
11
|
};
|
12
12
|
exports.success = success;
|
13
13
|
var warning = function (message) {
|
@@ -15,10 +15,10 @@ var warning = function (message) {
|
|
15
15
|
};
|
16
16
|
exports.warning = warning;
|
17
17
|
var info = function (message) {
|
18
|
-
console.log(chalk_1.default.yellow(figures_1.default.info)
|
18
|
+
console.log("".concat(chalk_1.default.yellow(figures_1.default.info), " ").concat(chalk_1.default.bold(message)));
|
19
19
|
};
|
20
20
|
exports.info = info;
|
21
21
|
var error = function (message) {
|
22
|
-
console.log(chalk_1.default.red(figures_1.default.cross)
|
22
|
+
console.log("".concat(chalk_1.default.red(figures_1.default.cross), " ").concat(chalk_1.default.bold(message)));
|
23
23
|
};
|
24
24
|
exports.error = error;
|
package/dist/utils/messages.js
CHANGED
@@ -49,7 +49,7 @@ var figures_1 = __importDefault(require("figures"));
|
|
49
49
|
var terminal_link_1 = __importDefault(require("terminal-link"));
|
50
50
|
var templates_1 = require("../lib/templates");
|
51
51
|
var header = function (message) {
|
52
|
-
return chalk_1.default.yellow(figures_1.default.star)
|
52
|
+
return "".concat(chalk_1.default.yellow(figures_1.default.star), " ").concat(chalk_1.default.bold(message));
|
53
53
|
};
|
54
54
|
exports.welcomeMessage = (0, chalk_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n {green Welcome to Payload. Let's create a project! }\n"], ["\n {green Welcome to Payload. Let's create a project! }\n"])));
|
55
55
|
function helpMessage() {
|