Skip to content
This repository was archived by the owner on Apr 5, 2021. It is now read-only.

Commit 9d6d8b0

Browse files
authored
Merge pull request #35 from A-Tokyo/development
V 0.4.0
2 parents d0002dd + df6b340 commit 9d6d8b0

File tree

64 files changed

+1666
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1666
-261
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Running a generator:
127127
yo at-angular:component my-component # Generates a component
128128
yo at-angular:component my-component/my-nested-component # Generates a nested component
129129
yo at-angular:component my-component/my-nested-component/... # Generates a multiple nested component
130+
yo at-angular:remove # Runs the at removal tool to remove a generated item
130131

131132
Running the project:
132133

generators/app/src/install.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ module.exports = function (AngularATGenerator) {
3838
}
3939

4040
deps = _.concat(deps, this.importList);
41-
42-
this.npmInstall(deps, {'save': true});
41+
if(!this.options.skipinstall){
42+
this.npmInstall(deps, {'save': true});
43+
}
4344
};
4445

4546
// Install dependencies from package.json
4647
AngularATGenerator.prototype.install = function install() {
4748
// install templated dependencies
49+
if(!this.options.skipinstall){
4850
this.npmInstall();
51+
}
4952
};
5053

5154
};

generators/app/templates/_docs/docs-assets/docs-app.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

generators/app/templates/_docs/docs-assets/docs.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ body {
44
-webkit-font-smoothing: antialiased;
55
}
66

7+
[ng-cloak] {
8+
display: none !important;
9+
}
10+
711
/*Navbar*/
812
.docs-navbar {
913
position: fixed;
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
// Docs in JSON format
2-
var docs =
3-
{
4-
"components": [
5-
// Add new components above
6-
],
7-
"directives": [
8-
// Add new directives above
9-
],
10-
"services": [
11-
{"name": "store", "nameCamel": "store", "path": "store", "description": "Store service fetches and holds some application data like arrays for dropdowns and so on."},
12-
// Add new services above
13-
],
14-
"pages": [
15-
// Add new pages above
16-
],
17-
"info": {"appName":"<%= props.appName %>", "port": 8080}
18-
// Add application info above
19-
};
1+
// generator-at-angular-docs angular application
2+
var docsApp = angular.module('generator-at-angular-docs', []);
3+
// Docs main controller
4+
docsApp.controller('docsCtrl', function ($scope, $http){
5+
$http({'method': "GET", 'url': 'docs-assets/docs.json', cache: false}).then(function(res){
6+
// attaching appName to scope
7+
$scope.appName = res.data.info.appName;
8+
// attaching docs to scope
9+
$scope.components = res.data.components;
10+
$scope.directives = res.data.directives;
11+
$scope.services = res.data.services;
12+
$scope.pages = res.data.pages;
13+
// Base href for app routes
14+
$scope.apphost = 'http://localhost:'+res.data.info.port;
15+
});
16+
// attaching currentYear to scope
17+
$scope.currentYear = new Date().getFullYear();
18+
/*
19+
* replaceSlashWith2Underscores
20+
* takes a string as an input
21+
* replaces every '/' with '__'
22+
*/
23+
$scope.replaceSlashWith2Underscores = function(string){
24+
return string.replace(new RegExp('/', 'g'), '__');
25+
};
26+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"components": [],
3+
"directives": [],
4+
"services": [{"name": "store", "nameCamel": "store", "path": "store", "description": "Store service fetches and holds some application data like arrays for dropdowns and so on."}],
5+
"pages": [],
6+
"info": {"appName":"<%= props.appName %>", "port": 8080}
7+
}

generators/app/templates/_docs/docs.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link rel="stylesheet" href="./docs-assets/docs.css">
1717
</head>
1818

19-
<body ng-controller="docsCtrl" ng-cloak data-spy="scroll" data-target=".navbar" data-offset="56">
19+
<body ng-controller="docsCtrl" data-spy="scroll" data-target=".navbar" data-offset="56">
2020
<nav class="navbar navbar-toggleable-sm navbar-inverse bg-primary docs-navbar">
2121
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
2222
<span class="navbar-toggler-icon"></span>
@@ -39,7 +39,7 @@
3939
</ul>
4040
</div>
4141
</nav>
42-
<article class="docs-body">
42+
<article class="docs-body" ng-cloak>
4343
<header class="jumbotron jumbotron-fluid">
4444
<div class="container">
4545
<h1 class="display-3 main-h">{{appName || 'App'}} Documentation</h1>
@@ -223,10 +223,8 @@ <h6>description:</h6>
223223
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
224224
<!-- AngularJS -->
225225
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
226-
<!-- docs as a JSON global object -->
226+
<!-- docs angular application -->
227227
<script src="./docs-assets/docs.js" charset="utf-8"></script>
228-
<!-- docs-app.js script -->
229-
<script src="./docs-assets/docs-app.js" charset="utf-8"></script>
230228
</body>
231229

232230
</html>

generators/app/templates/_package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"build": "cross-env NODE_ENV=production webpack -p --colors",
1414
"dev": "cross-env NODE_ENV=development webpack-dev-server --progress",
15-
"docs": "open -a \"Google Chrome\" docs/docs.html || open docs/docs.html || xdg-open docs/docs.html || explorer docs/docs.html",
15+
"docs": "node_modules/node-static/bin/cli.js ./docs -i docs.html -p 8081",
1616
"start": "npm run dev",
1717
"test": "karma start --log-level debug --single-run",
1818
"tests": "karma start --log-level debug"
@@ -60,6 +60,7 @@
6060
"karma-webpack": "^1.6.0",
6161
"ngtemplate-loader": "^1.3.1",
6262
"node-sass": "^3.4.0",
63+
"node-static": "^0.7.9",
6364
"postcss-loader": "^0.13.0",
6465
"sass-loader": "^4.0.2",
6566
"style-loader": "^0.13.1",

generators/component/src/files.js

Lines changed: 111 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,122 @@
11
'use strict';
22
const _ = require('lodash');
33
const utils = require('../../utils.js');
4+
const jsonfile = require('jsonfile');
5+
const jsonQuery = require('json-query');
6+
const fs = require('fs-extra');
47

58
module.exports = function(AngularATGenerator) {
69

7-
AngularATGenerator.prototype.copyCopmFiles = function copyFiles() {
8-
// setting defaults, component name and path settings
9-
let fullPath = this.props.componentName;
10-
let pathAsArray = fullPath.split('/');
11-
let componentName = pathAsArray[pathAsArray.length - 1];
12-
let parentName = null;
13-
let parentPath = null;
14-
let isDuplicate = false;
15-
// data to be passed to templates and used to get info
16-
const data = {
17-
'componentName': componentName,
18-
'componentNameCamel': _.camelCase(componentName),
19-
'controllerName': _.upperFirst(_.camelCase(componentName)),
20-
'componentModule': _.camelCase(componentName)
21-
};
22-
//if the component has no parent
23-
if (pathAsArray.length === 1) {
24-
try {
25-
const indexModulesWriteLine = "require('./components/" + data.componentName + "/" + data.componentName + ".module').name,";
26-
utils.addToFile('index.components.js', indexModulesWriteLine, utils.COMPONENT_MARKER, this.destinationRoot() + '/src/app');
27-
} catch (err) {
28-
this.log('Could not generate this item due to missing file structure.');
29-
return;
30-
}
31-
} else {
32-
//if the component is nested in a parent component
33-
parentName = pathAsArray[pathAsArray.length - 2];
34-
// if single parent, join by '/' else join by '/components/' to nest within the parent components
35-
const joinString = (pathAsArray.length>2)?'/components/':'/';
36-
parentPath = _.join(pathAsArray.slice(0, pathAsArray.length - 1), joinString);
37-
fullPath = parentPath + '/components/' + data.componentName;
38-
// importing files to parent component
39-
try {
40-
//module
41-
const moduleImport = "import * as " + data.componentModule + " from './components/" + componentName + '/' + componentName + ".module';";
42-
utils.addToFile(parentName + '.module.js', moduleImport, utils.IMPORT_MODULE_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
43-
//dependency
44-
const dependencyImport = "'" + data.componentModule + "',";
45-
utils.addToFile(parentName + '.module.js', dependencyImport, utils.IMPORT_DEPENDENCY_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
46-
} catch (err) {
47-
this.log('Parent component files not found.');
48-
return;
49-
}
50-
}
10+
AngularATGenerator.prototype.copyCopmFiles = function copyFiles() {
11+
// setting defaults, component name and path settings
12+
let fullPath = this.props.componentName;
13+
let pathAsArray = fullPath.split('/');
14+
let componentName = pathAsArray[pathAsArray.length - 1];
15+
let parentName = null;
16+
let parentPath = null;
17+
let isDuplicate = false;
18+
// data to be passed to templates and used to get info
19+
const data = {
20+
'componentName': componentName,
21+
'componentNameCamel': _.camelCase(componentName),
22+
'controllerName': _.upperFirst(_.camelCase(componentName)),
23+
'componentModule': _.camelCase(componentName)
24+
};
25+
26+
// if (this.options.r) {
27+
//
28+
// if (pathAsArray.length === 1) {
29+
// try {
30+
// const indexModulesRemoveLine = "require('./components/" + data.componentName + "/" + data.componentName + ".module').name,";
31+
// utils.removeLineFromFile('index.components.js', indexModulesRemoveLine, this.destinationRoot() + '/src/app')
32+
// utils.deleteDirRecursive(this.destinationRoot() + '/src/app/components/' + data.componentName);
33+
// } catch (err) {}
34+
// }else{
35+
// parentName = pathAsArray[pathAsArray.length - 2];
36+
//
37+
// // //module
38+
// // const moduleImportRemoveLine = "import * as " + data.componentModule + " from './components/" + componentName + '/' + componentName + ".module';";
39+
// // utils.addToFile(parentName + '.module.js', moduleImport, utils.IMPORT_MODULE_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
40+
// // //dependency
41+
// // const dependencyImport = "'" + data.componentModule + "',";
42+
// // utils.addToFile(parentName + '.module.js', dependencyImport, utils.IMPORT_DEPENDENCY_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
43+
//
44+
// }
45+
// return;
46+
// }
5147

52-
// checking if the module exists, if so it is a duplicate
53-
isDuplicate = utils.existsSync(this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.module.js'));
48+
//if the component has no parent
49+
if (pathAsArray.length === 1) {
50+
try {
51+
const indexModulesWriteLine = "require('./components/" + data.componentName + "/" + data.componentName + ".module').name,";
52+
utils.addToFile('index.components.js', indexModulesWriteLine, utils.COMPONENT_MARKER, this.destinationRoot() + '/src/app');
53+
} catch (err) {
54+
this.log('Could not generate this item due to missing file structure.');
55+
return;
56+
}
57+
} else {
58+
//if the component is nested in a parent component
59+
parentName = pathAsArray[pathAsArray.length - 2];
60+
// if single parent, join by '/' else join by '/components/' to nest within the parent components
61+
const joinString = (pathAsArray.length > 2)
62+
? '/components/'
63+
: '/';
64+
parentPath = _.join(pathAsArray.slice(0, pathAsArray.length - 1), joinString);
65+
fullPath = parentPath + '/components/' + data.componentName;
66+
// importing files to parent component
67+
try {
68+
//module
69+
const moduleImport = "import * as " + data.componentModule + " from './components/" + componentName + '/' + componentName + ".module';";
70+
utils.addToFile(parentName + '.module.js', moduleImport, utils.IMPORT_MODULE_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
71+
//dependency
72+
const dependencyImport = "'" + data.componentModule + "',";
73+
utils.addToFile(parentName + '.module.js', dependencyImport, utils.IMPORT_DEPENDENCY_MARKER, this.destinationRoot() + '/src/app/components/' + parentPath);
74+
} catch (err) {
75+
this.log('Parent component files not found.');
76+
return;
77+
}
78+
}
5479

55-
// copy template files, no need for try and catch since file structure already exists from above
56-
this.fs.copyTpl(this.templatePath('_component.html'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component.html'), data);
57-
this.fs.copyTpl(this.templatePath('_component.scss'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component.scss'), data);
58-
this.fs.copyTpl(this.templatePath('_component.module.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.module.js'), data);
59-
this.fs.copyTpl(this.templatePath('_component.component.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component' + '.js'), data);
60-
this.fs.copyTpl(this.templatePath('_component.component-spec.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component-spec' + '.js'), data);
80+
// checking if the module exists, if so it is a duplicate
81+
isDuplicate = utils.existsSync(this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.module.js'));
6182

62-
// Documenting the creation of the component
63-
if(!isDuplicate){
64-
try{
65-
const nestedLineMarkExtensionForDocs = " for "+fullPath;
66-
const descriptionForDocs = (this.props.description && this.props.description.length>0)?this.props.description:data.componentName + " component";
67-
const componentDocJSONString = '{\n\t\t"name": "' + data.componentName + '", "path": "' + this.props.componentName + '",\n\t\t"components": [\n\t\t\t'+utils.COMPONENT_NESTED_MARKER+nestedLineMarkExtensionForDocs+'\n\t\t],\n\t\t"directives": [\n\t\t\t'+utils.DIRECTIVE_NESTED_MARKER+nestedLineMarkExtensionForDocs+'\n\t\t],\n\t\t"services": [\n\t\t\t'+utils.SERVICE_NESTED_MARKER+nestedLineMarkExtensionForDocs+'\n\t\t],\n\t\t"description": "'+ descriptionForDocs + ' component"\n\t\t},'
68-
// extending the nested Line marker with information about the component in order to insert there later
69-
utils.addToFile(utils.DOCS_STORAGE_FILENAME, componentDocJSONString, utils.COMPONENT_MARKER, this.destinationRoot() + utils.DOCS_ASSETS_PATH);
70-
// if the component has a parent, Link it to its parent
71-
if (pathAsArray.length !== 1) {
72-
const nestedLineMarkExtensionOfParent = " for "+parentPath;
73-
// Foreign Key String for component is injected into the parent component
74-
const componentDocForeignKeyJSONString = '{"path": "' + this.props.componentName + '", "name": "' + data.componentName + '"},';
75-
utils.addToFile(utils.DOCS_STORAGE_FILENAME, componentDocForeignKeyJSONString, utils.COMPONENT_NESTED_MARKER+nestedLineMarkExtensionOfParent, this.destinationRoot() + utils.DOCS_ASSETS_PATH);
76-
}
77-
} catch (err) {
78-
this.log('Could not document this item due to missing documentation file.');
79-
}
83+
// copy template files, no need for try and catch since file structure already exists from above
84+
this.fs.copyTpl(this.templatePath('_component.html'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component.html'), data);
85+
this.fs.copyTpl(this.templatePath('_component.scss'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component.scss'), data);
86+
this.fs.copyTpl(this.templatePath('_component.module.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.module.js'), data);
87+
this.fs.copyTpl(this.templatePath('_component.component.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component' + '.js'), data);
88+
this.fs.copyTpl(this.templatePath('_component.component-spec.js'), this.destinationPath(this.destinationRoot() + '/src/app/components/' + fullPath + '/' + data.componentName + '.component-spec' + '.js'), data);
89+
90+
// Documenting the creation of the component
91+
if (!isDuplicate) {
92+
const file = this.destinationPath(this.destinationRoot() + utils.DOCS_ASSETS_PATH+'/'+utils.DOCS_STORAGE_FILENAME);
93+
jsonfile.readFile(file, function(err, docsJSON) {
94+
if (err) {
95+
this.log('Could not document this item due to missing or corrupted documentation file.');
96+
return;
8097
}
81-
};
98+
const descriptionForDocs = (this.props.description && this.props.description.length > 0)
99+
? this.props.description
100+
: data.componentName + " component";
101+
const componentDocJSON = {
102+
"name": data.componentName,
103+
"path": this.props.componentName,
104+
"components": [],
105+
"directives": [],
106+
"services": [],
107+
"description": descriptionForDocs
108+
};
109+
docsJSON.components.push(componentDocJSON);
110+
if (pathAsArray.length !== 1) {
111+
// Foreign Key String for component is injected into the parent component
112+
const componentDocForeignKeyJSON = {
113+
"path": this.props.componentName,
114+
"name": data.componentName
115+
};
116+
docsJSON.components[jsonQuery('components[path=' + pathAsArray.slice(0, -1).join('/') + ']', {data: docsJSON}).key].components.push(componentDocForeignKeyJSON);
117+
}
118+
jsonfile.writeFile(file, docsJSON, function(err) {}.bind(this));
119+
}.bind(this));
120+
}
121+
};
82122
};

0 commit comments

Comments
 (0)