2019-03-06 19:19:33 +01:00
|
|
|
const path = require('path');
|
|
|
|
const rimraf = require('rimraf');
|
|
|
|
const execa = require('execa');
|
2019-07-18 16:25:20 +02:00
|
|
|
const generateNew = require('strapi-generate-new/lib/generate-new');
|
2019-03-06 19:19:33 +01:00
|
|
|
|
2019-03-12 11:41:38 +01:00
|
|
|
/**
|
|
|
|
* Delete the testApp folder
|
|
|
|
* @param {string} appName - name of the app / folder where the app is located
|
|
|
|
*/
|
2019-03-06 19:19:33 +01:00
|
|
|
const cleanTestApp = appName => {
|
2019-03-12 11:41:38 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
rimraf(path.resolve(appName), err => {
|
|
|
|
if (err) reject(err);
|
2019-03-06 19:19:33 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-03-12 11:41:38 +01:00
|
|
|
/**
|
|
|
|
* Runs strapi generate new
|
|
|
|
* @param {Object} options - Options
|
|
|
|
* @param {string} options.appName - Name of the app that will be created (also the name of the folder)
|
|
|
|
* @param {database} options.database - Arguments to create the testApp with the provided database params
|
|
|
|
*/
|
2019-03-25 16:37:46 +01:00
|
|
|
const generateTestApp = async ({ appName, database }) => {
|
2019-07-18 16:25:20 +02:00
|
|
|
const scope = {
|
|
|
|
database: {
|
|
|
|
settings: database,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
rootPath: path.resolve(appName),
|
|
|
|
name: 'test-app',
|
|
|
|
// disable quickstart run app after creation
|
|
|
|
runQuickstartApp: false,
|
|
|
|
// use pacakge version as strapiVersion (all packages have the same version);
|
|
|
|
strapiVersion: require('strapi/package.json').version,
|
|
|
|
debug: false,
|
|
|
|
quick: false,
|
|
|
|
uuid: undefined,
|
|
|
|
deviceId: null,
|
|
|
|
// use yarn if available and --use-npm isn't true
|
|
|
|
useYarn: true,
|
|
|
|
installDependencies: false,
|
|
|
|
strapiDependencies: [
|
|
|
|
'strapi',
|
|
|
|
'strapi-admin',
|
|
|
|
'strapi-utils',
|
|
|
|
'strapi-plugin-settings-manager',
|
|
|
|
'strapi-plugin-content-type-builder',
|
|
|
|
'strapi-plugin-content-manager',
|
|
|
|
'strapi-plugin-users-permissions',
|
|
|
|
'strapi-plugin-email',
|
|
|
|
'strapi-plugin-upload',
|
|
|
|
'strapi-plugin-graphql',
|
|
|
|
'strapi-plugin-documentation',
|
|
|
|
],
|
|
|
|
additionalsDependencies: {},
|
|
|
|
};
|
2019-04-16 18:05:12 +02:00
|
|
|
|
2019-07-18 16:25:20 +02:00
|
|
|
await generateNew(scope);
|
2019-03-06 19:19:33 +01:00
|
|
|
};
|
|
|
|
|
2019-03-12 11:41:38 +01:00
|
|
|
/**
|
|
|
|
* Starts the test App in the appName folder
|
|
|
|
* @param {Object} options - Options
|
|
|
|
* @param {string} options.appName - Name of the app / folder in which run the start script
|
|
|
|
*/
|
2019-03-06 19:19:33 +01:00
|
|
|
const startTestApp = ({ appName }) => {
|
2019-05-15 09:22:00 +02:00
|
|
|
return execa.shell('strapi develop --no-build', {
|
2019-03-12 11:41:38 +01:00
|
|
|
stdio: 'inherit',
|
2019-03-06 19:19:33 +01:00
|
|
|
cwd: path.resolve(appName),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
cleanTestApp,
|
|
|
|
generateTestApp,
|
|
|
|
startTestApp,
|
|
|
|
};
|