mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 22:23:10 +00:00
Fix directories resolve
This commit is contained in:
parent
84d106e7f8
commit
fb720da187
@ -48,14 +48,39 @@ const LIFECYCLES = {
|
||||
DESTROY: 'destroy',
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve the working directories based on the instance options.
|
||||
*
|
||||
* Behavior:
|
||||
* - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)
|
||||
* - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code
|
||||
*
|
||||
* Default values:
|
||||
* - If `appDir` is `undefined`, it'll be set to `process.cwd()`
|
||||
* - If `distDir` is `undefined`, it'll be set to `appDir`
|
||||
*/
|
||||
const resolveWorkingDirectories = opts => {
|
||||
const cwd = process.cwd();
|
||||
|
||||
const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;
|
||||
const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;
|
||||
|
||||
return { app: appDir, dist: distDir };
|
||||
};
|
||||
|
||||
class Strapi {
|
||||
constructor(opts = {}) {
|
||||
destroyOnSignal(this);
|
||||
|
||||
const distRootDir = opts.dir ? path.resolve(process.cwd(), opts.dir) : process.cwd();
|
||||
const appConfig = loadConfiguration(distRootDir, opts);
|
||||
const rootDirs = resolveWorkingDirectories(opts);
|
||||
|
||||
// Load the app configuration from the dist directory
|
||||
const appConfig = loadConfiguration(rootDirs.dist, opts);
|
||||
|
||||
// Instanciate the Strapi container
|
||||
this.container = createContainer(this);
|
||||
|
||||
// Register every Strapi registry in the container
|
||||
this.container.register('config', createConfigProvider(appConfig));
|
||||
this.container.register('content-types', contentTypesRegistry(this));
|
||||
this.container.register('services', servicesRegistry(this));
|
||||
@ -68,18 +93,17 @@ class Strapi {
|
||||
this.container.register('apis', apisRegistry(this));
|
||||
this.container.register('auth', createAuth(this));
|
||||
|
||||
this.dirs = utils.getDirs(
|
||||
{
|
||||
appDir: process.cwd(),
|
||||
distDir: distRootDir,
|
||||
},
|
||||
{ strapi: this }
|
||||
);
|
||||
// Create a mapping of every useful directory (for the app, dist and static directories)
|
||||
this.dirs = utils.getDirs(rootDirs, { strapi: this });
|
||||
|
||||
// Strapi state management variables
|
||||
this.isLoaded = false;
|
||||
this.reload = this.reload();
|
||||
|
||||
// Instanciate the Koa app & the HTTP server
|
||||
this.server = createServer(this);
|
||||
|
||||
// Strapi utils instanciation
|
||||
this.fs = createStrapiFs(this);
|
||||
this.eventHub = createEventHub();
|
||||
this.startupLogger = createStartupLogger(this);
|
||||
@ -88,6 +112,8 @@ class Strapi {
|
||||
this.telemetry = createTelemetry(this);
|
||||
|
||||
createUpdateNotifier(this).notify();
|
||||
|
||||
console.log(JSON.stringify(appConfig, null, 2));
|
||||
}
|
||||
|
||||
get config() {
|
||||
|
||||
@ -13,7 +13,7 @@ const getEnabledPlugins = require('../../core/loaders/plugins/get-enabled-plugin
|
||||
module.exports = async ({ buildDestDir, forceBuild = true, isTSProject, optimization, srcDir }) => {
|
||||
const strapiInstance = strapi({
|
||||
// TODO check if this is working @convly
|
||||
dir: buildDestDir,
|
||||
distDir: buildDestDir,
|
||||
autoReload: true,
|
||||
serveAdminPanel: false,
|
||||
});
|
||||
|
||||
@ -5,4 +5,4 @@ const strapi = require('../index');
|
||||
/**
|
||||
* `$ strapi start`
|
||||
*/
|
||||
module.exports = dir => strapi({ dir }).start();
|
||||
module.exports = distDir => strapi({ distDir }).start();
|
||||
|
||||
@ -16,7 +16,7 @@ module.exports = async function({ browser }) {
|
||||
const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
|
||||
|
||||
const strapiInstance = strapi({
|
||||
dir: buildDestDir,
|
||||
distDir: buildDestDir,
|
||||
autoReload: true,
|
||||
serveAdminPanel: false,
|
||||
});
|
||||
|
||||
4
packages/core/strapi/lib/core/bootstrap.js
vendored
4
packages/core/strapi/lib/core/bootstrap.js
vendored
@ -25,9 +25,9 @@ module.exports = async function({ strapi }) {
|
||||
}
|
||||
|
||||
// ensure public repository exists
|
||||
if (!(await fse.pathExists(strapi.dirs.public))) {
|
||||
if (!(await fse.pathExists(strapi.dirs.static.public))) {
|
||||
throw new Error(
|
||||
`The public folder (${strapi.dirs.public}) doesn't exist or is not accessible. Please make sure it exists.`
|
||||
`The public folder (${strapi.dirs.static.public}) doesn't exist or is not accessible. Please make sure it exists.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const { join, resolve } = require('path');
|
||||
|
||||
const getDirs = ({ appDir, distDir }) => ({
|
||||
const getDirs = ({ app: appDir, dist: distDir }, { strapi }) => ({
|
||||
dist: {
|
||||
root: distDir,
|
||||
src: join(distDir, 'src'),
|
||||
|
||||
@ -24,7 +24,10 @@ const createStrapiInstance = async ({
|
||||
} = {}) => {
|
||||
// read .env file as it could have been updated
|
||||
dotenv.config({ path: process.env.ENV_PATH });
|
||||
const options = { dir: TEST_APP_URL };
|
||||
const options = {
|
||||
appDir: TEST_APP_URL,
|
||||
distDir: TEST_APP_URL,
|
||||
};
|
||||
const instance = strapi(options);
|
||||
|
||||
if (bypassAuth) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user