create-bridge-app
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -16,36 +16,54 @@ #!/usr/bin/env node | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("./utils"); | ||
const prettier_1 = __importDefault(require("prettier")); | ||
const code_1 = require("./code"); | ||
const util_1 = require("util"); | ||
const exec = (0, util_1.promisify)(require('child_process').exec); | ||
const readline_1 = __importDefault(require("readline")); | ||
const readline = readline_1.default.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
const os_1 = __importDefault(require("os")); | ||
const path_1 = __importDefault(require("path")); | ||
const prompts_1 = __importDefault(require("prompts")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const child_process_1 = require("child_process"); | ||
const launch = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const slugRegex = /^[a-zA-Z0-9-]+$/; | ||
const { projectName } = yield (0, prompts_1.default)({ | ||
type: 'text', | ||
name: 'projectName', | ||
message: `What's your project's name?`, | ||
validate: (text) => slugRegex.test(text) ? true : 'You can only use alphanumeric characters and -', | ||
}); | ||
if (fs_1.default.existsSync(`./${projectName}`)) { | ||
const { override } = yield (0, prompts_1.default)({ | ||
type: 'confirm', | ||
name: 'override', | ||
message: `A folder in ./${projectName} already exists. Do you want to override it?`, | ||
}); | ||
if (!override) | ||
process.exit(1); | ||
fs_1.default.rmSync(`./${projectName}`, { recursive: true }); | ||
} | ||
const { template } = yield (0, prompts_1.default)({ | ||
type: 'select', | ||
choices: [ | ||
{ title: 'minimal-express', value: 'minimal-express' }, | ||
{ title: 'minimal-http', value: 'minimal-http' }, | ||
], | ||
name: 'template', | ||
message: `Which template do you want to use?`, | ||
validate: (text) => slugRegex.test(text) ? true : 'You can only use alphanumeric characters and -', | ||
}); | ||
const tempRepoPath = path_1.default.join(`${os_1.default.tmpdir()},bridgeRepoTemp`); | ||
(0, child_process_1.execSync)(`git clone https://github.com/bridge-codes/bridge.git ${tempRepoPath} -q`); | ||
fs_1.default.mkdirSync(projectName); | ||
fs_1.default.renameSync(path_1.default.join(tempRepoPath, `examples/${template}`), projectName); | ||
const packageJSONPath = `./${projectName}/package.json`; | ||
fs_1.default.readFile(packageJSONPath, 'utf-8', (err, data) => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
const regexStr = `"name": "${template}",`; | ||
const result = data.replace(new RegExp(regexStr, 'g'), `"name": "${projectName}",`); | ||
fs_1.default.writeFile(packageJSONPath, result, 'utf8', function (err) { | ||
if (err) | ||
return console.log(err); | ||
}); | ||
}); | ||
fs_1.default.rmSync(tempRepoPath, { recursive: true }); | ||
}); | ||
readline.question(`What's your project name? `, (name) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log(`Downloading dependencies...`); | ||
yield exec(`mkdir ${name}`); | ||
yield (0, utils_1.writeFileAsync)(`${name}/package.json`, prettier_1.default.format(`{ | ||
"name": "${name | ||
.toLowerCase() | ||
.normalize('NFD') | ||
.replace(/[^a-zA-Z0-9]/g, '')}", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"start": "node ./dist/index.js", | ||
"dev": "nodemon --config nodemon.json ./index.ts", | ||
"build": "tsc" | ||
} | ||
}`, { parser: 'json' })); | ||
yield exec(`cd ${name} && npm i bridge express zod dotenv && npm i --save-dev @types/express @types/node typescript ts-node nodemon && npx tsc --init --outDir dist`); | ||
Promise.all([ | ||
(0, utils_1.writeFileAsync)(`${name}/index.ts`, prettier_1.default.format(code_1.indexFile, { parser: 'typescript' })), | ||
(0, utils_1.writeFileAsync)(`${name}/nodemon.json`, prettier_1.default.format(code_1.nodemonFile, { parser: 'json' })), | ||
(0, utils_1.writeFileAsync)(`${name}/.gitignore`, code_1.gitIgnoreFile), | ||
(0, utils_1.writeFileAsync)(`${name}/.env`, `PROJECT_NAME=${name}\nPORT=8080\nSERVER_URL=http://localhost:8080`), | ||
(0, utils_1.writeFileAsync)(`${name}/README.md`, `#${name}\n\nWelcome on ${name}, this is a Bridge project, visit https://bridge.codes to learn how to automatically generate a complete online documentation and a fully typed client code in any language.`), | ||
]); | ||
readline.close(); | ||
})); | ||
launch(); |
{ | ||
"name": "create-bridge-app", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"description": "Create Bridge-powered Express app with one command", | ||
@@ -17,4 +17,3 @@ "author": "Bridge Team <support@bridge.codes>", | ||
"build": "tsc", | ||
"remove-dist": "if [ -d dist ]; then rm -rf dist; fi", | ||
"publish-minor": "npm run remove-dist && tsc && npm version patch && npm publish" | ||
"publish-minor": "tsc && npm version patch && npm publish" | ||
}, | ||
@@ -28,2 +27,3 @@ "repository": { | ||
"@types/prettier": "^2.7.1", | ||
"@types/prompts": "^2.4.2", | ||
"ts-node": "^10.9.1", | ||
@@ -34,4 +34,4 @@ "typescript": "^4.9.4" | ||
"prettier": "^2.8.1", | ||
"readline": "^1.3.0" | ||
"prompts": "^2.4.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
8801
4
145
2
3
+ Addedprompts@^2.4.2
+ Addedkleur@3.0.3(transitive)
+ Addedprompts@2.4.2(transitive)
+ Addedsisteransi@1.0.5(transitive)
- Removedreadline@^1.3.0
- Removedreadline@1.3.0(transitive)