Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed readme with url links #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
Write more about the project
## f-meter
- f-meter is a command line interface which gives project audits and performance
- Internally uses lighthouse
- Providing url of website to f-meter
![Screenshot](https://i.imgur.com/GxKf0yH.png)

- It will calculate the values of audits like performance,accessebility etc and compaires it with standard values of web audits .Showing the results of comparison as below :
![Screenshot](https://imgur.com/xrdrOkR.png)
![Screenshot](https://imgur.com/lRYCgm9.png)
Binary file added bin/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions bin/custom.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
extends: 'lighthouse:default',
settings: {
'onlyCategories': [
'performance',
'accessibility',
'best-practices',
'seo',
'pwa'
],
'threshold-scores':{
'performance':60,
'accessibility':50,
'best-practices':50,
'seo':60,
'pwa':50
}
},
chromeOptions:{
headless:true,
sandboxing:false,
showLogStatus:false
},
urls:[
'https://www.twitter.com',
'https://www.facebook.com',
'https://www.qed42.com/blog'
]
}
94 changes: 94 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env node

var lighthouse = require('bin/node_modules/lighthouse');
const chromeLauncher = require('bin/node_modules/chrome-launcher');
var config = require('../configs/custom.config');
const Table = require('bin/node_modules/cli-table');
var clc = require("cli-color");
let tables=[],chromeFlags=['--disable-gpu'];
let i=0;
let threshold=config.settings["threshold-scores"];
const program=require('bin/node_modules/commander');
// var exec=require('child-process').exec;

// let urls=['https://www.twitter.com','https://www.facebook.com','https://www.qed42.com/careers'];
if(config.chromeOptions.headless){
chromeFlags.push('--headless');
}
if(!config.chromeOptions.sandboxing){
chromeFlags.push('--no-sandbox');
}
console.log("chrome flag array :",chromeFlags);

var opts = {
chromeFlags:chromeFlags,
logLevel: config.chromeOptions.showLogStatus ? 'info':'silent',
output:'json'
}

createTableStructure = () => {
return new Table({
head: [clc.cyanBright('Categories'), clc.cyanBright('Calculated Audits'), clc.cyanBright('Expected Audits')],
colWidths: [30, 30, 30]
});
}

createTableData = (newTable,res) => {
try {
if(res){
Object.values(res).map(data => {
newTable.push(
[clc.yellowBright(data.id), data.score*100 >= threshold[data.id] ? clc.green(data.score*100) : clc.red(data.score*100), threshold[data.id]]
)
})
}
console.log(newTable.toString());
} catch (err) {
console.log("error in creating table values :", err);
}
}

async function launcher(url){
return chromeLauncher.launch(opts).then(chrome => {
opts.port = chrome.port;
console.log("started :",chrome.pid);
return lighthouse(url,opts,config).then(result => {
console.log(`${url} :`,Object.values(result.lhr.categories).map(score => score.score));
return chrome.kill().then(() => result.lhr.categories);
})
});
}

async function auditUrls(urls){
for(let url of urls){
await launcher(url).then(results => {
let table;
table=createTableStructure();
createTableData(table,results);
tables.push({url:url,table:table});
});
}
console.log("\n-------------all audits are-----------------\n");
if(tables){
tables.map(data => {
console.log(`${data.url} :`);
console.log(`${data.table.toString()}`);
});
}
}

// async function auditUrls(urls){
// await urls.map(async (url,index) => {
// await launcher(url).then(results => {
// console.log(`${url} : ${results}`);

// });
// })
// }

auditUrls(config.urls);





19 changes: 19 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "fmeter-with-travis",
"version": "1.0.0",
"description": "Get project Info though CLI ",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chrome-launcher": "^0.11.2",
"cli-color": "^1.4.0",
"cli-table": "^0.3.1",
"colors": "^1.3.3",
"core-util-is": "^1.0.2",
"js-yaml": "^3.13.1",
"lighthouse": "^5.2.0"
}
}
23 changes: 23 additions & 0 deletions hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name":"fmeter-cli",
"version":"1.0.0",
"description":"Get project Info though CLI ",
"bin":{
"fmeter":"index.js"
},
"scripts":{
"test":"echo \"Error: no test specified\" && exit 1"
},
"dependencies":{
"commander":"^2.20.0",
"fs-extra":"^8.1.0",
"inquirer":"^6.3.1",
"lighthouse":"^5.2.0",
"chrome-launcher":"^0.11.2",
"cli-color":"^1.4.0",
"cli-table":"^0.3.1",
"colors":"^1.3.3",
"core-util-is":"^1.0.2",
"js-yaml":"^3.13.1"
}
}
83 changes: 83 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node

var program = require('commander');
var inquirer = require('inquirer');
var fs = require('fs-extra');
var merge = require('merge'),original,cloned;
const dest_curr_dir=process.cwd();
var src_dir='/usr/local/lib/node_modules/bin';
let template = {
name: "fmeter-cli",
version: "1.0.0",
description: "Get project Info though CLI ",
bin: {
fmeter: "index.js"
},
scripts: {
"test": "echo \"Error: no test specified\" && exit 1"
},
}

const questions=[
{ type: 'other', name: 'username', message: 'Specify your name :' },
{ type: 'other', name: 'useremail', message: 'Specify your email' },
];

function getFmeterFiles(){
if (!fs.existsSync('./bin')){
fs.mkdirSync('./bin');
fs.copySync(src_dir,`${dest_curr_dir}/bin`);
console.log("copied successfully...");
return true;
}
}

async function getUserInfo(){
return await inquirer
.prompt(questions)
.then(function(ans){
return ans;
});
}

function mergeDependancies(){
if(fs.exists(`${__dirname}/bin`)){
let originalFile=JSON.parse(fs.readFileSync('./package.json'));
let bin_jsonFile=JSON.parse(fs.readFileSync('./bin/package.json'));
original=originalFile["dependencies"];
bin_json=bin_jsonFile["dependencies"];
// console.log("original :",original["dependencies"]);
// console.log("bin :",bin_json["dependencies"]);
dependencies=merge(original,bin_json);
console.log("dependencies",dependencies);
template={...template,dependencies:dependencies}
console.log(template);
let data=JSON.stringify(template);
fs.unlinkSync('./package.json');
fs.createFileSync("./package.json");
fs.writeFileSync('hi.json',data);
console.log("files created successfully.");
}else{
console.log("first get the fmeter files.");
}
}

program
.command('init')
.description('configuring fmeter on local')
.action(()=>{
console.log("-------configuring fmeter----------");
fs.access(`${__dirname}/bin`,function(err){
if(!err){
console.log("File exits");
return;
}
getUserInfo().then(async res=>{
console.log("result is :",res);
getFmeterFiles();
mergeDependancies();
})
})
})

program.parse(process.argv);
Loading