chore(react): adding prettier and formating files

This commit is contained in:
Ely Lucas
2020-12-07 09:31:33 -07:00
committed by GitHub
parent 01afdc42e5
commit 91aaaab71a
163 changed files with 3205 additions and 2535 deletions

View File

@@ -1,4 +1,3 @@
const path = require('path');
const { rollup } = require('rollup');
const virtual = require('@rollup/plugin-virtual');
@@ -6,7 +5,7 @@ const fs = require('fs');
function main() {
const input = process.argv[2] || get_input();
check(input).then(result => {
check(input).then((result) => {
const relative = path.relative(process.cwd(), input);
if (result.shaken) {
@@ -17,80 +16,83 @@ function main() {
});
}
function error(msg) {
console.error(msg);
process.exit(1);
console.error(msg);
process.exit(1);
}
function get_input() {
if (!fs.existsSync('package.json')) {
error(`Could not find package.json`);
}
if (!fs.existsSync('package.json')) {
error(`Could not find package.json`);
}
const pkg = JSON.parse(fs.readFileSync('package.json'), 'utf-8');
const pkg = JSON.parse(fs.readFileSync('package.json'), 'utf-8');
const unresolved = pkg.module || pkg.main || 'index';
const resolved = resolve(unresolved);
const unresolved = pkg.module || pkg.main || 'index';
const resolved = resolve(unresolved);
if (!resolved) {
error(`Could not resolve entry point`);
}
if (!resolved) {
error(`Could not resolve entry point`);
}
return resolved;
return resolved;
}
function resolve(file) {
if (is_directory(file)) {
return if_exists(`${file}/index.mjs`) || if_exists(`${file}/index.js`);
}
if (is_directory(file)) {
return if_exists(`${file}/index.mjs`) || if_exists(`${file}/index.js`);
}
return if_exists(file) || if_exists(`${file}.mjs`) || if_exists(`${file}.js`);
return if_exists(file) || if_exists(`${file}.mjs`) || if_exists(`${file}.js`);
}
function is_directory(file) {
try {
const stats = fs.statSync(file);
return stats.isDirectory();
} catch (err) {
return false;
}
try {
const stats = fs.statSync(file);
return stats.isDirectory();
} catch (err) {
return false;
}
}
function if_exists(file) {
return fs.existsSync(file) ? file : null;
return fs.existsSync(file) ? file : null;
}
const check = input => {
const resolved = path.resolve(input);
const check = (input) => {
const resolved = path.resolve(input);
return rollup({
input: '__agadoo__',
plugins: [
virtual({
__agadoo__: `import ${JSON.stringify(resolved)}`
}),
{
resolveId(id) {
if (!id.startsWith('.') && !id.startsWith('/')) {
return {id: id, external: true, moduleSideEffects: false};
}
return null;
}
}
],
onwarn: (warning, handle) => {
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
}
}).then(bundle => bundle.generate({
format: 'es'
})).then(o => {
const output = o.output;
console.log(output);
return {
shaken: output.length === 1 && output[0].code.trim() === ''
};
});
return rollup({
input: '__agadoo__',
plugins: [
virtual({
__agadoo__: `import ${JSON.stringify(resolved)}`,
}),
{
resolveId(id) {
if (!id.startsWith('.') && !id.startsWith('/')) {
return { id: id, external: true, moduleSideEffects: false };
}
return null;
},
},
],
onwarn: (warning, handle) => {
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
},
})
.then((bundle) =>
bundle.generate({
format: 'es',
})
)
.then((o) => {
const output = o.output;
console.log(output);
return {
shaken: output.length === 1 && output[0].code.trim() === '',
};
});
};
main();