Has Anyone managed to install the suitecloud-cli n...
# sdf
p
Has Anyone managed to install the suitecloud-cli npm package without “-g”. Or is this not supported as of now?
a
whats the problem you are having installing without -g?
p
@Ali Syed (NS DevTools QA), Incompetence 🙂 I missed @oracle in the package name
a
so all good? if yes then enjoy and do share your feedback.
p
Almost! 🙂 what I’m trying to do is writing a predeployment script in Node that will basically download all Project objects to a seperate folder and then runs a compare with my project. What I’m trying to achieve is to require @oracle/suitecloud-cli” and avoid having to run it (the imports) as a shell command
a
you can do that in the `suitecloud.config.js`file by adding a predeployment function
🙏 1
p
Thank you very much! Must have missed that Help Page
a
Copy code
module.exports = {
    commands: {
        project:deploy: {
            projectFolder: 'dist', //this means it will deploy this folder instead of 'src',
             beforeExecuting: function(options){
               // perform your operations here
               return options;
             }
        },
    },
};
it supports promises, so if you return a Promise, the CLI will wait to perform the deployment until it's resolved
we presented something like this last SuiteWorld. This was the `suitecloud.config.js`file:
Copy code
const { build } = require('./gulpfile');


module.exports = {
	defaultProjectFolder: 'src',
	commands: {
		deploy: {
			projectFolder: 'dist',
			beforeExecuting: async options => {
				await build();
				return options;
			},
		},
		validate: {
			projectFolder: 'dist',
			beforeExecuting: async options => {
				await build();
				options.arguments.server = true;
				return options;
			},
		},
	},
};
We used gulp to run several functions before deployment (TypeScript transpiling, copying objects into final destination folder, running tests, etc)
This was the
gulpfile.js
Copy code
const { src, dest, series } = require('gulp');
var ts = require('gulp-typescript');
const del = require('del');
var jest = require('jest');

function test() {
	return jest.runCLI(
		{
			transform: {
				'^.+\\.jsx?$': 'babel-jest',
				'^.+\\.tsx?$': 'ts-jest',
			},
			testRegex: '(/__tests__/tests/.*|(\\.|/)(test|spec))\\.tsx?$',
			moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
			preset: 'ts-jest',
		},
		[process.cwd()]
	);
}

function clean() {
	console.log('Running clean');
	return del(['dist/**', '!dist']);
}

function copy() {
	console.log('Running copy');
	return new Promise((resolve, reject) => {
		var paths = ['src/**/*.xml'];
		src(paths)
			.pipe(dest('dist/'))
			.on('end', resolve)
			.on('error', reject);
	});
}

function buildTypeScript() {
	console.log('Transpiling TypeScript to JS');
	return new Promise((resolve, reject) => {
		var tsProject = ts.createProject('tsconfig.json');
		var tsResult = tsProject.src().pipe(tsProject());
		tsResult.js
			.pipe(dest('dist'))
			.on('end', () => {
				console.log('Transpiling done!');
				resolve();
			})
			.on('error', reject);
	});
}

function build() {
	console.log('Building project...');
	return new Promise((resolve, reject) => {
		try {
			series(test, clean, copy, buildTypeScript)(_ => {
				console.log('Building complete');
				resolve();
			});
		} catch (error) {
			console.log(error);
			reject(error);
		}
	});
}

module.exports = {
	build,
    test,
    clean
};
If you want to use
gulp
or
del
packages to do this, we used these npm packages: "del": "^4.0.0",     "gulp": "^4.0.0",
p
Thank you very much, very useful
a
no problem!
p
@Albert Margarit (NS Eng Lead), Big thanks for the input yesterday, making big progress creating some devtools for our team
a
awesome!
Please share with us more details about what you guys are building on top of the CLI. It can help us to drive future improvements