mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[ADF-4733] Create an adf-cli dispatcher to run the docker-publish (#4914)
* Create an adf-cli dispatcher to run the docker-publish * not needed * fix typo comma * Create the adf-cli dist folder that contains -bin -script -package.json Build the dist folder during the ADF CI/CI pipeline
This commit is contained in:
parent
fadcc19eba
commit
a6e18e6c1b
60
lib/cli/bin/adf-cli
Executable file
60
lib/cli/bin/adf-cli
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env node
|
||||
const minimist = require('minimist');
|
||||
const path = require('path');
|
||||
|
||||
const args = minimist(process.argv.slice(2), {
|
||||
boolean: ['verbose']
|
||||
});
|
||||
const scriptName = args._.shift();
|
||||
const scriptPath = path.join('../scripts', scriptName);
|
||||
|
||||
const cwd = process.cwd();
|
||||
process.chdir(path.join(__dirname, '..'));
|
||||
|
||||
|
||||
// This might get awkward, so we fallback to console if there was an error.
|
||||
let logger = null;
|
||||
try {
|
||||
logger = new (require('@angular-devkit/core').logging.IndentLogger)('root');
|
||||
const { bold, gray, red, yellow, white } = require('@angular-devkit/core').terminal;
|
||||
const filter = require('rxjs/operators').filter;
|
||||
|
||||
logger
|
||||
.pipe(filter(entry => (entry.level !== 'debug' || args.verbose)))
|
||||
.subscribe(entry => {
|
||||
let color = gray;
|
||||
let output = process.stdout;
|
||||
switch (entry.level) {
|
||||
case 'info': color = white; break;
|
||||
case 'warn': color = yellow; break;
|
||||
case 'error': color = red; output = process.stderr; break;
|
||||
case 'fatal': color = x => bold(red(x)); output = process.stderr; break;
|
||||
}
|
||||
|
||||
output.write(color(entry.message) + '\n');
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Reverting to manual console logging.\nReason: ${e.message}.`);
|
||||
logger = {
|
||||
debug: console.log.bind(console),
|
||||
info: console.log.bind(console),
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console),
|
||||
fatal: x => { console.error(x); process.exit(100); },
|
||||
createChild: () => logger,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Promise.resolve()
|
||||
.then(() => require(scriptPath).default(args, logger, cwd))
|
||||
.then(exitCode => process.exit(exitCode || 0))
|
||||
.catch(err => {
|
||||
logger.fatal(err && err.stack);
|
||||
process.exit(99);
|
||||
});
|
||||
} catch (err) {
|
||||
logger.fatal(err.stack);
|
||||
process.exit(99);
|
||||
}
|
5384
lib/cli/package-lock.json
generated
5384
lib/cli/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,8 @@
|
||||
"author": "Alfresco Software, Ltd.",
|
||||
"bin": {
|
||||
"adf-license": "./bin/doc/licenseList.js",
|
||||
"adf-audit": "./bin/doc/audit.js"
|
||||
"adf-audit": "./bin/doc/audit.js",
|
||||
"adf-cli": "./bin/adf-cli"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -14,10 +15,16 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/Alfresco/alfresco-ng2-components/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build-tsc": "tsc -p tsconfig.json",
|
||||
"dist": "rm -rf ./dist/ && npm run build-tsc && cp -R ./bin ./dist/ && cp ./package.json ./dist/"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^2.15.1",
|
||||
"license-checker": "^25.0.1",
|
||||
"npm-registry-fetch": "^3.9.0",
|
||||
"@angular-devkit/core": "^7.2.15",
|
||||
"rxjs": ">=6.2.2",
|
||||
"shelljs": "^0.8.3",
|
||||
"spdx-license-list": "^5.0.0",
|
||||
"ejs": "^2.6.1"
|
||||
|
82
lib/cli/scripts/docker-publish.ts
Normal file
82
lib/cli/scripts/docker-publish.ts
Normal file
@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { logging } from '@angular-devkit/core';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as path from 'path';
|
||||
|
||||
export interface PublishArgs {
|
||||
tag?: string;
|
||||
loginCheck?: boolean;
|
||||
loginUsername?: string;
|
||||
loginPassword?: string;
|
||||
loginRepo?: string;
|
||||
dockerRepo?: string;
|
||||
dockerTags?: string;
|
||||
pathProject: string;
|
||||
}
|
||||
|
||||
function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
|
||||
if (process.platform.startsWith('win')) {
|
||||
args.unshift('/c', command);
|
||||
command = 'cmd.exe';
|
||||
}
|
||||
|
||||
const { status, error, stderr, stdout } = spawnSync(command, args, { ...opts });
|
||||
|
||||
if (status !== 0) {
|
||||
logger.error(`Command failed: ${command} ${args.map((x) => JSON.stringify(x)).join(', ')}`);
|
||||
if (error) {
|
||||
logger.error('Error: ' + (error ? error.message : 'undefined'));
|
||||
} else {
|
||||
logger.error(`STDERR:\n${stderr}`);
|
||||
}
|
||||
throw error;
|
||||
} else {
|
||||
return stdout.toString();
|
||||
}
|
||||
}
|
||||
|
||||
function _loginPerform(args: PublishArgs, logger: logging.Logger) {
|
||||
logger.info('Perform docker login...');
|
||||
const loginDockerRes = _exec('docker', ['login', `-u=${args.loginUsername}`, `-p=${args.loginPassword}`, `${args.loginRepo}`], {}, logger);
|
||||
logger.info(loginDockerRes);
|
||||
}
|
||||
|
||||
function _buildImagePerform(args: PublishArgs, tag: string, logger: logging.Logger) {
|
||||
logger.info('Perform docker build...');
|
||||
logger.info('Path project for Dockerfile...' + args.pathProject);
|
||||
|
||||
const buildDockerRes = _exec('docker', ['build', `-t=${args.dockerRepo}:${tag}`, args.pathProject], {}, logger);
|
||||
logger.info(buildDockerRes);
|
||||
}
|
||||
|
||||
export default async function (args: PublishArgs, logger: logging.Logger) {
|
||||
if (args.loginCheck === true) {
|
||||
_loginPerform(args, logger);
|
||||
}
|
||||
|
||||
if (args.dockerTags !== undefined) {
|
||||
args.dockerTags.split(',').forEach( (tag) => {
|
||||
logger.info(`Building docker image for tag ${tag} ...`);
|
||||
_buildImagePerform(args, tag, logger);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
35
lib/cli/tsconfig.json
Normal file
35
lib/cli/tsconfig.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noEmitOnError": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedParameters": false, // The linter is used for these.
|
||||
"noUnusedLocals": false, // The linter is used for these.
|
||||
"outDir": "./dist",
|
||||
"rootDir": ".",
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"target": "es2018",
|
||||
"lib": [
|
||||
"es2018"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"paths": {
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
"dist/**/*",
|
||||
"./build.ts",
|
||||
"node_modules/**/*"
|
||||
]
|
||||
}
|
@ -2,8 +2,11 @@
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
cd $DIR/../..
|
||||
cd $DIR/../../lib/cli/
|
||||
|
||||
echo "====== Cli ======"
|
||||
echo "====== Build ======"
|
||||
cp -R ./lib/cli/ lib/dist/cli/
|
||||
npm run dist
|
||||
|
||||
cd $DIR/../../
|
||||
cp -R ./lib/cli/dist lib/dist/cli/
|
||||
|
Loading…
x
Reference in New Issue
Block a user