Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/schematic-op…
Browse files Browse the repository at this point in the history
…tions

* upstream/master:
  feat(voidplugin): plugin that lets you exclude routes
  fix(scully readme): put readme back on npm
  feat(schematics): add support for nx monorepos (#162)
  Postrenderers addition (#160)
  chore(script): 🤖 add commit select for commit only the file the pr need (#158)
  improvement(scully): export built-in plugins (#153)
  feat(transferstateservice): Fix ngc error (#152)
  • Loading branch information
d-koppenhagen committed Jan 8, 2020
2 parents a799ccf + 1708e5c commit 4fd2cb0
Show file tree
Hide file tree
Showing 35 changed files with 158 additions and 2,461 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ Before you submit your Pull Request (PR) consider the following guidelines:

1. Commit your changes using a descriptive commit message that follows our
[commit message conventions](#commit). Adherence to these conventions
is necessary run the command `npm run commit`
is necessary run the command `npm run commit` (this add all the files using `git add .`) or
if you need only add some files, you can need run the command `npm run commit:select`.

1. Push your branch to GitHub:

Expand Down
2 changes: 1 addition & 1 deletion extraPlugin/extra-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {configValidator, routeSplit, registerPlugin} = require('../scully/bin');
const {configValidator, routeSplit, registerPlugin} = require('../dist/scully');

console.log(__dirname);

Expand Down
13 changes: 13 additions & 0 deletions extraPlugin/voidPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {configValidator, registerPlugin} = require('../dist/scully');

const voidPlugin = async (route, options) => {
/**
* I don't do anything here,
* just return an empty array
* as that will effectively remove the route from the list
* */
return [];
};

voidPlugin[configValidator] = async conf => [];
registerPlugin('router', 'void', voidPlugin);
24 changes: 24 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"restartable": "rs",
"ignore": [
".git",
"./node_modules",
"./projects",
"./scully",
"./blog"
],
"verbose": true,
"execMap": {
"js": "node"
},
"events": {
"restart": "osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
},
"watch": [
"dist/scully/"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js"
}
25 changes: 9 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@
"scripts": {
"ng": "ng",
"tsc": "tsc",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"compile:server_bak": "webpack --config webpack.server.config.js --progress --colors",
"build:ssr_bak": "npm run build:client-and-server-bundles && npm run compile:server",
"serve:ssr_bak": "node dist/server",
"build:client-and-server-bundles_bak": "ng build --prod && ng run sampleBlog:server:production --bundleDependencies all",
"serve:ssr": "node dist/server/main.js",
"build:ssr": "ng build --prod && ng run sampleBlog:server:production",
"generate": "tsc -p ./scully/tsconfig.scully.json && node ./scully/bin",
"scully:dev:watch": "tsc -w -p ./scully/tsconfig.scully.json",
"scully:dev:compile": "tsc -p ./scully/tsconfig.scully.json",
"scully:dev:run": "nodemon ./scully/bin/scully.js --ext js",
"scully:serve": "nodemon ./scully/bin/scully.js serve --ext js ",
"scully:dev:all": "ng build @scullyio/ng-lib && ng build && npm run scully:dev:compile && node ./scully/bin/scully",
"scully:dev:watch": "tsc -w -p ./scully/tsconfig.scully.json",
"scully:dev:compile": "tsc -p ./scully/tsconfig.scully.json",
"scully:dev:run": "nodemon ./dist/scully/scully.js --ext js",
"scully:serve": "nodemon ./dist/scully/scully.js serve --ext js ",
"scully:dev:all": "ng build @scullyio/ng-lib && ng build && npm run scully:dev:compile && node ./dist/scully/scully",
"scully:publish:patch": "cd ./scully && tsc -p ./tsconfig.scully.json && npm version patch && cp ./package.json ../dist/scully &&cp ./readme.md ../dist/scully && cd ../dist/scully && npm publish --access=public",
"scully:publish:minor": "tsc -p ./tsconfig.scully.json && npm version minor",
"scully:publish:major": "tsc -p ./tsconfig.scully.json && npm version major",
"commit": "git add . && npx git-cz",
"commit:select": "npx git-cz",
"build-bazel": "bazel build //...",
"test-bazel": "bazel test //...",
"compile-scully-watch": "ibazel build //scully:compile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const SCULLY_SCRIPT_ID = `scully-transfer-state`;
const SCULLY_STATE_START = `___SCULLY_STATE_START___`;
const SCULLY_STATE_END = `___SCULLY_STATE_END___`;

// Adding this dynamic comment to supress ngc error around Document as a DI token.
// https://github.com/angular/angular/issues/20351#issuecomment-344009887
/** @dynamic */
@Injectable({
providedIn: 'root',
})
Expand Down
Binary file modified schematics/scully/scullyio-init-0.0.7.tgz
Binary file not shown.
17 changes: 12 additions & 5 deletions schematics/scully/src/create-markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import {Rule, Tree, url, applyTemplates, move, chain, SchematicContext} from '@angular-devkit/schematics';
import {strings, normalize} from '@angular-devkit/core';
import {Schema as MyServiceSchema} from './schema';
import {addRouteToModule, addRouteToScullyConfig, applyWithOverwrite, getPrefix} from '../utils/utils';
import {
addRouteToModule,
addRouteToScullyConfig,
applyWithOverwrite,
getPrefix,
getSrc,
} from '../utils/utils';

const SCULLY_CONF_FILE = '/scully.config.js';
const ANGULAR_CONF_FILE = './angular.json';

export default function(options: MyServiceSchema): Rule {
return (host: Tree, context: SchematicContext) => {
try {
const sourceDir = getSrc(host);
const name = options.name ? options.name : 'blog';
const nameDasherized = strings.dasherize(options.name);
const sourceDir = options.sourceDir
const targetDirName = options.sourceDir
? strings.dasherize(options.sourceDir) // use sourceDir when provided
: strings.dasherize(options.name); // fall back to name when not provided
const date = new Date();
// format yyyy-mm-dd
const fullDay = date.toISOString().substring(0, 10);
const path = `./${sourceDir}/${fullDay}-${nameDasherized}.md`;
const path = `${targetDirName}/${fullDay}-${nameDasherized}.md`;
if (!host.exists(path)) {
host.create(
path,
Expand All @@ -39,7 +46,7 @@ publish: false
} catch (e) {
// for test in schematics
scullyJs = `exports.config = {
projectRoot: "./src/app",
projectRoot: "${getSrc(host)}/app",
routes: {
},
};`;
Expand All @@ -54,7 +61,7 @@ publish: false
host.overwrite(SCULLY_CONF_FILE, newScullyJs);
context.logger.info(`✅️ Update ${SCULLY_CONF_FILE}`);

const pathName = strings.dasherize(`./src/app/${name}`);
const pathName = strings.dasherize(`${sourceDir}/app/${name}`);
let prefix = 'app';
if (host.exists(ANGULAR_CONF_FILE)) {
prefix = getPrefix(host.read(ANGULAR_CONF_FILE).toString());
Expand Down
4 changes: 3 additions & 1 deletion schematics/scully/src/create-markdown/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ describe('create-markdown', () => {

it('should create the markdown file in the default directory', () => {
const dayString = new Date().toISOString().substring(0, 10);
const mdFileContent = getFileContent(appTree, `blog/${dayString}-blog.md`);
const expectedFileName = `/blog/${dayString}-blog.md`;
expect(appTree.files).toContain(expectedFileName);
const mdFileContent = getFileContent(appTree, expectedFileName);
expect(mdFileContent).toMatch(/title: This is the blog/g);
expect(mdFileContent).toMatch(/description: blog/g);
expect(mdFileContent).toMatch(/# Page blog example/g);
Expand Down
8 changes: 4 additions & 4 deletions schematics/scully/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Schema} from './schema';
import {scullyVersion, scullyComponentVersion} from './version-names';
import {addModuleImportToRootModule, getProjectFromWorkspace, getWorkspace} from 'schematics-utilities';
import {NodePackageInstallTask, RunSchematicTask} from '@angular-devkit/schematics/tasks';
import {getSrc} from '../utils/utils';

export default (options: Schema): Rule => {
return chain([
Expand Down Expand Up @@ -32,7 +33,7 @@ const addHttpClientModule = (options: Schema) => (tree: Tree, context: Schematic
};

const addPolyfill = (options: Schema) => (tree: Tree, context: SchematicContext) => {
let polyfills = tree.read('./src/polyfills.ts').toString();
let polyfills = tree.read(`${getSrc(tree)}/polyfills.ts`).toString();
if (polyfills.includes('SCULLY IMPORTS')) {
context.logger.info('⚠️ Skipping polyfills.ts');
} else {
Expand All @@ -42,13 +43,13 @@ const addPolyfill = (options: Schema) => (tree: Tree, context: SchematicContext)
\n* SCULLY IMPORTS
\n*/
\n// tslint:disable-next-line: align \nimport 'zone.js/dist/task-tracking';`;
tree.overwrite('./src/polyfills.ts', polyfills);
tree.overwrite(`${getSrc(tree)}/polyfills.ts`, polyfills);
}
};

const injectIdleService = (options: Schema) => (tree: Tree, context: SchematicContext) => {
try {
const appComponentPath = './src/app/app.component.ts';
const appComponentPath = `${getSrc(tree)}/app/app.component.ts`;
const appComponent = tree.read(appComponentPath).toString();
if (appComponent.includes('IdleMonitorService')) {
context.logger.info(`⚠️️ Skipping ${appComponentPath}`);
Expand All @@ -66,7 +67,6 @@ const injectIdleService = (options: Schema) => (tree: Tree, context: SchematicCo
idImport.search(/export class AppComponent {/g) + 'export class AppComponent {'.length;
output = [idImport.slice(0, position), add, idImport.slice(position)].join('');
} else {

const coma = haveMoreInjects(idImport);
const add = `${idle}${coma}`;
if (idImport.search(/constructor \(/) === -1) {
Expand Down
4 changes: 3 additions & 1 deletion schematics/scully/src/scully/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Rule, SchematicContext, Tree, SchematicsException} from '@angular-devkit/schematics';
import {Schema} from './schema';
import {getSrc} from '../utils/utils';
// for now we dont have any option for use
// @ts-ignore
export function scully(options: Schema): Rule {
Expand All @@ -24,10 +25,11 @@ export function scully(options: Schema): Rule {

// add config file
if (!tree.exists('./scully.config.js')) {
const srcFolder = getSrc(tree);
tree.create(
'./scully.config.js',
`exports.config = {
projectRoot: "./src/app",
projectRoot: "${srcFolder}/app",
routes: {
}
};`
Expand Down
12 changes: 10 additions & 2 deletions schematics/scully/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ export function getPrefix(angularjson: string) {
}

export function addRouteToModule(host: Tree, options: any) {
let path = './src/app/app-routing.module.ts';
const srcFolder = getSrc(host);
let path = `${srcFolder}/app/app-routing.module.ts`;
if (!host.exists(path)) {
path = './src/app/app.module.ts';
path = `${srcFolder}/app/app.module.ts`;
}
const text = host.read(path);
if (!text) {
Expand Down Expand Up @@ -148,6 +149,13 @@ function buildRelativeModulePath(options: ModuleOptions, modulePath: string): st
return buildRelativePath(modulePath, importModulePath);
}

export function getSrc(host: Tree) {
const angularConfig = JSON.parse(host.read('./angular.json').toString());
// TODO: make scully handle other projects as just the default one.
const defaultProject = angularConfig.defaultProject;
return angularConfig.projects[defaultProject].sourceRoot;
}

class FileNotFoundException extends Error {
constructor(fileName: string) {
const message = `File ${fileName} not found!`;
Expand Down
4 changes: 4 additions & 0 deletions scully.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** load the plugin */
require('./extraPlugin/extra-plugin.js');
require('./extraPlugin/voidPlugin');

exports.config = {
/** projectRoot is mandatory! */
Expand Down Expand Up @@ -88,5 +89,8 @@ exports.config = {
folder: './blog',
},
},
'/**': {
type: 'void',
},
},
};
40 changes: 0 additions & 40 deletions scully/index.d.ts

This file was deleted.

Loading

0 comments on commit 4fd2cb0

Please sign in to comment.