mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5033] Improve publish script (#5297)
* check if npm package is already present before to publish * fix lint and remove duplicate password * fix script
This commit is contained in:
@@ -29,7 +29,13 @@ export function exec(command: string, args?: string[], opts?: { cwd?: string })
|
||||
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 (args) {
|
||||
logger.error(`Command failed: ${command} ${args.map((x) => JSON.stringify(x)).join(', ')}`);
|
||||
} else {
|
||||
logger.error(`Command failed ${command}`);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
logger.error('Error: ' + (error ? error.message : 'undefined'));
|
||||
} else {
|
||||
|
@@ -41,23 +41,43 @@ const projects = [
|
||||
'extensions'
|
||||
];
|
||||
|
||||
function npmPublish(args: PublishArgs, project: string) {
|
||||
async function npmPublish(args: PublishArgs, project: string) {
|
||||
if (args.npmRegistry) {
|
||||
changeRegistry(args, project);
|
||||
}
|
||||
logger.info(`Publishing lib ${project} to npm`);
|
||||
const options = ['publish'];
|
||||
if (args.tag) {
|
||||
options.push('-tag');
|
||||
options.push(`${args.tag}`);
|
||||
}
|
||||
const response = exec('npm', options, { cwd: path.resolve(`${args.pathProject}/lib/dist/${project}`) });
|
||||
logger.info(response);
|
||||
if (args.npmRegistry) {
|
||||
removeNPMRC(args, project);
|
||||
|
||||
const version = require(`${args.pathProject}/lib/dist/${project}/package.json`).version;
|
||||
|
||||
const exist = npmCheckExist(project, version);
|
||||
|
||||
if (!exist) {
|
||||
logger.info(`Publishing lib ${project} to npm`);
|
||||
const options = ['publish'];
|
||||
if (args.tag) {
|
||||
options.push('-tag');
|
||||
options.push(`${args.tag}`);
|
||||
}
|
||||
const response = exec('npm', options, { cwd: path.resolve(`${args.pathProject}/lib/dist/${project}`) });
|
||||
logger.info(response);
|
||||
if (args.npmRegistry) {
|
||||
removeNPMRC(args, project);
|
||||
}
|
||||
|
||||
await sleep(120000);
|
||||
} else {
|
||||
logger.info(`@alfresco/adf-${project}@${version} already exist`);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function npmCheckExist(project: string, version: string) {
|
||||
logger.info(`Check if lib ${project} is already in npm`);
|
||||
|
||||
const exist = exec(`npm`, [`view`, `@alfresco/adf-${project}@${version} version`] );
|
||||
|
||||
return exist !== '';
|
||||
}
|
||||
|
||||
function changeRegistry(args: PublishArgs, project: string) {
|
||||
logger.info(`Change registry... `);
|
||||
const folder = `${args.pathProject}/lib/dist/${project}`;
|
||||
@@ -98,9 +118,8 @@ async function main(args) {
|
||||
}
|
||||
|
||||
for (let i = 0; i < projects.length; i++) {
|
||||
await sleep(120000);
|
||||
logger.info(`========Analyzing project: ${projects[i]} ========`);
|
||||
npmPublish(args, projects[i]);
|
||||
await npmPublish(args, projects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ export interface CommitArgs {
|
||||
skipGnu: boolean;
|
||||
}
|
||||
|
||||
function commitPerform(args: CommitArgs): string {
|
||||
function getSha(args: CommitArgs): string {
|
||||
logger.info('Check commit sha...');
|
||||
|
||||
const gitPointer = args.pointer ? args.pointer : 'HEAD';
|
||||
@@ -57,7 +57,7 @@ function main(args) {
|
||||
.version('0.1.0')
|
||||
.description('This command allows you to update the commit sha as part of the package.json.\n' +
|
||||
'Your package.json must to have an existing property called "commit.\n\n' +
|
||||
'adf-cli update-commit-sha --pointer "HEAD~1" --pathProject "$(pwd)"\n\n' +
|
||||
'adf-cli update-commit-sha --pointer "HEAD~1" --pathProject "$(pwd)"\n\n' +
|
||||
'adf-cli update-commit-sha --pathProject "$(pwd)" --skipGnu')
|
||||
.option('--pointer [type]', 'pointer')
|
||||
.option('--pathPackage [type]', 'pathPackage')
|
||||
@@ -68,7 +68,7 @@ function main(args) {
|
||||
program.outputHelp();
|
||||
}
|
||||
|
||||
const sha = commitPerform(args);
|
||||
const sha = getSha(args);
|
||||
|
||||
replacePerform(args, sha);
|
||||
}
|
||||
|
Reference in New Issue
Block a user