@assylman/riverpod-cli
Version:
nodejs cli for creating well structured flutter riverpod folders and files needed to work with Riverpod plugin
35 lines (34 loc) • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInformationFromPubspec = getInformationFromPubspec;
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const _1 = require(".");
const flutterSdk = 'sdk: flutter';
function getInformationFromPubspec(name, options) {
const pubspecFile = './pubspec.yaml';
/// check if project has pubspec.yaml file
if (!fs_1.default.existsSync(pubspecFile)) {
throw Error('Cannot find pubspec.yaml file. Probably it\'s not a flutter project. Aborted...');
}
const data = fs_1.default.readFileSync(pubspecFile, { encoding: 'utf-8' });
const splittedData = data.split(os_1.default.EOL);
const useImports = options.useImports ?? _1.Imports.relative;
const info = {};
if (useImports.includes(_1.Imports.absolute)) {
info['useAbsoluteImports'] = true;
if (!splittedData[0]) {
/// throw an error if options flag is -i, but we cannot find packageName inside pubspec.yaml file
throw Error('Using absolute imports, can\'t find a package name inside your pubspec.yaml file');
}
const pkgName = splittedData[0].replaceAll('name: ', '');
info['packageName'] = pkgName;
}
else {
info['useAbsoluteImports'] = false;
}
return info;
}