@@ -35,11 +35,14 @@ const corsSettings = cors({
3535} )
3636
3737function createApp ( argv = { } ) {
38+ // Override default configs (defaults) with passed-in params (argv)
3839 argv = Object . assign ( { } , defaults , argv )
3940
4041 argv . host = SolidHost . from ( { port : argv . port , serverUri : argv . serverUri } )
4142
42- argv . templates = initTemplates ( )
43+ let configPath = initConfigPath ( argv )
44+
45+ argv . templates = initTemplateDirs ( configPath )
4346
4447 let ldp = new LDP ( argv )
4548 let app = express ( )
@@ -103,15 +106,22 @@ function createApp (argv = {}) {
103106 return app
104107}
105108
106- function initTemplates ( ) {
107- let accountTemplatePath = ensureTemplateCopiedTo (
108- '../default-templates/new-account' ,
109- '../config/account-template'
109+ function initConfigPath ( argv ) {
110+ let configPath = path . resolve ( argv . configPath )
111+ fs . mkdirp ( configPath )
112+
113+ return configPath
114+ }
115+
116+ function initTemplateDirs ( configPath ) {
117+ let accountTemplatePath = ensureDirCopy (
118+ './default-templates/new-account' ,
119+ path . join ( configPath , 'templates' , 'new-account' )
110120 )
111121
112- let emailTemplatesPath = ensureTemplateCopiedTo (
113- '.. /default-templates/emails' ,
114- '../config/email- templates'
122+ let emailTemplatesPath = ensureDirCopy (
123+ './default-templates/emails' ,
124+ path . join ( configPath , ' templates', 'emails' )
115125 )
116126
117127 return {
@@ -121,29 +131,25 @@ function initTemplates () {
121131}
122132
123133/**
124- * Ensures that a template directory has been initialized in `config/` from
125- * default templates.
134+ * Ensures that a directory has been copied / initialized. Used to ensure that
135+ * account templates, email templates and default apps have been copied from
136+ * their defaults to the customizable config directory, at server startup.
126137 *
127- * @param defaultTemplateDir {string} Path to a default template directory,
128- * relative to `lib/`. For example, '../default-templates/emails' contains
129- * various email templates pre-defined by the Solid dev team.
138+ * @param fromDir {string} Path to copy from (defaults)
130139 *
131- * @param configTemplateDir {string} Path to a template directory customized
132- * to this particular installation (relative to `lib/`). Server operators
133- * are encouraged to override/customize these templates in the `config/`
134- * directory.
140+ * @param toDir {string} Path to copy to (customizable config)
135141 *
136- * @return {string } Returns the absolute path to the customizable template copy
142+ * @return {string } Returns the absolute path for `toDir`
137143 */
138- function ensureTemplateCopiedTo ( defaultTemplateDir , configTemplateDir ) {
139- let configTemplatePath = path . join ( __dirname , configTemplateDir )
140- let defaultTemplatePath = path . join ( __dirname , defaultTemplateDir )
144+ function ensureDirCopy ( fromDir , toDir ) {
145+ fromDir = path . resolve ( fromDir )
146+ toDir = path . resolve ( toDir )
141147
142- if ( ! fs . existsSync ( configTemplatePath ) ) {
143- fs . copySync ( defaultTemplatePath , configTemplatePath )
148+ if ( ! fs . existsSync ( toDir ) ) {
149+ fs . copySync ( fromDir , toDir )
144150 }
145151
146- return configTemplatePath
152+ return toDir
147153}
148154
149155/**
0 commit comments