Skip to content

Commit 9a070f4

Browse files
committed
initial commit
1 parent da34d50 commit 9a070f4

22 files changed

+425
-0
lines changed

.gitignore

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"type": "node",
10+
"request": "launch",
11+
"name": "Launch Program",
12+
"cwd": "${workspaceRoot}/example",
13+
"args": [
14+
"index.html"
15+
],
16+
"runtimeExecutable": "${env:HOME}/.nvm/versions/v7.3.0/bin/node",
17+
"program": "${workspaceRoot}/cli.js"
18+
}
19+
]
20+
}

cli.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env node
2+
var program = require('commander');
3+
var process = require('process');
4+
var path = require('path');
5+
var fse = require('fs-extra');
6+
var package = require('./package.json');
7+
var cac = require('./index');
8+
9+
program
10+
.description(package.description)
11+
.arguments('<file>')
12+
.action(function (file) {
13+
var fileText = fse.readFileSync(file, 'utf8');
14+
var components = cac.getComponentsFromHtml(fileText);
15+
var generatedCount = 0;
16+
17+
components.forEach(function(component){
18+
var targetPath = path.join(process.cwd(), component.dashedName);
19+
fse.removeSync(targetPath);
20+
fse.mkdirSync(targetPath);
21+
22+
var tsFilePath = path.join(targetPath, component.dashedName + '.component.ts');
23+
var cssFilePath = path.join(targetPath, component.dashedName + '.component.css');
24+
var htmlFilePath = path.join(targetPath, component.dashedName + '.component.html');
25+
var specFilePath = path.join(targetPath, component.dashedName + '.component.spec.ts');
26+
27+
fse.writeFileSync(tsFilePath, component.ts, 'utf8');
28+
fse.writeFileSync(cssFilePath, component.css, 'utf8');
29+
fse.writeFileSync(htmlFilePath, component.html, 'utf8');
30+
fse.writeFileSync(specFilePath, component.spec, 'utf8');
31+
generatedCount++;
32+
});
33+
34+
console.log('Generated ' + generatedCount + ' components, into ' + process.cwd());
35+
})
36+
.version(package.version)
37+
.parse(process.argv);
38+
39+
// Check the program.args obj - if none, show help
40+
if (program.args.length === 0) {
41+
program.help();
42+
}

example/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<div data-component="Test">
11+
<h1>Test</h1>
12+
<div class="inside" data-component="InnerTest">
13+
<span>content</span>
14+
<div class="inside" data-component="SubChildTest">
15+
<span>content</span>
16+
</div>
17+
<div class="inside" data-component="SubChildTest2">
18+
<span>content2</span>
19+
</div>
20+
</div>
21+
</div>
22+
</body>
23+
</html>

example/inner-test/inner-test.component.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="inside">
2+
<span>content</span>
3+
<sub-child-test></sub-child-test>
4+
<sub-child-test2></sub-child-test2>
5+
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { InnerTestComponent } from './inner-test.component';
4+
5+
describe('InnerTestComponent', () => {
6+
let component: InnerTestComponent;
7+
let fixture: ComponentFixture<InnerTestComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ InnerTestComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(InnerTestComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should be created', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
26+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'inner-test',
5+
templateUrl: './inner-test.component.html',
6+
styleUrls: ['./inner-test.component.css']
7+
})
8+
export class InnerTestComponent {
9+
constructor () {}
10+
}
11+

example/sub-child-test/sub-child-test.component.css

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="inside">
2+
<span>content</span>
3+
</div>

0 commit comments

Comments
 (0)