spyne-cli 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -1
- package/package.json +5 -4
- package/src/app/channels/channel-custom.js +1 -0
- package/src/app/components/my-ui-el-view.js +25 -0
- package/src/app/components/sdafsdfaa.js +25 -0
- package/src/hello-world-app-source/README.md +15 -0
- package/src/hello-world-app-source/apache-htaccess +20 -0
- package/src/hello-world-app-source/karma.conf.js +75 -0
- package/src/hello-world-app-source/package.json +50 -0
- package/src/hello-world-app-source/src/app/app-view.js +38 -0
- package/src/hello-world-app-source/src/app/channels/.gitkeep +0 -0
- package/src/hello-world-app-source/src/app/components/.gitkeep +0 -0
- package/src/hello-world-app-source/src/app/traits/.gitkeep +0 -0
- package/src/hello-world-app-source/src/index.js +16 -0
- package/src/hello-world-app-source/src/index.tmpl.html +12 -0
- package/src/hello-world-app-source/src/scss/01-vendors/normalize.css +349 -0
- package/src/hello-world-app-source/src/scss/02-variables/mixins.scss +0 -0
- package/src/hello-world-app-source/src/scss/03-components/.gitkeep +0 -0
- package/src/hello-world-app-source/src/scss/main.scss +15 -0
- package/src/hello-world-app-source/src/static/data/.gitkeep +0 -0
- package/src/hello-world-app-source/src/static/fonts/.gitkeep +0 -0
- package/src/hello-world-app-source/src/static/imgs/.gitkeep +0 -0
- package/src/hello-world-app-source/src/tests/unit-tests/index.test.js +10 -0
- package/src/hello-world-app-source/webpack.config.js +178 -0
- package/src/spyne-app-creator.js +119 -0
- package/src/utils/file-utils.js +120 -1
- package/tests/create-spyne-app.test.js +64 -0
- package/tests/utils/file-utils.test.js +17 -1
- package/index-cli.js +0 -56
package/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {SpyneCliUI} from './src/ui.js';
|
|
3
3
|
import clear from 'clear';
|
|
4
|
+
import SpyneAppCreator from './src/spyne-app-creator.js';
|
|
4
5
|
import SpyneFilePrompt from './src/spyne-file-prompt.js';
|
|
6
|
+
const args = process.argv;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let spyneAppCreator = new SpyneAppCreator(args);
|
|
10
|
+
const {createAppBool} = spyneAppCreator;
|
|
5
11
|
|
|
6
12
|
const startPromptFn = async()=>{
|
|
7
13
|
clear();
|
|
@@ -10,5 +16,9 @@ const startPromptFn = async()=>{
|
|
|
10
16
|
await spyneFilePrompt.startPrompt();
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
if (createAppBool){
|
|
20
|
+
spyneAppCreator.generateResponse();
|
|
21
|
+
} else {
|
|
22
|
+
startPromptFn();
|
|
23
|
+
}
|
|
14
24
|
|
package/package.json
CHANGED
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
"spyne-cli": "index.js"
|
|
5
5
|
},
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.4.0",
|
|
8
8
|
"description": "Generates spyne objects and saves them to standard spyne.",
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"debug": "nodemon --no-stdin index.js",
|
|
12
|
-
"resetApp": "node ./index-cli resetAppDir",
|
|
13
|
-
"resetAll": "npm run resetApp && clear && npm start",
|
|
14
12
|
"start": "node index.js",
|
|
15
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
14
|
},
|
|
@@ -32,7 +30,10 @@
|
|
|
32
30
|
"clear": "^0.1.0",
|
|
33
31
|
"enquirer": "^2.3.6",
|
|
34
32
|
"figlet": "^1.5.2",
|
|
35
|
-
"json-stringify-safe": "^5.0.1"
|
|
33
|
+
"json-stringify-safe": "^5.0.1",
|
|
34
|
+
"pkg-dir": "^6.0.1",
|
|
35
|
+
"pkg-up": "^4.0.0",
|
|
36
|
+
"read-pkg": "^7.0.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"chai": "^4.3.4",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Some content for tests/utils/file-utils-test -- should test saving to file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {ViewStream} from 'spyne';
|
|
2
|
+
|
|
3
|
+
export class MyUiElView extends ViewStream {
|
|
4
|
+
|
|
5
|
+
constructor(props={}) {
|
|
6
|
+
|
|
7
|
+
super(props);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
addActionListeners() {
|
|
11
|
+
// return nexted array(s)
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
broadcastEvents() {
|
|
16
|
+
// return nexted array(s)
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
onRendered() {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {ViewStream} from 'spyne';
|
|
2
|
+
|
|
3
|
+
export class Sdafsdfaa extends ViewStream {
|
|
4
|
+
|
|
5
|
+
constructor(props={}) {
|
|
6
|
+
|
|
7
|
+
super(props);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
addActionListeners() {
|
|
11
|
+
// return nexted array(s)
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
broadcastEvents() {
|
|
16
|
+
// return nexted array(s)
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
onRendered() {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## Spynejs Hello World Application
|
|
2
|
+
barebones app preconfigured for building, testing and adding content using the spyne-cli tool
|
|
3
|
+
|
|
4
|
+
App includes
|
|
5
|
+
* AppView
|
|
6
|
+
* Application Folder Structure
|
|
7
|
+
* Build, production setup using webpack and sass
|
|
8
|
+
* Spyne Console plugin
|
|
9
|
+
* Unit testing
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm run init or npm install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Build better web experiences, faster
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# html5 pushstate (history) support:
|
|
2
|
+
<ifModule mod_rewrite.c>
|
|
3
|
+
RewriteEngine On
|
|
4
|
+
|
|
5
|
+
# the final correct redirect
|
|
6
|
+
RewriteEngine on
|
|
7
|
+
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
|
|
8
|
+
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
|
12
|
+
RewriteCond %{REQUEST_FILENAME} !-d
|
|
13
|
+
RewriteCond %{REQUEST_URI} !index
|
|
14
|
+
RewriteRule (.*) index.html [L,QSA]
|
|
15
|
+
</ifModule>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<IfModule mod_headers.c>
|
|
19
|
+
Header add Access-Control-Allow-Origin: *
|
|
20
|
+
</IfModule>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const webpackConfigFn = require('./webpack.config');
|
|
2
|
+
const webpackConfig = webpackConfigFn();
|
|
3
|
+
|
|
4
|
+
webpackConfig.entry = undefined;
|
|
5
|
+
webpackConfig.output = undefined;
|
|
6
|
+
webpackConfig.stats = "normal";
|
|
7
|
+
webpackConfig.watch = true;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module.exports = function(config) {
|
|
11
|
+
config.set({
|
|
12
|
+
|
|
13
|
+
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|
14
|
+
basePath: '',
|
|
15
|
+
|
|
16
|
+
// frameworks to use
|
|
17
|
+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|
18
|
+
frameworks: ['webpack', 'mocha', 'chai'],
|
|
19
|
+
|
|
20
|
+
// list of files / patterns to load in the browser
|
|
21
|
+
files: [
|
|
22
|
+
|
|
23
|
+
{ pattern: './node_modules/ramda/dist/ramda.min.js', watched: false},
|
|
24
|
+
{ pattern: './node_modules/rxjs/**/*.js', included:false, watched: false},
|
|
25
|
+
{ pattern: './src/tests/unit-tests/**/*.test.js', watched: true}
|
|
26
|
+
|
|
27
|
+
],
|
|
28
|
+
|
|
29
|
+
// list of files / patterns to exclude
|
|
30
|
+
exclude: [],
|
|
31
|
+
|
|
32
|
+
// preprocess matching files before serving them to the browser
|
|
33
|
+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|
34
|
+
preprocessors: {
|
|
35
|
+
'./src/tests/unit-tests/**/*.test.js': ['webpack']
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
webpack: webpackConfig,
|
|
39
|
+
webpackMiddleware: {noInfo:true},
|
|
40
|
+
|
|
41
|
+
// test results reporter to use
|
|
42
|
+
// possible values: 'dots', 'progress'
|
|
43
|
+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|
44
|
+
reporters: ['progress'],
|
|
45
|
+
|
|
46
|
+
// web server port
|
|
47
|
+
port: 9876,
|
|
48
|
+
|
|
49
|
+
// enable / disable colors in the output (reporters and logs)
|
|
50
|
+
colors: true,
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// level of logging
|
|
54
|
+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|
55
|
+
logLevel: config.LOG_INFO,
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// enable / disable watching file and executing tests whenever any file changes
|
|
59
|
+
autoWatch: true,
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// start these browsers
|
|
63
|
+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|
64
|
+
browsers: ['Chrome'],
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// Continuous Integration mode
|
|
68
|
+
// if true, Karma captures browsers, runs the tests and exits
|
|
69
|
+
singleRun: true,
|
|
70
|
+
|
|
71
|
+
// Concurrency level
|
|
72
|
+
// how many browser should be started simultaneous
|
|
73
|
+
concurrency: Infinity
|
|
74
|
+
})
|
|
75
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spyne-hello-world-app",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Bare bones spyne application.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"init": "npm install && npm i -D mocha-loader --force",
|
|
8
|
+
"start": "webpack serve --open",
|
|
9
|
+
"build": "webpack --mode production --env build",
|
|
10
|
+
"build:apache": "buildType=apache webpack --mode production --env build",
|
|
11
|
+
"test": "karma start"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"spyne": "^0.18.3",
|
|
15
|
+
"spyne-plugin-console": "^0.3.3"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"chai": "^4.3.4",
|
|
19
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
20
|
+
"copy-webpack-plugin": "^10.2.0",
|
|
21
|
+
"css-loader": "^6.5.1",
|
|
22
|
+
"eslint": "^8.6.0",
|
|
23
|
+
"file-loader": "^6.2.0",
|
|
24
|
+
"html-loader": "^3.1.0",
|
|
25
|
+
"html-webpack-plugin": "^5.5.0",
|
|
26
|
+
"karma": "^6.3.10",
|
|
27
|
+
"karma-chai": "^0.1.0",
|
|
28
|
+
"karma-chrome-launcher": "^3.1.0",
|
|
29
|
+
"karma-coverage": "^2.1.0",
|
|
30
|
+
"karma-mocha": "^2.0.1",
|
|
31
|
+
"karma-webpack": "^5.0.0",
|
|
32
|
+
"mini-css-extract-plugin": "^2.4.6",
|
|
33
|
+
"mocha-loader": "^5.1.5",
|
|
34
|
+
"requirejs": "^2.3.6",
|
|
35
|
+
"resolve-url-loader": "^4.0.0",
|
|
36
|
+
"sass": "^1.47.0",
|
|
37
|
+
"sass-loader": "^12.4.0",
|
|
38
|
+
"style-loader": "^3.3.1",
|
|
39
|
+
"webpack": "^5.65.0",
|
|
40
|
+
"webpack-cli": "^4.9.1",
|
|
41
|
+
"webpack-dev-server": "^4.7.2"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": ""
|
|
46
|
+
},
|
|
47
|
+
"author": "",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"homepage": ""
|
|
50
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {ViewStream} from 'spyne';
|
|
2
|
+
|
|
3
|
+
export class AppView extends ViewStream {
|
|
4
|
+
|
|
5
|
+
constructor(props = {}) {
|
|
6
|
+
props.tagName='main';
|
|
7
|
+
props.id='app-main';
|
|
8
|
+
props.class='main';
|
|
9
|
+
super(props);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
addActionListeners() {
|
|
13
|
+
// return nexted array(s)
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
broadcastEvents() {
|
|
19
|
+
// return nexted array(s)
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addHelloWorld(e){
|
|
24
|
+
const helloWorldView = new ViewStream({
|
|
25
|
+
tagName: 'h2',
|
|
26
|
+
"style": "color:#1F2933; padding: 2rem; font-family:sans-serif;",
|
|
27
|
+
data: "Hello World"
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.appendView(helloWorldView);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
onRendered() {
|
|
35
|
+
this.addHelloWorld();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import'./scss/main.scss';
|
|
2
|
+
import {SpyneApp} from 'spyne';
|
|
3
|
+
import {AppView} from './app/app-view';
|
|
4
|
+
|
|
5
|
+
const config = {
|
|
6
|
+
debug:true
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
SpyneApp.init(config);
|
|
10
|
+
|
|
11
|
+
if (process.env.NODE_ENV === 'development') {
|
|
12
|
+
const {SpynePluginConsole} = require('spyne-plugin-console');
|
|
13
|
+
new SpynePluginConsole({position: ['bottom', 'right'], minimize: true});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
new AppView().prependToDom(document.body);
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
|
|
2
|
+
|
|
3
|
+
/* Document
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 1. Correct the line height in all browsers.
|
|
8
|
+
* 2. Prevent adjustments of font size after orientation changes in iOS.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
html {
|
|
12
|
+
line-height: 1.15; /* 1 */
|
|
13
|
+
-webkit-text-size-adjust: 100%; /* 2 */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Sections
|
|
17
|
+
========================================================================== */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Remove the margin in all browsers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Render the `main` element consistently in IE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
main {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Correct the font size and margin on `h1` elements within `section` and
|
|
37
|
+
* `article` contexts in Chrome, Firefox, and Safari.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
h1 {
|
|
41
|
+
font-size: 2em;
|
|
42
|
+
margin: 0.67em 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Grouping content
|
|
46
|
+
========================================================================== */
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 1. Add the correct box sizing in Firefox.
|
|
50
|
+
* 2. Show the overflow in Edge and IE.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
hr {
|
|
54
|
+
box-sizing: content-box; /* 1 */
|
|
55
|
+
height: 0; /* 1 */
|
|
56
|
+
overflow: visible; /* 2 */
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
61
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
pre {
|
|
65
|
+
font-family: monospace, monospace; /* 1 */
|
|
66
|
+
font-size: 1em; /* 2 */
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Text-level semantics
|
|
70
|
+
========================================================================== */
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Remove the gray background on active links in IE 10.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
a {
|
|
77
|
+
background-color: transparent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 1. Remove the bottom border in Chrome 57-
|
|
82
|
+
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
abbr[title] {
|
|
86
|
+
border-bottom: none; /* 1 */
|
|
87
|
+
text-decoration: underline; /* 2 */
|
|
88
|
+
text-decoration: underline dotted; /* 2 */
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add the correct font weight in Chrome, Edge, and Safari.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
b,
|
|
96
|
+
strong {
|
|
97
|
+
font-weight: bolder;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
102
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
code,
|
|
106
|
+
kbd,
|
|
107
|
+
samp {
|
|
108
|
+
font-family: monospace, monospace; /* 1 */
|
|
109
|
+
font-size: 1em; /* 2 */
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Add the correct font size in all browsers.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
small {
|
|
117
|
+
font-size: 80%;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Prevent `sub` and `sup` elements from affecting the line height in
|
|
122
|
+
* all browsers.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
sub,
|
|
126
|
+
sup {
|
|
127
|
+
font-size: 75%;
|
|
128
|
+
line-height: 0;
|
|
129
|
+
position: relative;
|
|
130
|
+
vertical-align: baseline;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
sub {
|
|
134
|
+
bottom: -0.25em;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sup {
|
|
138
|
+
top: -0.5em;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* Embedded content
|
|
142
|
+
========================================================================== */
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Remove the border on images inside links in IE 10.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
img {
|
|
149
|
+
border-style: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* Forms
|
|
153
|
+
========================================================================== */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 1. Change the font styles in all browsers.
|
|
157
|
+
* 2. Remove the margin in Firefox and Safari.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
button,
|
|
161
|
+
input,
|
|
162
|
+
optgroup,
|
|
163
|
+
select,
|
|
164
|
+
textarea {
|
|
165
|
+
font-family: inherit; /* 1 */
|
|
166
|
+
font-size: 100%; /* 1 */
|
|
167
|
+
line-height: 1.15; /* 1 */
|
|
168
|
+
margin: 0; /* 2 */
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Show the overflow in IE.
|
|
173
|
+
* 1. Show the overflow in Edge.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
button,
|
|
177
|
+
input { /* 1 */
|
|
178
|
+
overflow: visible;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Remove the inheritance of text transform in Edge, Firefox, and IE.
|
|
183
|
+
* 1. Remove the inheritance of text transform in Firefox.
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
button,
|
|
187
|
+
select { /* 1 */
|
|
188
|
+
text-transform: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Correct the inability to style clickable types in iOS and Safari.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
button,
|
|
196
|
+
[type="button"],
|
|
197
|
+
[type="reset"],
|
|
198
|
+
[type="submit"] {
|
|
199
|
+
-webkit-appearance: button;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Remove the inner border and padding in Firefox.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
button::-moz-focus-inner,
|
|
207
|
+
[type="button"]::-moz-focus-inner,
|
|
208
|
+
[type="reset"]::-moz-focus-inner,
|
|
209
|
+
[type="submit"]::-moz-focus-inner {
|
|
210
|
+
border-style: none;
|
|
211
|
+
padding: 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Restore the focus styles unset by the previous rule.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
button:-moz-focusring,
|
|
219
|
+
[type="button"]:-moz-focusring,
|
|
220
|
+
[type="reset"]:-moz-focusring,
|
|
221
|
+
[type="submit"]:-moz-focusring {
|
|
222
|
+
outline: 1px dotted ButtonText;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Correct the padding in Firefox.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
fieldset {
|
|
230
|
+
padding: 0.35em 0.75em 0.625em;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 1. Correct the text wrapping in Edge and IE.
|
|
235
|
+
* 2. Correct the color inheritance from `fieldset` elements in IE.
|
|
236
|
+
* 3. Remove the padding so developers are not caught out when they zero out
|
|
237
|
+
* `fieldset` elements in all browsers.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
legend {
|
|
241
|
+
box-sizing: border-box; /* 1 */
|
|
242
|
+
color: inherit; /* 2 */
|
|
243
|
+
display: table; /* 1 */
|
|
244
|
+
max-width: 100%; /* 1 */
|
|
245
|
+
padding: 0; /* 3 */
|
|
246
|
+
white-space: normal; /* 1 */
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
progress {
|
|
254
|
+
vertical-align: baseline;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Remove the default vertical scrollbar in IE 10+.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
textarea {
|
|
262
|
+
overflow: auto;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 1. Add the correct box sizing in IE 10.
|
|
267
|
+
* 2. Remove the padding in IE 10.
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
[type="checkbox"],
|
|
271
|
+
[type="radio"] {
|
|
272
|
+
box-sizing: border-box; /* 1 */
|
|
273
|
+
padding: 0; /* 2 */
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Correct the cursor style of increment and decrement buttons in Chrome.
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
[type="number"]::-webkit-inner-spin-button,
|
|
281
|
+
[type="number"]::-webkit-outer-spin-button {
|
|
282
|
+
height: auto;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 1. Correct the odd appearance in Chrome and Safari.
|
|
287
|
+
* 2. Correct the outline style in Safari.
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
[type="search"] {
|
|
291
|
+
-webkit-appearance: textfield; /* 1 */
|
|
292
|
+
outline-offset: -2px; /* 2 */
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Remove the inner padding in Chrome and Safari on macOS.
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
[type="search"]::-webkit-search-decoration {
|
|
300
|
+
-webkit-appearance: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 1. Correct the inability to style clickable types in iOS and Safari.
|
|
305
|
+
* 2. Change font properties to `inherit` in Safari.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
::-webkit-file-upload-button {
|
|
309
|
+
-webkit-appearance: button; /* 1 */
|
|
310
|
+
font: inherit; /* 2 */
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* Interactive
|
|
314
|
+
========================================================================== */
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
* Add the correct display in Edge, IE 10+, and Firefox.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
details {
|
|
321
|
+
display: block;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/*
|
|
325
|
+
* Add the correct display in all browsers.
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
summary {
|
|
329
|
+
display: list-item;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Misc
|
|
333
|
+
========================================================================== */
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Add the correct display in IE 10+.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
template {
|
|
340
|
+
display: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Add the correct display in IE 10.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
[hidden] {
|
|
348
|
+
display: none;
|
|
349
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@import "01-vendors/normalize.css";
|
|
2
|
+
@import "02-variables/mixins.scss";
|
|
3
|
+
|
|
4
|
+
body {
|
|
5
|
+
font-family: sans-serif;
|
|
6
|
+
background: #CBD2D9;
|
|
7
|
+
display: flex;
|
|
8
|
+
position: relative;
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
|
|
15
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const {expect, assert} = require('chai');
|
|
2
|
+
const {SpyneApp, SpyneAppProperties} = require('spyne');
|
|
3
|
+
|
|
4
|
+
describe('should initialize spyne', () => {
|
|
5
|
+
it('should be show that spyne has initialized', () => {
|
|
6
|
+
SpyneApp.init();
|
|
7
|
+
expect(SpyneAppProperties.initialized).to.be.true;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const webpack = require('webpack');
|
|
3
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
4
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
5
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
6
|
+
|
|
7
|
+
const _defaultAssetsDirName = "assets";
|
|
8
|
+
const port = 8062;
|
|
9
|
+
|
|
10
|
+
let mode;
|
|
11
|
+
let _isProduction;
|
|
12
|
+
let _buildType;
|
|
13
|
+
|
|
14
|
+
// USE "/./" FOR ROOT DOMAIN OR "./" FOR RELATIVE DOMAIN PATHS"
|
|
15
|
+
let _relativeRoot = "./"
|
|
16
|
+
let _publicPath;
|
|
17
|
+
let _assetsFolder;
|
|
18
|
+
let _imgPath;
|
|
19
|
+
|
|
20
|
+
module.exports = (env={mode:"development"})=> {
|
|
21
|
+
|
|
22
|
+
mode = env.mode || 'development';
|
|
23
|
+
_isProduction = env.build === true;
|
|
24
|
+
_buildType = process.env.buildType;
|
|
25
|
+
_publicPath = _isProduction ? _relativeRoot : "/";
|
|
26
|
+
_assetsFolder = _isProduction ? `${_defaultAssetsDirName}/` : "";
|
|
27
|
+
_imgPath = `${_publicPath}${_assetsFolder}static/imgs/`;
|
|
28
|
+
|
|
29
|
+
const config = {
|
|
30
|
+
mode,
|
|
31
|
+
|
|
32
|
+
entry: {
|
|
33
|
+
index: './src/index.js'
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
output: {
|
|
37
|
+
filename: `${_assetsFolder}js/[name].js`,
|
|
38
|
+
publicPath: _publicPath,
|
|
39
|
+
clean: true
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
devtool: _isProduction ? false : 'inline-cheap-source-map',
|
|
43
|
+
|
|
44
|
+
devServer: {
|
|
45
|
+
static: {
|
|
46
|
+
directory: 'src',
|
|
47
|
+
},
|
|
48
|
+
historyApiFallback: true,
|
|
49
|
+
port
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
plugins: getWebpackPlugins(),
|
|
53
|
+
|
|
54
|
+
optimization: {
|
|
55
|
+
splitChunks: {
|
|
56
|
+
cacheGroups: {
|
|
57
|
+
common: {
|
|
58
|
+
test: /[\\/]node_modules[\\/]/,
|
|
59
|
+
name: "vendor",
|
|
60
|
+
chunks: 'all',
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
module: {
|
|
67
|
+
rules: [
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
test: /\.html$/,
|
|
71
|
+
loader: "html-loader",
|
|
72
|
+
options: {
|
|
73
|
+
minimize: false,
|
|
74
|
+
esModule: false,
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
test: /\.(sa|sc|c)ss$/,
|
|
80
|
+
use: [
|
|
81
|
+
_isProduction !== true ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
82
|
+
'css-loader',
|
|
83
|
+
{
|
|
84
|
+
loader: 'sass-loader', options: {
|
|
85
|
+
sourceMap: true
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
{
|
|
92
|
+
test: /\.(ttf|woff|woff2)$/,
|
|
93
|
+
type: 'asset/resource',
|
|
94
|
+
generator: {
|
|
95
|
+
filename: `${_assetsFolder}static/fonts/[name][ext][query]`
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
101
|
+
type: "asset"
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
test: /\.(json)$/,
|
|
106
|
+
type: 'javascript/auto',
|
|
107
|
+
use: [
|
|
108
|
+
{
|
|
109
|
+
loader: 'file-loader',
|
|
110
|
+
options: {
|
|
111
|
+
name: `${_assetsFolder}static/data/[name].[ext]`
|
|
112
|
+
},
|
|
113
|
+
}]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
resolve: {
|
|
120
|
+
alias: {
|
|
121
|
+
plugins: path.resolve(__dirname, 'src/plugins/'),
|
|
122
|
+
imgs: path.resolve(__dirname, 'src/static/imgs/'),
|
|
123
|
+
fonts: path.resolve(__dirname, 'src/static/fonts/'),
|
|
124
|
+
data: path.resolve(__dirname, '/./src/static/data/'),
|
|
125
|
+
css: path.resolve(__dirname, 'src/css/'),
|
|
126
|
+
core: path.resolve(__dirname, 'src/core/'),
|
|
127
|
+
traits: path.resolve(__dirname, 'src/app/traits/'),
|
|
128
|
+
channels: path.resolve(__dirname, 'src/app/channels/'),
|
|
129
|
+
components: path.resolve(__dirname, 'src/app/components/'),
|
|
130
|
+
node_modules: path.resolve(__dirname, 'node_modules/')
|
|
131
|
+
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
extensions: ['.js', '.css'],
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return config;
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
const getWebpackPlugins = ()=> {
|
|
144
|
+
|
|
145
|
+
const miniCssPlugin = ()=> {
|
|
146
|
+
return new MiniCssExtractPlugin({
|
|
147
|
+
filename: `${_assetsFolder}/css/main.css`
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const definePlugin = new webpack.DefinePlugin({
|
|
152
|
+
"IMG_PATH": JSON.stringify(_imgPath),
|
|
153
|
+
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const htmlPlugin = new HtmlWebpackPlugin({
|
|
157
|
+
template: './src/index.tmpl.html',
|
|
158
|
+
minify: false
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const getCopyPatternsPlugin = () => {
|
|
162
|
+
const patterns = [
|
|
163
|
+
{from: "./src/static/imgs", to: `${_assetsFolder}static/imgs`}
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
if (_buildType === 'apache') {
|
|
167
|
+
patterns.push(
|
|
168
|
+
{from: "./apache-htaccess", to: ".htaccess", toType: "file"})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return new CopyWebpackPlugin({patterns})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return _isProduction ?
|
|
175
|
+
[htmlPlugin, definePlugin, miniCssPlugin, getCopyPatternsPlugin()] :
|
|
176
|
+
[htmlPlugin, definePlugin];
|
|
177
|
+
|
|
178
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import c from 'ansi-colors';
|
|
3
|
+
import {checkIfFolderExists, copyDirSync} from './utils/file-utils.js';
|
|
4
|
+
|
|
5
|
+
let _createAppBool = false;
|
|
6
|
+
let _folderName;
|
|
7
|
+
let _folderPath = path.resolve();
|
|
8
|
+
let _appDirectory;
|
|
9
|
+
let _errorMsg;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import {packageDirectory} from 'pkg-dir';
|
|
15
|
+
const globalPath = "/usr/local/lib/node_modules/spyne-cli"
|
|
16
|
+
const _spyneAppSrcRelPath = '/src/hello-world-app-source';
|
|
17
|
+
let _spyneAppSrcPath = path.resolve(globalPath, _spyneAppSrcRelPath);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const getSpyneSrcPath = async()=> {
|
|
21
|
+
const localPath = await packageDirectory();
|
|
22
|
+
const mainPath = localPath || globalPath;
|
|
23
|
+
_spyneAppSrcPath = path.resolve(mainPath, 'src/hello-world-app-source');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export default class SpyneAppCreator {
|
|
28
|
+
|
|
29
|
+
constructor(args=[]) {
|
|
30
|
+
|
|
31
|
+
let {createAppBool, folderName} = SpyneAppCreator.checkArgs(args);
|
|
32
|
+
|
|
33
|
+
_createAppBool = createAppBool;
|
|
34
|
+
_folderName = folderName;
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
this.checkForErrors = SpyneAppCreator.checkForErrors.bind(this);
|
|
38
|
+
this.generateResponse = SpyneAppCreator.generateResponse.bind(this);
|
|
39
|
+
this.copyDirAndReturnResponse = SpyneAppCreator.copyDirAndReturnResponse.bind(this);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
static async generateResponse(){
|
|
46
|
+
try{
|
|
47
|
+
await getSpyneSrcPath();
|
|
48
|
+
} catch(e){
|
|
49
|
+
console.log('getting src path err ',e);
|
|
50
|
+
}
|
|
51
|
+
_errorMsg = this.checkForErrors();
|
|
52
|
+
return _errorMsg ? console.log(_errorMsg) : this.copyDirAndReturnResponse();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
static copyDirAndReturnResponse(appDir=_appDirectory){
|
|
58
|
+
copyDirSync(_spyneAppSrcPath, appDir);
|
|
59
|
+
console.log(SpyneAppCreator.successColors(`spyne at created at ${appDir}`));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
static successColors(successStr="XXXX"){
|
|
64
|
+
return c.blueBright(successStr);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static errorColors(errorStr="XXXX"){
|
|
68
|
+
return c.greenBright(errorStr);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static checkForErrors(folderPath=_folderPath, folderName=_folderName){
|
|
72
|
+
|
|
73
|
+
let folderNameIsMissing = folderName === undefined;
|
|
74
|
+
|
|
75
|
+
if (folderNameIsMissing){
|
|
76
|
+
return SpyneAppCreator.errorColors("Please add a folder name!");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_appDirectory = `${folderPath}/${folderName}`;
|
|
80
|
+
|
|
81
|
+
let pathAlreadyExistsBool = SpyneAppCreator.checkIfDirectoryExists(_appDirectory);
|
|
82
|
+
|
|
83
|
+
if (pathAlreadyExistsBool){
|
|
84
|
+
return SpyneAppCreator.errorColors('App folder already exists!');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return undefined;
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static checkIfDirectoryExists(appDir=""){
|
|
92
|
+
return checkIfFolderExists(appDir);;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
static checkArgs(args){
|
|
98
|
+
const methodStr = args.length>=3 ? args[2] : false;
|
|
99
|
+
const folderName = args.length>=4 ? args[3] : undefined;
|
|
100
|
+
const createAppBool = methodStr === "create-app";
|
|
101
|
+
|
|
102
|
+
return {folderName, createAppBool};
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get createAppBool(){
|
|
107
|
+
return _createAppBool;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get folderName(){
|
|
111
|
+
return _folderName;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get folderPath(){
|
|
115
|
+
return _folderPath;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
}
|
package/src/utils/file-utils.js
CHANGED
|
@@ -11,6 +11,16 @@ import R from 'ramda';;
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
const checkIfFileExists = (fileLoc) => fs.existsSync(fileLoc)
|
|
14
|
+
const checkIfFolderExists = (dir) => {
|
|
15
|
+
try {
|
|
16
|
+
if (fs.existsSync(dir)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
} catch(e) {
|
|
20
|
+
console.log("An checkIfFolderExists error occurred.")
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
14
24
|
|
|
15
25
|
|
|
16
26
|
const onSaveSpyneFileToDir = (fileStr, fileName, fileDirectory) =>{
|
|
@@ -66,4 +76,113 @@ const validateFileDirectory = (value)=>{
|
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
|
|
69
|
-
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function copyDirSync(src, dest, options={}) {
|
|
83
|
+
var srcPath = path.resolve(src);
|
|
84
|
+
var destPath = path.resolve(dest);
|
|
85
|
+
if(path.relative(srcPath, destPath).charAt(0) != ".") {
|
|
86
|
+
console.warn("dest path must be out of src path");
|
|
87
|
+
}
|
|
88
|
+
var settings = Object.assign(Object.create(copyDirSync.options), options);
|
|
89
|
+
copyDirSync0(srcPath, destPath, settings);
|
|
90
|
+
function copyDirSync0(srcPath, destPath, settings) {
|
|
91
|
+
var files = fs.readdirSync(srcPath);
|
|
92
|
+
if (!fs.existsSync(destPath)) {
|
|
93
|
+
fs.mkdirSync(destPath);
|
|
94
|
+
}else if(!fs.lstatSync(destPath).isDirectory()) {
|
|
95
|
+
if(settings.overwrite)
|
|
96
|
+
throw new Error(`Cannot overwrite non-directory '${destPath}' with directory '${srcPath}'.`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
files.forEach(function(filename) {
|
|
100
|
+
var childSrcPath = path.join(srcPath, filename);
|
|
101
|
+
var childDestPath = path.join(destPath, filename);
|
|
102
|
+
var type = fs.lstatSync(childSrcPath).isDirectory() ? "directory" : "file";
|
|
103
|
+
if(!settings.filter(childSrcPath, type))
|
|
104
|
+
return;
|
|
105
|
+
if (type == "directory") {
|
|
106
|
+
copyDirSync0(childSrcPath, childDestPath, settings);
|
|
107
|
+
} else {
|
|
108
|
+
fs.copyFileSync(childSrcPath, childDestPath, settings.overwrite ? 0 : fs.constants.COPYFILE_EXCL);
|
|
109
|
+
if(!settings.preserveFileDate)
|
|
110
|
+
fs.futimesSync(childDestPath, Date.now(), Date.now());
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true;
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
copyDirSync.options = {
|
|
119
|
+
overwrite: true,
|
|
120
|
+
preserveFileDate: true,
|
|
121
|
+
filter: function(filepath, type) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const copyFileSync = (source, target)=>{
|
|
127
|
+
|
|
128
|
+
let targetFile = target;
|
|
129
|
+
|
|
130
|
+
// If target is a directory, a new file with the same name will be created
|
|
131
|
+
if (fs.existsSync(target)) {
|
|
132
|
+
if (fs.lstatSync(target).isDirectory()) {
|
|
133
|
+
targetFile = path.join(target, path.basename(source));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const copyFolderRecursiveSync = (source, target) => {
|
|
141
|
+
let files = [];
|
|
142
|
+
|
|
143
|
+
// Check if folder needs to be created or integrated
|
|
144
|
+
let targetFolder = target;// path.join(target);
|
|
145
|
+
if (!fs.existsSync(targetFolder)) {
|
|
146
|
+
fs.mkdirSync(targetFolder);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Copy
|
|
150
|
+
if (fs.lstatSync(source).isDirectory()) {
|
|
151
|
+
files = fs.readdirSync(source);
|
|
152
|
+
files.forEach(function(file) {
|
|
153
|
+
let curSource = path.join(source, file);
|
|
154
|
+
if (fs.lstatSync(curSource).isDirectory()) {
|
|
155
|
+
copyFolderRecursiveSync(curSource, targetFolder);
|
|
156
|
+
} else {
|
|
157
|
+
copyFileSync(curSource, targetFolder);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const removeDir = function(path) {
|
|
164
|
+
if (fs.existsSync(path)) {
|
|
165
|
+
const files = fs.readdirSync(path)
|
|
166
|
+
|
|
167
|
+
if (files.length > 0) {
|
|
168
|
+
files.forEach(function(filename) {
|
|
169
|
+
if (fs.statSync(path + "/" + filename).isDirectory()) {
|
|
170
|
+
removeDir(path + "/" + filename)
|
|
171
|
+
} else {
|
|
172
|
+
fs.unlinkSync(path + "/" + filename)
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
fs.rmdirSync(path)
|
|
176
|
+
} else {
|
|
177
|
+
fs.rmdirSync(path)
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
console.log("Directory path not found.")
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
export {getLocalFileDirectory, validateFileDirectory, onSaveSpyneFileToDir,checkIfFolderExists, checkIfFileExists, copyFolderRecursiveSync, removeDir, copyDirSync}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
const {expect} = chai;
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
import SpyneAppCreator from '../src/spyne-app-creator.js';
|
|
6
|
+
|
|
7
|
+
const appArgsFalseArr = [ '/usr/local/bin/node', '/usr/local/bin/spyne-cli', 'create-app'];
|
|
8
|
+
const appArgsTrueArr = [ '/usr/local/bin/node', '/usr/local/bin/spyne-cli', 'create-app', 'myapp'];
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
describe('should test app creation methods', () => {
|
|
12
|
+
|
|
13
|
+
it('should run create app false', () => {
|
|
14
|
+
let {createAppBool, folderName} = SpyneAppCreator.checkArgs(appArgsFalseArr);
|
|
15
|
+
expect(createAppBool).to.be.true;
|
|
16
|
+
expect(folderName).to.eq(undefined);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should run create app true', () => {
|
|
20
|
+
let {createAppBool, folderName} = SpyneAppCreator.checkArgs(appArgsTrueArr);
|
|
21
|
+
expect(createAppBool).to.be.true;
|
|
22
|
+
expect(folderName).to.eq('myapp');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return directory exists bool true', ()=>{
|
|
26
|
+
let folderName = 'utils';
|
|
27
|
+
let currentPath = path.resolve('./src');
|
|
28
|
+
const appDir = `${currentPath}/${folderName}`;
|
|
29
|
+
const dirAlreadyExistsBool = SpyneAppCreator.checkIfDirectoryExists(appDir);
|
|
30
|
+
expect(dirAlreadyExistsBool).to.equal(true);
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should return directory exists bool false', ()=>{
|
|
34
|
+
let folderName = 'dir-does-not-exist';
|
|
35
|
+
let currentPath = path.resolve('./src');
|
|
36
|
+
const appDir = `${currentPath}/${folderName}`;
|
|
37
|
+
const dirAlreadyExistsBool = SpyneAppCreator.checkIfDirectoryExists(appDir);
|
|
38
|
+
expect(dirAlreadyExistsBool).to.equal(false);
|
|
39
|
+
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should return folder name is undefined error', ()=>{
|
|
43
|
+
const appPath = path.resolve('./src');
|
|
44
|
+
const errorCheck = SpyneAppCreator.checkForErrors(appPath);
|
|
45
|
+
const folderNameMissingErrCheck = String(errorCheck).indexOf('Please add a folder name!')>=1;
|
|
46
|
+
expect(folderNameMissingErrCheck).to.be.true;
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should return app folder already exists error', ()=>{
|
|
50
|
+
|
|
51
|
+
const folder = 'h-world-new';
|
|
52
|
+
const appPath = path.resolve('./src');
|
|
53
|
+
const appSrc = `${appPath}/hello-world-app-source`
|
|
54
|
+
const appDest = `${appPath}/${folder}`
|
|
55
|
+
const errorCheck = SpyneAppCreator.checkForErrors(appPath, folder);
|
|
56
|
+
const hasAppExistsErr = String(errorCheck).indexOf("App folder already exists!")>=1;
|
|
57
|
+
expect(hasAppExistsErr).to.be.true;
|
|
58
|
+
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
});
|
|
@@ -5,10 +5,11 @@ import {AnswersData} from '../mocks/answers.js';
|
|
|
5
5
|
const {answersArr} = AnswersData;
|
|
6
6
|
import R from 'ramda';
|
|
7
7
|
import fs from 'fs';
|
|
8
|
+
import path from 'path';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
import {onSaveSpyneFileToDir} from '../../src/utils/file-utils.js';
|
|
12
|
+
import {onSaveSpyneFileToDir, copyDirSync, removeDir} from '../../src/utils/file-utils.js';
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
const getAnswersByFileType = (fileType) => R.compose(R.head, R.filter(R.propEq('fileType', fileType)))(answersArr)
|
|
@@ -67,4 +68,19 @@ describe('should test saving to file', () => {
|
|
|
67
68
|
|
|
68
69
|
});
|
|
69
70
|
|
|
71
|
+
it('should copy a folder recursively', ()=>{
|
|
72
|
+
const folder = 'h-world-new';
|
|
73
|
+
|
|
74
|
+
const appPath = path.resolve('./src');
|
|
75
|
+
const appSrc = `${appPath}/hello-world-app-source`
|
|
76
|
+
const appDest = `${appPath}/${folder}`
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
removeDir(appDest);
|
|
80
|
+
const copiedFiles = copyDirSync(appSrc, appDest);
|
|
81
|
+
expect(copiedFiles).to.be.true;
|
|
82
|
+
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
|
|
70
86
|
});
|
package/index-cli.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fsPromises from "fs/promises";
|
|
6
|
-
import R from 'ramda';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const args = process.argv;
|
|
10
|
-
|
|
11
|
-
const methodStr = args.length>=3 ? args[2] : 'empty';
|
|
12
|
-
const undefinedFn = async ()=>console.log('params are undefined.');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const deleteFile = async (filePath) => {
|
|
16
|
-
try {
|
|
17
|
-
await fsPromises.unlink(filePath);
|
|
18
|
-
//console.log('Successfully removed file!');
|
|
19
|
-
} catch (err) {
|
|
20
|
-
console.log(err);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function getFiles(dir) {
|
|
25
|
-
return fs.readdirSync(dir).flatMap((item) => {
|
|
26
|
-
const path = `${dir}/${item}`;
|
|
27
|
-
if (fs.statSync(path).isDirectory()) {
|
|
28
|
-
return getFiles(path);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return path;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const resetAppDir = ()=>{
|
|
36
|
-
|
|
37
|
-
const appDir = path.resolve('./', 'src/app');
|
|
38
|
-
const gitKeepRe = /(.*\/)(.gitkeep)/g;
|
|
39
|
-
const readFilesArr = R.compose(R.reject(R.test(gitKeepRe)))(getFiles(appDir));
|
|
40
|
-
readFilesArr.forEach(deleteFile);
|
|
41
|
-
console.log('app dir is reset');
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const methodHash = {
|
|
48
|
-
resetAppDir
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const methodFn = methodHash[methodStr] || undefinedFn;
|
|
53
|
-
|
|
54
|
-
methodFn();
|
|
55
|
-
|
|
56
|
-
|