-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add plugins flag to newapp command
- Loading branch information
1 parent
d9dfb5d
commit 0d0b411
Showing
7 changed files
with
301 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,50 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const { replaceFileValuesFromMap, copyFile } = require("./utils"); | ||
const { | ||
createSrcFiles, | ||
validatePlugins, | ||
validateAppName, | ||
validateConfig, | ||
loadConfigFile, | ||
createNewApp, | ||
createPackageJsonFile, | ||
createConfigFile, | ||
createWebpackConfigFiles, | ||
createTestConfigFiles, | ||
getPluginsDepsAndConfig, | ||
} = require("./utils"); | ||
|
||
const baseAppPackageJSON = require("../app/package.json"); | ||
const baseAppPath = path.resolve(__dirname, "../app"); | ||
|
||
module.exports = function newApp(appName, { port }) { | ||
const appShellPath = path.resolve(__dirname, "../../../apps/"); | ||
const appPath = path.resolve(appShellPath, appName); | ||
const appExists = fs.existsSync(appPath); | ||
if (appExists) { | ||
console.error(`Error: App ${appName} already exists on ${appShellPath}`); | ||
module.exports = function newApp(appName, { port, plugins, config }) { | ||
try { | ||
let configFile; | ||
const isDefaultApp = !plugins && !config; | ||
|
||
validateAppName(appName); | ||
validatePlugins(plugins); | ||
validateConfig(config); | ||
if (config) configFile = loadConfigFile(config); | ||
const { pluginsDeps, pluginsConfig } = getPluginsDepsAndConfig({ | ||
isDefaultApp, | ||
plugins, | ||
configFile, | ||
}); | ||
const appPath = createNewApp(appName); | ||
createPackageJsonFile({ | ||
appName, | ||
baseAppPackageJSON, | ||
pluginsDeps, | ||
appPath, | ||
}); | ||
createConfigFile({ appPath, config, pluginsConfig }); | ||
createWebpackConfigFiles({ appPath, port, baseAppPath }); | ||
createTestConfigFiles({ appPath, baseAppPath }); | ||
createSrcFiles({ appPath, appName, baseAppPath }); | ||
} catch (e) { | ||
console.error(e); | ||
return; | ||
} | ||
|
||
console.log(`Creating a new app: ${appName}`); | ||
console.log(`Directory: ${appPath}`); | ||
console.log(`\n\n`); | ||
console.log("Creating app files..."); | ||
|
||
// create app dir | ||
fs.mkdirSync(appPath); | ||
fs.mkdirSync(`${appPath}/src`); | ||
fs.mkdirSync(`${appPath}/src/public`); | ||
|
||
// create app package.json | ||
fs.writeFileSync( | ||
`${appPath}/package.json`, | ||
JSON.stringify( | ||
{ | ||
name: appName, | ||
...baseAppPackageJSON, | ||
}, | ||
null, | ||
2 | ||
) | ||
); | ||
// create webpack config files | ||
const wpDev = replaceFileValuesFromMap(`${baseAppPath}/webpack.dev.js`, { | ||
__PORT__: +port, | ||
}); | ||
fs.writeFileSync(`${appPath}/webpack.dev.js`, wpDev); | ||
copyFile("webpack.common.js", appPath, baseAppPath); | ||
copyFile("webpack.prod.js", appPath, baseAppPath); | ||
// create test config files | ||
copyFile("jest.config.js", appPath, baseAppPath); | ||
|
||
// create src files | ||
const indexHtml = replaceFileValuesFromMap( | ||
`${baseAppPath}/src/public/index.html`, | ||
{ __APP_NAME__: appName } | ||
); | ||
const indexJs = replaceFileValuesFromMap(`${baseAppPath}/src/index.js`, { | ||
__APP_NAME__: appName, | ||
}); | ||
fs.writeFileSync(`${appPath}/src/public/index.html`, indexHtml); | ||
fs.writeFileSync(`${appPath}/src/index.js`, indexJs); | ||
|
||
console.log("Done!"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": { | ||
"ticketvote": { | ||
"version": "1.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.