Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Merge 7edcd58 into 8be6783
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Nov 29, 2018
2 parents 8be6783 + 7edcd58 commit ee5d54c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 8 deletions.
123 changes: 119 additions & 4 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ describe('generator-console-package:app:@easyops', () => {
`packages/${packageName}/package.json`,
`"name": "@easyops/${packageName}"`
);
assert.fileContent(
`packages/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
);
});

it('should update files', () => {
Expand All @@ -111,11 +115,118 @@ describe('generator-console-package:app:@easyops', () => {
});
});

describe('generator-console-package:app:@brick', () => {
const random = Math.random().toString(36).substring(7);
const Random = random.substr(0, 1).toUpperCase() + random.substr(1);
const packageName = `just-for-test-brick-${random}`;
const pascalCaseName = `JustForTestBrick${Random}`;
let mockSpawn;

beforeAll(() => {

return helpers
.run(path.join(__dirname, '../generators/app'))
.inTmpDir(dir => {
fs.copySync(path.join(__dirname, '../generators/app/templates/library/mock'), dir);
fs.writeJsonSync(path.resolve(dir, './package.json'), { name: 'unknown' });
})
.on('ready', gen => {
mockSpawn = sandbox.stub(gen, 'spawnCommand').callsFake(() => {
const spawnEvent = new EventEmitter();
process.nextTick(() => {
spawnEvent.emit('close');
});
return spawnEvent;
});
})
.withPrompts({
scope: '@brick',
packageName
});
});

afterAll(() => {
sandbox.restore();
});

it('should create files', () => {
assert.file([
// Created files:
`@brick/${packageName}/src/components/${packageName}.component.html`,
`@brick/${packageName}/src/components/${packageName}.component.scss`,
`@brick/${packageName}/src/components/${packageName}.component.spec.ts`,
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`@brick/${packageName}/src/index.module.ts`,
`@brick/${packageName}/package.json`,
`@brick/${packageName}/public_api.ts`,
`@brick/${packageName}/README.md`,

// Modified files:
'angular.json',
'tsconfig.json'
]);
});

it('should create correct files', () => {
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`selector: "${packageName}"`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`templateUrl: "./${packageName}.component.html"`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`styleUrls: ["./${packageName}.component.scss"]`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`styleUrls: ["./${packageName}.component.scss"]`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`export class ${pascalCaseName}Component implements OnInit`
);
assert.fileContent(
`@brick/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
`@brick/${packageName}/package.json`,
`"name": "@brick/${packageName}"`
);
assert.noFileContent(
`@brick/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
);
});

it('should update files', () => {
assert.fileContent(
'angular.json',
`"${packageName}": {\n "root": "@brick/${packageName}/src"`
);
assert.fileContent(
'tsconfig.json',
`"@brick/${packageName}": [\n "@brick/${packageName}"\n ]`
);
});

it('should run `yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('yarn', ['link'], {
cwd: `@brick/${packageName}/dist`
})).toBe(true);

expect(mockSpawn.callCount).toBe(1);
});
});

describe('generator-console-package:app:@plugin-common', () => {
const random = Math.random().toString(36).substring(7);
const Random = random.substr(0, 1).toUpperCase() + random.substr(1);
const packageName = `just-for-test-2-${random}`;
const pascalCaseName = `JustForTest2${Random}`;
const packageName = `just-for-test-common-${random}`;
const pascalCaseName = `JustForTestCommon${Random}`;
let mockSpawn;

beforeAll(() => {
Expand Down Expand Up @@ -192,6 +303,10 @@ describe('generator-console-package:app:@plugin-common', () => {
`@plugin-common/${packageName}/package.json`,
`"name": "@plugin-common/${packageName}"`
);
assert.fileContent(
`@plugin-common/${packageName}/package.json`,
'"start": "ng-packagr -w -p package.json"'
);
});

it('should update files', () => {
Expand All @@ -217,8 +332,8 @@ describe('generator-console-package:app:@plugin-common', () => {
describe('generator-console-package:app:@console-plugin', () => {
const random = Math.random().toString(36).substring(7);
const Random = random.substr(0, 1).toUpperCase() + random.substr(1);
const packageName = `just-for-test-3-${random}`;
const pascalCaseName = `JustForTest3${Random}`;
const packageName = `just-for-test-plugin-${random}`;
const pascalCaseName = `JustForTestPlugin${Random}`;
let mockSpawn;

beforeAll(() => {
Expand Down
16 changes: 12 additions & 4 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ const yosay = require('yosay');
const scopePropsMap = new Map();
scopePropsMap.set('@easyops', {
repository: 'Console-W',
subPackagePath: 'packages'
subPackagePath: 'packages',
removeScriptsStart: false
});
scopePropsMap.set('@brick', {
repository: 'console-plugins',
subPackagePath: '@brick',
removeScriptsStart: true
});
scopePropsMap.set('@plugin-common', {
repository: 'console-plugins',
subPackagePath: '@plugin-common'
subPackagePath: '@plugin-common',
removeScriptsStart: false
});
scopePropsMap.set('@console-plugin', {
repository: 'console-plugins',
subPackagePath: 'packages'
subPackagePath: 'packages',
removeScriptsStart: false
});
const scopes = Array.from(scopePropsMap.keys());

Expand Down Expand Up @@ -128,7 +136,7 @@ module.exports = class extends Generator {

tplPairs = {
'dist/package-for-yarn-link.json': 'dist/package.json',
'package-sample.json': 'package.json',
'package.json.ejs': 'package.json',
'README.md': 'README.md',
'src/index.module.ts': 'src/index.module.ts',
...['html', 'scss', 'spec.ts', 'ts'].reduce((acc, ext) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"license": "UNLICENSED",
"files": ["dist"],
"scripts": {
<% if (!removeScriptsStart) { %>
"start": "ng-packagr -w -p package.json",
<% } %>
"prebuild": "rimraf dist",
"build": "ng-packagr -p package.json",
"prepublishOnly": "npm run build",
Expand Down

0 comments on commit ee5d54c

Please sign in to comment.