Skip to content

Commit

Permalink
chore() publish 6.5.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 19, 2019
1 parent 593e2d6 commit 82c15a1
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/schematics",
"version": "6.5.0",
"version": "6.5.1",
"description": "Nest - modern, fast, powerful node.js web framework (@schematics)",
"main": "index.js",
"publishConfig": {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const DEFAULT_VERSION = '0.0.1';
export const DEFAULT_PATH_NAME = 'src';
export const DEFAULT_LIB_PATH = 'libs';
export const DEFAULT_APPS_PATH = 'apps';
export const DEFAULT_DIR_ENTRY_APP = 'main';
export const ALTERNATIVE_DIR_ENTRY_APP = 'default';
export const TEST_ENV = 'test';
7 changes: 7 additions & 0 deletions src/lib/sub-app/sub-app.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('SubApp Factory', () => {
const tree: UnitTestTree = runner.runSchematic('app', options);
const files: string[] = tree.files;
expect(files).toEqual([
'/apps/main/tsconfig.app.json',
'/apps/main/tslint.json',
'/apps/project/tsconfig.app.json',
'/apps/project/tslint.json',
'/apps/project/src/app.controller.spec.ts',
Expand All @@ -35,6 +37,8 @@ describe('SubApp Factory', () => {
const tree: UnitTestTree = runner.runSchematic('app', options);
const files: string[] = tree.files;
expect(files).toEqual([
'/apps/main/tsconfig.app.json',
'/apps/main/tslint.json',
'/apps/awesome-project/tsconfig.app.json',
'/apps/awesome-project/tslint.json',
'/apps/awesome-project/src/app.controller.spec.ts',
Expand All @@ -54,6 +58,9 @@ describe('SubApp Factory', () => {
const tree: UnitTestTree = runner.runSchematic('app', options);
const files: string[] = tree.files;
expect(files).toEqual([
'/apps/main/.babelrc',
'/apps/main/index.js',
'/apps/main/jsconfig.json',
'/apps/project/.babelrc',
'/apps/project/index.js',
'/apps/project/jsconfig.json',
Expand Down
99 changes: 78 additions & 21 deletions src/lib/sub-app/sub-app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
} from '@angular-devkit/schematics';
import * as fse from 'fs-extra';
import {
ALTERNATIVE_DIR_ENTRY_APP,
DEFAULT_APPS_PATH,
DEFAULT_DIR_ENTRY_APP,
DEFAULT_LANGUAGE,
DEFAULT_PATH_NAME,
TEST_ENV,
Expand All @@ -38,11 +40,18 @@ interface TsConfigPartialType {
}

export function main(options: SubAppOptions): Rule {
const defaultAppName =
options.name === DEFAULT_DIR_ENTRY_APP
? ALTERNATIVE_DIR_ENTRY_APP
: DEFAULT_DIR_ENTRY_APP;

options = transform(options);
return chain([
updateTsConfig(),
addSubAppToCliOptions(options.path, options.name),
moveDefaultAppToApps(options.path),
updatePackageJson(options, defaultAppName),
addSubAppToCliOptions(options.path, options.name, defaultAppName),
branchAndMerge(mergeWith(generateWorkspace(options, defaultAppName))),
moveDefaultAppToApps(options.path, defaultAppName, options.sourceRoot),
branchAndMerge(mergeWith(generate(options))),
]);
}
Expand Down Expand Up @@ -77,7 +86,6 @@ function updateJsonFile<T>(
callback((json as {}) as T);
host.overwrite(path, JSON.stringify(json, null, 2));
}

return host;
}

Expand All @@ -104,32 +112,62 @@ function updateTsConfig() {
};
}

function moveDefaultAppToApps(projectRoot: string): Rule {
function updatePackageJson(options: SubAppOptions, defaultAppName: string) {
return (host: Tree) => {
const nestCliFileExists = host.exists('nest-cli.json');
const nestFileExists = host.exists('nest.json');
if (!host.exists('package.json')) {
return host;
}
return updateJsonFile(
host,
'package.json',
(packageJson: Record<string, any>) => {
const scripts = packageJson.scripts;
if (!scripts) {
return;
}
const defaultTestScriptName = 'test:e2e';
if (!scripts[defaultTestScriptName]) {
return;
}
const defaultTestDir = 'test';
const newTestDir = join(
options.path as Path,
defaultAppName,
options.sourceRoot,
);
scripts[defaultTestScriptName] = (scripts[
defaultTestScriptName
] as string).replace(defaultTestDir, newTestDir);
},
);
};
}

let sourceRoot: string;
if (!nestCliFileExists && !nestFileExists) {
sourceRoot = DEFAULT_PATH_NAME;
} else {
const source = host.read(
nestCliFileExists ? 'nest-cli.json' : 'nest.json',
);
if (source) {
const sourceText = source.toString('utf-8');
const config = parseJson(sourceText) as Record<string, any>;
sourceRoot = (config && config.sourceRoot) || DEFAULT_PATH_NAME;
}
function moveDefaultAppToApps(
projectRoot: string,
appName: string,
sourceRoot = DEFAULT_PATH_NAME,
): Rule {
return (host: Tree) => {
if (process.env.NODE_ENV === TEST_ENV) {
return host;
}
if (fse.existsSync(sourceRoot)) {
fse.moveSync(sourceRoot, join(projectRoot as Path, appName, sourceRoot));
}
if (fse.existsSync(sourceRoot) && process.env.NODE_ENV !== TEST_ENV) {
fse.moveSync(sourceRoot, join(projectRoot as Path, sourceRoot));
const testDir = 'test';
if (fse.existsSync(testDir)) {
fse.moveSync(testDir, join(projectRoot as Path, appName, testDir));
}
return host;
};
}

function addSubAppToCliOptions(projectRoot: string, projectName: string): Rule {
function addSubAppToCliOptions(
projectRoot: string,
projectName: string,
appName: string,
): Rule {
const project = {
root: join(projectRoot as Path, projectName),
sourceRoot: join(projectRoot as Path, projectName, 'src'),
Expand All @@ -151,15 +189,34 @@ function addSubAppToCliOptions(projectRoot: string, projectName: string): Rule {
optionsFile.projects[projectName] = project;

// Update initial application options
if (
optionsFile.sourceRoot &&
optionsFile.sourceRoot.indexOf(projectRoot) >= 0
) {
return;
}
optionsFile.sourceRoot = join(
projectRoot as Path,
appName,
optionsFile.sourceRoot || DEFAULT_PATH_NAME,
);
},
);
};
}

function generateWorkspace(options: SubAppOptions, appName: string): Source {
const path = join(options.path as Path, appName);

return apply(url(join('./workspace' as Path, options.language)), [
template({
...strings,
...options,
}),
move(path),
]);
}

function generate(options: SubAppOptions): Source {
const path = join(options.path as Path, options.name);

Expand Down
1 change: 1 addition & 0 deletions src/lib/sub-app/sub-app.schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface SubAppOptions {
* Applications root directory
*/
rootDir?: string | Path;
sourceRoot?: string;
}
4 changes: 4 additions & 0 deletions src/lib/sub-app/workspace/js/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["env", "stage-0"],
"plugins": ["transform-decorators-legacy"]
}
2 changes: 2 additions & 0 deletions src/lib/sub-app/workspace/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('@babel/register');
require('./src/main');
10 changes: 10 additions & 0 deletions src/lib/sub-app/workspace/js/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES6",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"dist"
]
}
5 changes: 5 additions & 0 deletions src/lib/sub-app/workspace/ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
18 changes: 18 additions & 0 deletions src/lib/sub-app/workspace/ts/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"defaultSeverity": "error",
"extends": ["tslint:recommended"],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"quotemark": [true, "single"],
"member-access": [false],
"ordered-imports": [false],
"max-line-length": [true, 150],
"member-ordering": [false],
"interface-name": [false],
"arrow-parens": false,
"object-literal-sort-keys": false
},
"rulesDirectory": []
}

0 comments on commit 82c15a1

Please sign in to comment.