gluestack-ui
Version:
A CLI tool for easily adding components from gluestack to your projects.
210 lines (209 loc) • 9.87 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "path", "fast-glob", "fs", "../../config", ".", "./config-types", "child_process", "..", "../init"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateConfigExpoApp = generateConfigExpoApp;
const path = __importStar(require("path"));
const fast_glob_1 = __importDefault(require("fast-glob"));
const fs = __importStar(require("fs"));
const config_1 = require("../../config");
const _1 = require(".");
const config_types_1 = require("./config-types");
const child_process_1 = require("child_process");
const __1 = require("..");
const init_1 = require("../init");
// expo project type initialization
function getExpoProjectType(cwd) {
return __awaiter(this, void 0, void 0, function* () {
const files = yield fast_glob_1.default.glob('**/*', {
cwd,
deep: 3,
ignore: config_types_1.PROJECT_SHARED_IGNORE,
});
const isExpoProject = files.find((file) => file.startsWith('app.json') ||
file.startsWith('app.config.ts') ||
file.startsWith('app.config.js'));
if (!isExpoProject) {
return undefined;
}
const expoLayoutPath = fs.existsSync('app')
? 'app/_layout.*'
: fs.existsSync('src/app')
? 'src/app/_layout.*'
: '**/*_layout.*';
const isUsingExpoRouter = yield (0, _1.getFilePath)([expoLayoutPath]);
const isUsingDefaultExpo = yield (0, _1.getFilePath)(['App.*']);
return isUsingExpoRouter
? 'expo-router'
: isUsingDefaultExpo
? 'expo-default'
: undefined;
});
}
function isExpoSDK50(cwd) {
return __awaiter(this, void 0, void 0, function* () {
//if expo project, check if expo version is greater than 50.0.0 by checking expo version in package.json file
const packageJsonPath = path.join(_1._currDir, 'package.json');
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonContent);
const expoVersion = packageJson.dependencies.expo;
// Check if expo dependency exists
if (!expoVersion) {
return false;
}
const version = expoVersion.replace('^', '').replace('~', '');
const versionArray = version.split('.');
const majorVersion = parseInt(versionArray[0]);
if (majorVersion < 50) {
return false;
}
return true;
});
}
function resolvedExpoPaths(resultConfig) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const resolvedExpoPaths = {
tailwind: {
config: (0, _1.pathResolver)(resultConfig.tailwind.config),
css: (0, _1.pathResolver)(resultConfig.tailwind.css),
},
config: {
babelConfig: (0, _1.pathResolver)(resultConfig.config.babelConfig || ''),
metroConfig: (0, _1.pathResolver)(resultConfig.config.metroConfig || ''),
tsConfig: (0, _1.pathResolver)(resultConfig.config.tsConfig || ''),
},
app: {
entry: (0, _1.pathResolver)(resultConfig.app.entry || ''),
type: (_a = resultConfig === null || resultConfig === void 0 ? void 0 : resultConfig.app) === null || _a === void 0 ? void 0 : _a.type,
sdk50: (_b = resultConfig === null || resultConfig === void 0 ? void 0 : resultConfig.app) === null || _b === void 0 ? void 0 : _b.sdk50,
},
};
return resolvedExpoPaths;
});
}
//project specific initialization: expo
function initNatiwindExpoApp(resolvedConfig, permission) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, child_process_1.execSync)('npx expo install babel-plugin-module-resolver', {
stdio: 'inherit',
});
yield (0, init_1.commonInitialization)(config_1.config.expoProject, resolvedConfig, permission);
}
catch (err) {
throw new Error(err.message);
}
});
}
function generateConfigExpoApp(permission) {
return __awaiter(this, void 0, void 0, function* () {
const projectType = yield getExpoProjectType(_1._currDir);
const entryPath = yield (0, _1.getFilePath)(['**/*_layout.*', '**/*App.*']);
const globalCssPath = yield (0, _1.getFilePath)([
'**/*globals.css',
'**/*global.css',
]);
const tailwindConfigPath = yield (0, _1.getFilePath)(['tailwind.config.*']);
const BabelConfigPath = yield (0, _1.getFilePath)(['babel.config.*']);
const MetroConfigPath = yield (0, _1.getFilePath)(['metro.config.*']);
const tsConfigPath = yield (0, _1.getFilePath)(['tsconfig.*']);
// const gluestackConfig: RawConfig = {
// tailwind: {
// config: tailwindConfigPath.length
// ? tailwindConfigPath
// : 'tailwind.config.js',
// css: globalCssPath.length ? globalCssPath : 'global.css',
// },
// app: {
// entry: entryPath,
// // write a function to get current components path
// components: config.writableComponentsPath,
// },
// };
const resolvedGluestackConfig = {
tailwind: {
config: tailwindConfigPath.length
? tailwindConfigPath
: 'tailwind.config.js',
css: globalCssPath.length ? globalCssPath : 'global.css',
},
config: {
babelConfig: BabelConfigPath.length ? BabelConfigPath : 'babel.config.js',
metroConfig: MetroConfigPath.length ? MetroConfigPath : 'metro.config.js',
tsConfig: tsConfigPath.length ? tsConfigPath : 'tsconfig.json',
},
app: {
entry: entryPath,
type: projectType,
sdk50: yield isExpoSDK50(_1._currDir),
},
};
// await generateConfig(gluestackConfig);
const resolvedConfig = yield resolvedExpoPaths(resolvedGluestackConfig);
const filesTobeEnsured = [
resolvedConfig.config.babelConfig,
resolvedConfig.config.metroConfig,
resolvedConfig.config.tsConfig,
resolvedConfig.tailwind.css,
(0, _1.pathResolver)('nativewind-env.d.ts'),
];
const filesEnsured = yield (0, __1.ensureFilesPromise)(filesTobeEnsured);
if (permission && filesEnsured) {
yield initNatiwindExpoApp(resolvedConfig, permission);
}
});
}
});