Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 26, 2018
1 parent 2930fb3 commit c9e5174
Show file tree
Hide file tree
Showing 23 changed files with 267 additions and 244 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
npmFrog
======
# npmFrog

A nice npmjs.org-like web interface for jFrog Artifactory

Expand Down
14 changes: 7 additions & 7 deletions pm2.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
const env_local = {
"MOCK": true,
MOCK: true
};

module.exports = {
watchUI: {
name: "frog-ui",
script: "./node_modules/@vue/cli-service/bin/vue-cli-service.js",
args: "serve",
env_local,
env_local
},
compileServer: {
name: "frog-compile-server",
script: "./node_modules/typescript/bin/tsc",
cwd: "server",
args: "--watch",
env_local,
env_local
},
runServer: {
name: "frog-server",
script: "index.js",
cwd: "dist/server/",
env_local,
env_local
},
serveUIStatic: {
name: "frog-ui-static",
script: "serve",
env: {
PM2_SERVE_PATH: "dist/webui",
PM2_SERVE_PORT: 8000,
},
PM2_SERVE_PORT: 8000
}
}
}
};
8 changes: 2 additions & 6 deletions pm2.dev.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const tasks = require('./pm2.config');
const tasks = require("./pm2.config");

const runServer = tasks.runServer;
runServer.watch = true;

module.exports = {
apps: [
tasks.compileServer,
tasks.watchUI,
runServer,
]
apps: [tasks.compileServer, tasks.watchUI, runServer]
};
7 changes: 2 additions & 5 deletions pm2.prod.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const tasks = require('./pm2.config');
const tasks = require("./pm2.config");

module.exports = {
apps: [
tasks.runServer,
tasks.serveUIStatic,
]
apps: [tasks.runServer, tasks.serveUIStatic]
};
67 changes: 48 additions & 19 deletions server/artifactory-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,41 @@ function readMainCode(storageDir): string {
function fetchPackages(): AxiosPromise<PackagesResponse> {
if (process.env.MOCK) {
return new Promise<AxiosResponse>((resolve, reject) => {
resolve(createAxiosResponse(fs.readJSONSync(path.join(__dirname, 'mock', 'packages-all.json'))));
resolve(
createAxiosResponse(
fs.readJSONSync(path.join(__dirname, 'mock', 'packages-all.json')),
),
);
});
}
return (axios.get(`/-/all`));
return axios.get(`/-/all`);
}

async function getPackageDetail({ scope, packageName }): Promise<AxiosResponse> {
async function getPackageDetail({
scope,
packageName,
}): Promise<AxiosResponse> {
const latestVersionResponse = await getDistTags({ scope, packageName });
const latestVersion = latestVersionResponse.data.latest;
const key = `${scope}-${packageName}-${latestVersion}`;

const packageDetailResonse: AxiosResponse = process.env.MOCK
? await new Promise<AxiosResponse>((resolve, reject) => {
const packageResource = path.join(__dirname, 'mock', `${packageName}.json`);
let data;
try {
data = fs.readJSONSync(packageResource);
} catch (error) {
data = fs.readJSONSync(path.join(__dirname, 'mock', 'fractal-menu-enhancer.json'));
}
resolve(createAxiosResponse(data));
})
const packageResource = path.join(
__dirname,
'mock',
`${packageName}.json`,
);
let data;
try {
data = fs.readJSONSync(packageResource);
} catch (error) {
data = fs.readJSONSync(
path.join(__dirname, 'mock', 'fractal-menu-enhancer.json'),
);
}
resolve(createAxiosResponse(data));
})
: packageDetailCache[key]
? await new Promise<AxiosResponse>((resolve, reject) => {
resolve(createAxiosResponse(packageDetailCache[key]));
Expand All @@ -90,12 +103,18 @@ async function getPackageDetail({ scope, packageName }): Promise<AxiosResponse>

const additionalCode = process.env.MOCK
? await new Promise((resolve) => {
const packageResource = path.join(__dirname, 'mock', `${packageName}.readme.md`);
const packageResource = path.join(
__dirname,
'mock',
`${packageName}.readme.md`,
);
let data;
try {
data = readme2Html(packageResource);
} catch (error) {
data = readme2Html(path.join(__dirname, 'mock', 'fractal-menu-enhancer.readme.md'));
data = readme2Html(
path.join(__dirname, 'mock', 'fractal-menu-enhancer.readme.md'),
);
}
resolve({
readme: data,
Expand All @@ -105,7 +124,12 @@ async function getPackageDetail({ scope, packageName }): Promise<AxiosResponse>
: await new Promise(async (resolve, reject) => {
const packageDetail = packageDetailResonse.data;
const downloadUrl = packageDetail.versions[latestVersion].dist.tarball;
const storageDir = path.join(tmpDir, scope || '', packageName, latestVersion);
const storageDir = path.join(
tmpDir,
scope || '',
packageName,
latestVersion,
);
if (fs.existsSync(storageDir)) {
resolve(readAdditionalCode(storageDir));
} else {
Expand All @@ -122,7 +146,10 @@ async function getPackageDetail({ scope, packageName }): Promise<AxiosResponse>
// Store package in filesystem:
.then((result) => {
fs.ensureDirSync(storageDir);
const outputFilename = path.join(storageDir, `${packageName}-${latestVersion}.tar.gz`);
const outputFilename = path.join(
storageDir,
`${packageName}-${latestVersion}.tar.gz`,
);
fs.writeFileSync(outputFilename, result.data);
return outputFilename;
})
Expand Down Expand Up @@ -166,9 +193,11 @@ function readAdditionalCode(storageDir) {
function getDistTags({ scope, packageName }): AxiosPromise<any> {
return process.env.MOCK
? new Promise<AxiosResponse>((resolve, reject) => {
resolve(createAxiosResponse({
latest: '1.1.0',
}));
resolve(
createAxiosResponse({
latest: '1.1.0',
}),
);
})
: axios.get(`/-/package/${name2url({ scope, packageName })}/dist-tags`);
}
Expand Down
77 changes: 44 additions & 33 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,59 @@ app.use(bodyParser.json());
app.use(cors());

function handleError(error, targetResponse, msg) {
targetResponse.status(500).send(`Error: ${msg} Please verify your server settings.\n\n${error}`);
targetResponse
.status(500)
.send(`Error: ${msg} Please verify your server settings.\n\n${error}`);
}

app.get('/packages', (req, res) => {
artifactoryService.fetchPackages().then((response) => {
res.send(response.data);
}).catch((error) => {
handleError(error, res, `Could not get packagages from ${artifactoryService.baseURL}.`);
});
artifactoryService
.fetchPackages()
.then((response) => {
res.send(response.data);
})
.catch((error) => {
handleError(
error,
res,
`Could not get packagages from ${artifactoryService.baseURL}.`,
);
});
});

app.get('/package/:scope?/:packageName/dist-tags', (req, res) => {
artifactoryService.getDistTags(req.params).then((response) => {
res.send(response.data);
}).catch((error) => {
handleError(
error,
res,
`Could not get dist-tags for package "${
req.params.scope}/${req.params.packageName
}
" from ${
artifactoryService.baseURL
}.`);
});
artifactoryService
.getDistTags(req.params)
.then((response) => {
res.send(response.data);
})
.catch((error) => {
handleError(
error,
res,
`Could not get dist-tags for package "${req.params.scope}/${
req.params.packageName
}
" from ${artifactoryService.baseURL}.`,
);
});
});

app.get('/packageDetail/:scope?/:packageName', (req, res) => {
artifactoryService.getPackageDetail(req.params).then((response) => {
res.send(response.data);
}).catch((error) => {
handleError(
error,
res,
`Could not get package details for package "${
req.params.scope
}/${
req.params.packageName
}" from ${
artifactoryService.baseURL
}.`);
});
artifactoryService
.getPackageDetail(req.params)
.then((response) => {
res.send(response.data);
})
.catch((error) => {
handleError(
error,
res,
`Could not get package details for package "${req.params.scope}/${
req.params.packageName
}" from ${artifactoryService.baseURL}.`,
);
});
});

app.get('/config', (req, res) => {
Expand Down
11 changes: 2 additions & 9 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
"noImplicitAny": false,
"module": "commonjs",
"target": "es5",
"lib": [
"es5",
"es2015",
"dom",
"scripthost",
]
"lib": ["es5", "es2015", "dom", "scripthost"]
},
"include": [
"**/*.ts",
],
"include": ["**/*.ts"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Loading

0 comments on commit c9e5174

Please sign in to comment.