magento2 – Magento 2 how to create custom index.php and pass store code programmatically?

I have a multi-vendor e-commerce platform, everytime I create a new store I need to create a folder for the store and include an index.php

for example:


Inside the index.php I add the store code like this:

$params = $_SERVER;
$params(MagentoStoreModelStoreManager::PARAM_RUN_CODE) = 'store2_code'; //this is the important line
$params(MagentoStoreModelStoreManager::PARAM_RUN_TYPE) = 'store';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $params);
/** @var MagentoFrameworkAppHttp $app */
$app = $bootstrap->createApplication('MagentoFrameworkAppHttp');

How could I programmatically create an index.php file and add the store code?
Currently I know how to create the store programmatically, but just the index.php is missing.