-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compildconfig): support multiple projects (#229)
* feat(compildconfig): support multiple projects This Pr adds the `--project` option to Scully. This makes it possible to support multiple projects in 1 cli app BREAKING CHANGE: The `scully.config.js` is now named `scully.projectName.config.js` You need to manually update the name. * Delete scully.scullyDocs.config.jsconfi accidentially commited * docs(mutliproject): added docs and better erros for multiproject * feat(configfile): add configFile optiona back in
- Loading branch information
1 parent
641ca23
commit bf046c7
Showing
7 changed files
with
200 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Scully command line options | ||
|
||
Scully has the following options available: | ||
|
||
- [Scully command line options](#scully-command-line-options) | ||
- [serve](#serve) | ||
- [showBrowser](#showbrowser) | ||
- [configFile](#configfile) | ||
- [project](#project) | ||
|
||
## serve | ||
|
||
```bash | ||
npx scully serve | ||
``` | ||
|
||
this starts the scully server helper on its own. You can use this to inspect the result from Scully, or to speed up the scully proccess a bit. it does not _build_ the project, it only serves the angular build files, and the scully result files. | ||
|
||
## showBrowser | ||
|
||
```bash | ||
npx scully --showBrowser | ||
``` | ||
|
||
Alias `--sb`. This will show the chromium browser that is rendering your application. Can be used to diagnose some issues | ||
|
||
## configFile | ||
|
||
```bash | ||
npx scully --configFile someName | ||
``` | ||
|
||
Alias `--cf`. loads a different config file. if used at the same time as `--project` the project flag takes precedence. | ||
|
||
## project | ||
|
||
```bash | ||
npx scully --project someName | ||
``` | ||
|
||
Alias `--pr`. This enables you to select a different project. Scully by default uses the project that is the default project of the Angular CLI. When you want to run for another project, you can use this option, or use the Angular CLI to set another default project. |
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,100 @@ | ||
/** load the plugin */ | ||
require('./extraPlugin/extra-plugin.js'); | ||
require('./extraPlugin/tocPlugin'); | ||
require('./extraPlugin/voidPlugin'); | ||
|
||
exports.config = { | ||
/** projectRoot is mandatory! */ | ||
projectRoot: './projects/sampleBlog/src/app', | ||
/** outDir is where the static distribution files end up */ | ||
outDir: './dist/static', | ||
// hostName: '0.0.0.0', | ||
extraRoutes: [''], | ||
routes: { | ||
'/demo/:id': { | ||
type: 'extra', | ||
numberOfPages: 5, | ||
}, | ||
'/home/:topLevel': { | ||
type: 'extra', | ||
data: [ | ||
{title: 'All routes in application', data: 'all'}, | ||
{title: 'Unpublished routes in application', data: 'unpublished'}, | ||
{title: 'Toplevel routes in application', data: ''}, | ||
], | ||
}, | ||
'/user/:userId': { | ||
// Type is mandatory | ||
type: 'json', | ||
/** | ||
* Every parameter in the route must exist here | ||
*/ | ||
userId: { | ||
url: 'https://jsonplaceholder.typicode.com/users', | ||
property: 'id', | ||
}, | ||
}, | ||
'/nouser/:userId/:friendCode': { | ||
// Type is mandatory | ||
type: 'json', | ||
/** | ||
* Every parameter in the route must exist here | ||
*/ | ||
userId: { | ||
url: 'https://jsonplaceholder.typicode.com/users', | ||
property: 'id', | ||
}, | ||
friendCode: { | ||
/** users are their own friend in this sample ;) */ | ||
url: 'https://jsonplaceholder.typicode.com/users?userId=${userId}', | ||
property: 'id', | ||
}, | ||
}, | ||
'/todos/:todoId': { | ||
// Type is mandatory | ||
type: 'json', | ||
/** | ||
* Every parameter in the route must exist here | ||
*/ | ||
todoId: { | ||
url: 'https://jsonplaceholder.typicode.com/todos', | ||
property: 'id', | ||
/** | ||
* Headers can be sent optionally | ||
*/ | ||
headers: { | ||
'API-KEY': '0123456789', | ||
}, | ||
}, | ||
}, | ||
'/nouser/:userId/:posts/:comments': { | ||
// Type is mandatory | ||
type: 'json', | ||
/** | ||
* Every parameter in the route must exist here | ||
*/ | ||
userId: { | ||
url: 'https://jsonplaceholder.typicode.com/users', | ||
property: 'id', | ||
}, | ||
posts: { | ||
url: 'https://jsonplaceholder.typicode.com/posts?userId=${userId}', | ||
property: 'id', | ||
}, | ||
comments: { | ||
url: 'https://jsonplaceholder.typicode.com/comments?postId=${posts}', | ||
property: 'id', | ||
}, | ||
}, | ||
'/blog/:slug': { | ||
type: 'contentFolder', | ||
postRenderers: ['toc'], | ||
slug: { | ||
folder: './blog', | ||
}, | ||
}, | ||
'/**': { | ||
type: 'void', | ||
}, | ||
}, | ||
}; |
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,32 +1,62 @@ | ||
import {pathExists} from 'fs-extra'; | ||
import {pathExists, readFileSync} from 'fs-extra'; | ||
import {join} from 'path'; | ||
import * as yargs from 'yargs'; | ||
import {ScullyConfig} from '..'; | ||
import {angularRoot, scullyConfig} from './config'; | ||
import {logWarn, yellow} from './log'; | ||
import {findAngularJsonPath} from './findAngularJsonPath'; | ||
import {ScullyConfig} from './interfacesandenums'; | ||
import {logError, logWarn, yellow} from './log'; | ||
|
||
export const {configFile: configFileName} = yargs | ||
const angularRoot = findAngularJsonPath(); | ||
|
||
let angularConfig; | ||
|
||
try { | ||
angularConfig = JSON.parse(readFileSync(join(angularRoot, 'angular.json')).toString()); | ||
} catch (e) { | ||
logError(`Angular config file could not be parsed!`, e); | ||
process.exit(15); | ||
} | ||
const defaFaultProjectName = angularConfig.defaultProject; | ||
|
||
const createConfigName = (name = defaFaultProjectName) => `scully.${name}.config.js`; | ||
|
||
export const {configFile: configFileName, project} = yargs | ||
.string('cf') | ||
.alias('cf', 'configFile') | ||
.default('cf', 'scully.config.js') | ||
.describe('cf', 'provide name for config file').argv; | ||
.default('cf', '') | ||
.describe( | ||
'cf', | ||
'provide name of the config file to use. if the option --project is also there that takes precedence)' | ||
) | ||
.string('pr') | ||
.alias('pr', 'project') | ||
.default('pr', '') | ||
.describe('pr', 'provide name of the project to handle').argv; | ||
|
||
export const compileConfig = async (): Promise<ScullyConfig> => { | ||
try { | ||
const path = join(angularRoot, configFileName); | ||
let path = join(angularRoot, createConfigName()); | ||
if (configFileName) { | ||
path = join(angularRoot, configFileName); | ||
} | ||
if (project) { | ||
path = join(angularRoot, createConfigName(project)); | ||
} | ||
if (!(await pathExists(path))) { | ||
/** no ts config, nothing to do. */ | ||
logWarn(`Config file "${yellow(path)}" not found, only rendering normal routes`); | ||
return ({} as unknown) as ScullyConfig; | ||
/** no js config, nothing to do. */ | ||
logWarn(` | ||
--------- | ||
Config file "${yellow(path)}" not found, only rendering routes without parameters | ||
The config file should have a name that is formated as: | ||
scully.${yellow('<projectName>')}.config.js | ||
where ${yellow('<projectName>')} is the name of the project as defined in the 'angular.json' file | ||
--------- | ||
`); | ||
return ({projectName: project || defaFaultProjectName} as unknown) as ScullyConfig; | ||
} | ||
const {config} = await import(path); | ||
return config; | ||
return {projectName: project || defaFaultProjectName, ...config}; | ||
} catch (e) { | ||
console.error(e); | ||
return ({} as unknown) as ScullyConfig; | ||
// console.error(e); | ||
return ({projectName: project || defaFaultProjectName} as unknown) as ScullyConfig; | ||
} | ||
}; | ||
|
||
function myReq(path: string): Promise<any> { | ||
return import(join(scullyConfig.homeFolder, path)); | ||
} |
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