create-near-app
Version:
Quickly scaffold your dApp on NEAR Blockchain
133 lines (132 loc) ⢠7.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cargoNearIsNotInstalled = exports.checkingCargoNear = exports.updateFilesFailed = exports.updatingFiles = exports.depsInstallError = exports.depsInstall = exports.creatingApp = exports.directoryExists = exports.windowsWarning = exports.unsupportedNodeVersion = exports.argsError = exports.gatewayInstructions = exports.contractInstructions = exports.setupSuccess = exports.successFrontendToText = exports.successContractToText = exports.setupFailed = exports.welcome = exports.show = void 0;
const chalk_1 = __importDefault(require("chalk"));
const tracking_1 = require("./tracking");
if (process.env.NEAR_NO_COLOR) {
chalk_1.default.level = 0;
}
const show = (...args) => console.log(...args);
exports.show = show;
const welcome = () => (0, exports.show)((0, chalk_1.default) `
{blue ======================================================}
š {bold {green Welcome to Near!}} Learn more: https://docs.near.org/
š§ Let's get your project ready.
{blue ======================================================}
(${tracking_1.trackingMessage})\n`);
exports.welcome = welcome;
const setupFailed = () => (0, exports.show)((0, chalk_1.default) `{bold {red ==========================================}}
{red āļø There was a problem during the project setup}.
Please refer to https://github.com/near/create-near-app README to troubleshoot.
Notice: some platforms aren't supported (yet).
{bold {red ==========================================}}`);
exports.setupFailed = setupFailed;
const mapContractLanguage = (contract) => {
switch (contract) {
case 'ts':
return 'Typescript';
case 'rs':
return 'Rust';
default:
return '';
}
};
const successContractToText = (contract) => contract === 'none'
? ''
: (0, chalk_1.default) `a smart contract in {bold ${mapContractLanguage(contract)}}`;
exports.successContractToText = successContractToText;
const frontendTemplates = {
'next-page': 'NextJS (Classic)',
'next-app': 'NextJS (App Router)',
'vite-react': 'Vite React'
};
const successFrontendToText = (frontend) => frontend === 'none'
? ''
: (0, chalk_1.default) `a web-app using ${frontendTemplates[frontend]}`;
exports.successFrontendToText = successFrontendToText;
const setupSuccess = (projectName, contract, frontend, install, needsToInstallCargoNear) => (0, exports.show)((0, chalk_1.default) `
ā
Success! Created '${projectName}', ${(0, exports.successContractToText)(contract)}${(0, exports.successFrontendToText)(frontend)}.
${contract === 'rs'
? (0, chalk_1.default) `š¦ If you are new to Rust please visit {bold {green https://www.rust-lang.org }}\n`
: ''}
{bold {bgYellow {black Next steps}}}:
${(0, exports.contractInstructions)(projectName, contract, install, needsToInstallCargoNear)}${(0, exports.gatewayInstructions)(projectName, frontend, install)}`);
exports.setupSuccess = setupSuccess;
const contractInstructions = (projectName, contract, install, needsToInstallCargoNear) => {
if (contract === 'none') {
return '';
}
let message = '';
if (needsToInstallCargoNear) {
message += (0, chalk_1.default) ` - {inverse Install cargo-near}:
{blue Go to {bold https://github.com/near/cargo-near}}\n`;
}
message += (0, chalk_1.default) ` - {inverse Navigate to your project}:
{blue cd {bold ${projectName}}}\n`;
if (contract === 'ts' && !install) {
message += (0, chalk_1.default) ` - {inverse Install all dependencies}
{blue npm {bold install}}\n`;
}
message += (0, chalk_1.default) ` - {inverse Build your contract}:\n`;
if (contract === 'ts') {
message += (0, chalk_1.default) ` {blue npm {bold run build}}\n`;
}
else {
message += (0, chalk_1.default) ` {blue {bold cargo near build}}\n`;
}
message += (0, chalk_1.default) ` - {inverse Test your contract} in the Sandbox:\n`;
if (contract === 'ts') {
message += (0, chalk_1.default) ` {blue npm {bold run test}}\n`;
}
else {
message += (0, chalk_1.default) ` {blue {bold cargo test}}\n`;
}
message += (0, chalk_1.default) `\nš§ Read {bold {greenBright README.md}} to explore further`;
return message;
};
exports.contractInstructions = contractInstructions;
const gatewayInstructions = (projectName, frontend, install) => frontend === 'none'
? ''
: (0, chalk_1.default) `
- {inverse Navigate to your project}:
{blue cd {bold ${projectName}}}
${!install
? (0, chalk_1.default) ` - {inverse Install all dependencies}
{blue npm {bold install}}`
: 'Then:'}
- {inverse Start your app}:
{blue npm {bold run dev}}`;
exports.gatewayInstructions = gatewayInstructions;
const argsError = (msg) => (0, exports.show)((0, chalk_1.default) `{red Arguments error: {white ${msg}}}
Run {blue npx create-near-app} without arguments, or use:
npx create-near-app <projectName> [--frontend next-app|next-page] [--contract rs|ts|none]`);
exports.argsError = argsError;
const unsupportedNodeVersion = (supported) => (0, exports.show)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
exports.unsupportedNodeVersion = unsupportedNodeVersion;
const windowsWarning = () => (0, exports.show)((0, chalk_1.default) `{red Please use Windows Subsystem for Linux (WSL) to develop smart contracts}
{yellow Learn more here: https://docs.near.org/blog/getting-started-on-windows}
`);
exports.windowsWarning = windowsWarning;
const directoryExists = (dirName) => (0, exports.show)((0, chalk_1.default) `{red This directory already exists! ${dirName}}`);
exports.directoryExists = directoryExists;
const creatingApp = () => (0, exports.show)((0, chalk_1.default) `\n- Creating a new {bold NEAR dApp}...`);
exports.creatingApp = creatingApp;
// Installing dependencies messages
const depsInstall = () => (0, exports.show)((0, chalk_1.default) `- Installing dependencies in a few folders, this might take a while...`);
exports.depsInstall = depsInstall;
const depsInstallError = () => (0, exports.show)(chalk_1.default.red('Error installing NEAR project dependencies'));
exports.depsInstallError = depsInstallError;
// Updating files messages
const updatingFiles = () => (0, exports.show)((0, chalk_1.default) `- Updating Cargo.toml and rust-toolchain.toml files from the remote source...`);
exports.updatingFiles = updatingFiles;
const updateFilesFailed = () => (0, exports.show)((0, chalk_1.default) ` {yellow There was a problem during the Cargo.toml and rust-toolchain.toml files remote updating. Check your internet connection.}\n`);
exports.updateFilesFailed = updateFilesFailed;
// Checking cargo-near messages
const checkingCargoNear = () => (0, exports.show)((0, chalk_1.default) `- Checking if cargo-near extension is installed...`);
exports.checkingCargoNear = checkingCargoNear;
const cargoNearIsNotInstalled = () => (0, exports.show)((0, chalk_1.default) ` {bold {yellow Did not find cargo-near, please install it to build and deploy Rust contracts: https://github.com/near/cargo-near}}`);
exports.cargoNearIsNotInstalled = cargoNearIsNotInstalled;
//# sourceMappingURL=messages.js.map