Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Toolchain
sgc
Commits
29326400
Commit
29326400
authored
Aug 31, 2018
by
Philipp Nowinski
Browse files
[BUGFIX] prevent zombie tasks
parent
fdc1e9cb
Changes
10
Hide whitespace changes
Inline
Side-by-side
core/logger.js
View file @
29326400
...
...
@@ -95,7 +95,7 @@ module.exports = class Logger {
sound
:
true
,
wait
:
false
}
);
);
}
}
...
...
core/run.js
View file @
29326400
...
...
@@ -15,14 +15,22 @@ class Run {
*/
constructor
()
{
process
.
chdir
(
'
..
'
);
this
.
_start
();
}
/**
* Start the task runner
*/
async
_start
()
{
let
taskArgument
=
Run
.
getTaskName
();
let
taskNames
=
taskArgument
.
split
(
'
:
'
);
if
(
settings
.
tasks
.
hasOwnProperty
(
taskNames
[
0
]))
{
let
task
=
settings
.
tasks
[
taskNames
[
0
]]();
new
task
().
run
(
taskNames
[
1
]
||
null
);
await
new
task
().
run
(
taskNames
[
1
]
||
null
);
}
else
{
logger
.
error
(
`Task
${
chalk
.
bold
(
taskNames
[
0
])}
is not defined`
);
}
process
.
exit
();
}
/**
...
...
core/tasks/build.js
View file @
29326400
...
...
@@ -12,15 +12,20 @@ module.exports = class Build extends Task {
* @override
*/
async
run
()
{
let
images
=
this
.
_settings
.
tasks
.
images
();
let
css
=
this
.
_settings
.
tasks
.
css
();
let
js
=
this
.
_settings
.
tasks
.
js
();
this
.
_config
.
extensions
.
forEach
(
_extension
=>
{
settings
.
setExtension
(
_extension
);
new
images
().
run
();
new
css
().
run
();
new
js
().
run
();
return
new
Promise
(
async
resolve
=>
{
let
images
=
this
.
_settings
.
tasks
.
images
();
let
css
=
this
.
_settings
.
tasks
.
css
();
let
js
=
this
.
_settings
.
tasks
.
js
();
await
Promise
.
all
(
this
.
_config
.
extensions
.
map
(
async
_extension
=>
{
settings
.
setExtension
(
_extension
);
let
tasks
=
[];
tasks
.
push
(
new
images
().
run
());
tasks
.
push
(
new
css
().
run
());
tasks
.
push
(
new
js
().
run
());
await
Promise
.
all
(
tasks
);
}));
resolve
();
});
}
};
core/tasks/css.js
View file @
29326400
...
...
@@ -29,28 +29,31 @@ module.exports = class Css extends Task {
* @override
*/
async
run
(
_subTask
=
null
)
{
const
steps
=
[];
this
.
getElapsed
=
hirestime
();
if
(
_subTask
)
{
if
(
_subTask
===
'
qa
'
)
{
steps
.
push
(
this
.
_runQa
());
}
else
if
(
_subTask
===
'
compile
'
)
{
steps
.
push
(
this
.
_runCompile
());
}
else
if
(
_subTask
===
'
svg
'
)
{
steps
.
push
(
this
.
_svg
());
}
else
if
(
_subTask
===
'
abovethefold
'
)
{
steps
.
push
(
this
.
_abovethefold
());
return
new
Promise
(
async
resolve
=>
{
const
steps
=
[];
this
.
getElapsed
=
hirestime
();
if
(
_subTask
)
{
if
(
_subTask
===
'
qa
'
)
{
steps
.
push
(
this
.
_runQa
());
}
else
if
(
_subTask
===
'
compile
'
)
{
steps
.
push
(
this
.
_runCompile
());
}
else
if
(
_subTask
===
'
svg
'
)
{
steps
.
push
(
this
.
_svg
());
}
else
if
(
_subTask
===
'
abovethefold
'
)
{
steps
.
push
(
this
.
_abovethefold
());
}
else
{
this
.
_logTaskNotDefined
(
`css:
${
_subTask
}
`
);
}
}
else
{
this
.
_logTaskNotDefined
(
`css:
${
_subTask
}
`
);
}
}
else
{
if
(
this
.
_config
.
cssPipeline
.
qa
)
{
steps
.
push
(
this
.
_runQa
());
if
(
this
.
_config
.
cssPipeline
.
qa
)
{
steps
.
push
(
this
.
_runQa
());
}
steps
.
push
(
this
.
_runCompile
());
}
steps
.
push
(
this
.
_runCompile
()
);
}
await
Promise
.
all
(
steps
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
css
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
await
Promise
.
all
(
steps
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
css
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
resolve
(
);
}
);
}
/**
...
...
@@ -141,6 +144,7 @@ module.exports = class Css extends Task {
importer
:
globImporter
()
});
}
catch
(
_error
)
{
console
.
log
(
_error
);
return
this
.
_logger
.
error
(
_error
.
stack
);
}
...
...
core/tasks/images.js
View file @
29326400
...
...
@@ -21,21 +21,31 @@ module.exports = class Watch extends Task {
* @override
*/
async
run
(
_subTask
)
{
this
.
getElapsed
=
hirestime
();
if
(
_subTask
===
'
uploaded
'
)
{
this
.
_optimizeUploadedImages
();
}
else
{
this
.
_optimizeExtensionImages
();
}
return
new
Promise
(
async
resolve
=>
{
this
.
getElapsed
=
hirestime
();
if
(
_subTask
===
'
uploaded
'
)
{
await
this
.
_optimizeUploadedImages
();
}
else
{
await
this
.
_optimizeExtensionImages
();
}
resolve
();
});
}
/**
* Optimize all user uploaded images
*/
async
_optimizeUploadedImages
()
{
this
.
_config
.
images
.
optimize
.
forEach
(
async
imagesPath
=>
{
const
files
=
await
globby
([
`
${
imagesPath
}
/**/*.{png,jpg,gif,svg}`
]);
this
.
_optimize
(
files
);
return
new
Promise
(
async
resolve
=>
{
let
tasks
=
[];
this
.
_config
.
images
.
optimize
.
forEach
(
async
imagesPath
=>
{
tasks
.
push
(
new
Promise
(
async
resolve
=>
{
const
files
=
await
globby
([
`
${
imagesPath
}
/**/*.{png,jpg,gif,svg}`
]);
await
this
.
_optimize
(
files
);
resolve
();
}));
});
await
Promise
.
all
(
tasks
);
});
}
...
...
@@ -43,10 +53,13 @@ module.exports = class Watch extends Task {
* Optimize images on extension level
*/
async
_optimizeExtensionImages
()
{
const
imagesPath
=
this
.
_getFullPath
(
this
.
_config
.
directories
.
images
);
const
files
=
await
globby
([
`
${
imagesPath
}
/**/*.{png,jpg,gif,svg}`
]);
await
this
.
_optimize
(
files
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
images
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
return
new
Promise
(
async
resolve
=>
{
const
imagesPath
=
this
.
_getFullPath
(
this
.
_config
.
directories
.
images
);
const
files
=
await
globby
([
`
${
imagesPath
}
/**/*.{png,jpg,gif,svg}`
]);
await
this
.
_optimize
(
files
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
images
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
resolve
();
});
}
/**
...
...
core/tasks/js.js
View file @
29326400
...
...
@@ -22,26 +22,29 @@ module.exports = class Js extends Task {
* @override
*/
async
run
(
_subTask
=
null
)
{
this
.
getElapsed
=
hirestime
();
const
steps
=
[];
if
(
_subTask
)
{
// if _subTask is set, just execute that one task
if
(
_subTask
===
'
qa
'
)
{
steps
.
push
(
this
.
_runQa
());
}
else
if
(
_subTask
===
'
compile
'
)
{
steps
.
push
(
this
.
_runCompile
());
return
new
Promise
(
async
resolve
=>
{
this
.
getElapsed
=
hirestime
();
const
steps
=
[];
if
(
_subTask
)
{
// if _subTask is set, just execute that one task
if
(
_subTask
===
'
qa
'
)
{
steps
.
push
(
this
.
_runQa
());
}
else
if
(
_subTask
===
'
compile
'
)
{
steps
.
push
(
this
.
_runCompile
());
}
else
{
this
.
_logTaskNotDefined
(
`js:
${
_subTask
}
`
);
}
}
else
{
this
.
_logTaskNotDefined
(
`js:
${
_subTask
}
`
);
}
}
else
{
// otherwise execute everything
if
(
this
.
_config
.
jsPipeline
.
qa
)
{
steps
.
push
(
this
.
_runQa
());
// otherwise execute everything
if
(
this
.
_config
.
jsPipeline
.
qa
)
{
steps
.
push
(
this
.
_runQa
());
}
steps
.
push
(
this
.
_runCompile
());
}
steps
.
push
(
this
.
_runCompile
()
);
}
await
Promise
.
all
(
steps
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
js
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
await
Promise
.
all
(
steps
);
this
.
_logger
.
info
(
`Task
${
chalk
.
bold
(
'
js
'
)}
finished after
${
this
.
getElapsed
(
hirestime
.
S
)}
s`
);
resolve
(
);
}
);
}
/**
...
...
core/tasks/open.js
View file @
29326400
...
...
@@ -13,28 +13,33 @@ module.exports = class Open extends Task {
*
* @override
*/
run
()
{
if
(
yargs
.
_
.
length
>
1
)
{
if
(
this
.
_config
.
hasOwnProperty
(
'
open
'
))
{
// eslint-disable-next-line
let
sites
=
yargs
.
_
[
1
];
if
(
this
.
_config
.
open
.
hasOwnProperty
(
sites
))
{
let
index
=
0
;
this
.
_config
.
open
[
sites
].
forEach
(
site
=>
{
setTimeout
(()
=>
{
open
(
site
);
// eslint-disable-next-line
},
100
*
index
++
);
});
async
run
()
{
return
new
Promise
(
async
resolve
=>
{
if
(
yargs
.
_
.
length
>
1
)
{
if
(
this
.
_config
.
hasOwnProperty
(
'
open
'
))
{
// eslint-disable-next-line
let
sites
=
yargs
.
_
[
1
];
if
(
this
.
_config
.
open
.
hasOwnProperty
(
sites
))
{
let
index
=
0
;
this
.
_config
.
open
[
sites
].
forEach
(
site
=>
{
setTimeout
(()
=>
{
open
(
site
);
if
(
this
.
_config
.
open
[
sites
].
length
===
index
-
1
)
{
resolve
();
}
// eslint-disable-next-line
},
100
*
index
++
);
});
}
else
{
this
.
_logger
.
error
(
`The desired entry
${
chalk
.
bold
(
sites
)}
could not be found in your .sgc-config.json!`
);
}
}
else
{
this
.
_logger
.
error
(
`The desired
ent
r
y
${
chalk
.
bold
(
sites
)}
co
uld not be found in
your .sgc-config.json
!`
);
this
.
_logger
.
error
(
'
You have curr
ent
l
y
no
sites co
nfigured (set the "open" property inside
your .sgc-config.json
)!
'
);
}
}
else
{
this
.
_logger
.
error
(
'
You have currently no sites configured (set the "open" property inside your .sgc-config.json)
!
'
);
this
.
_logger
.
error
(
'
Please specify which site you want to open
!
'
);
}
}
else
{
this
.
_logger
.
error
(
'
Please specify which site you want to open!
'
);
}
});
}
};
core/tasks/releaseExtension.js
View file @
29326400
...
...
@@ -15,37 +15,42 @@ module.exports = class Open extends Task {
* @override
*/
async
run
()
{
if
(
typeof
yargs
.
ext
===
'
undefined
'
)
{
this
.
_logger
.
error
(
'
Please specify the extension you want to release!
'
);
}
else
if
(
!
fs
.
existsSync
(
`
${
this
.
_config
.
directories
.
basePath
}${
yargs
.
ext
}
`
))
{
this
.
_logger
.
error
(
`Could not find extension in
${
yargs
.
ext
}
!`
);
}
else
{
const
answers
=
await
inquirer
.
prompt
([
{
type
:
'
confirm
'
,
name
:
'
major
'
,
message
:
'
Does the user need to apply changes to the code base or configuration after installing your update?
'
},
{
type
:
'
confirm
'
,
name
:
'
feature
'
,
message
:
'
Did you develop new features?
'
,
when
:
answers
=>
!
answers
.
major
return
new
Promise
(
async
resolve
=>
{
if
(
typeof
yargs
.
ext
===
'
undefined
'
)
{
this
.
_logger
.
error
(
'
Please specify the extension you want to release!
'
);
resolve
();
}
else
if
(
!
fs
.
existsSync
(
`
${
this
.
_config
.
directories
.
basePath
}${
yargs
.
ext
}
`
))
{
this
.
_logger
.
error
(
`Could not find extension in
${
yargs
.
ext
}
!`
);
resolve
();
}
else
{
const
answers
=
await
inquirer
.
prompt
([
{
type
:
'
confirm
'
,
name
:
'
major
'
,
message
:
'
Does the user need to apply changes to the code base or configuration after installing your update?
'
},
{
type
:
'
confirm
'
,
name
:
'
feature
'
,
message
:
'
Did you develop new features?
'
,
when
:
answers
=>
!
answers
.
major
}
]);
try
{
let
pathToComposer
=
`
${
process
.
cwd
()}
/
${
this
.
_config
.
directories
.
basePath
}
/
${
yargs
.
ext
}
/composer.json`
,
pathToExtEmconf
=
`
${
process
.
cwd
()}
/
${
this
.
_config
.
directories
.
basePath
}
/
${
yargs
.
ext
}
/ext_emconf.php`
,
composerFile
=
require
(
pathToComposer
),
currentVersion
=
composerFile
.
version
,
nextVersionNumber
=
this
.
_getNextVersionNumber
(
answers
,
currentVersion
);
this
.
_updateComposerJson
(
currentVersion
,
nextVersionNumber
,
pathToComposer
).
then
(()
=>
{
this
.
_updateExtEmconf
(
currentVersion
,
nextVersionNumber
,
pathToExtEmconf
)
});
}
catch
(
error
)
{
this
.
_logger
.
error
(
'
Could not open file!
'
);
}
]);
try
{
let
pathToComposer
=
`
${
process
.
cwd
()}
/
${
this
.
_config
.
directories
.
basePath
}
/
${
yargs
.
ext
}
/composer.json`
,
pathToExtEmconf
=
`
${
process
.
cwd
()}
/
${
this
.
_config
.
directories
.
basePath
}
/
${
yargs
.
ext
}
/ext_emconf.php`
,
composerFile
=
require
(
pathToComposer
),
currentVersion
=
composerFile
.
version
,
nextVersionNumber
=
this
.
_getNextVersionNumber
(
answers
,
currentVersion
);
this
.
_updateComposerJson
(
currentVersion
,
nextVersionNumber
,
pathToComposer
).
then
(()
=>
{
this
.
_updateExtEmconf
(
currentVersion
,
nextVersionNumber
,
pathToExtEmconf
)
});
}
catch
(
error
)
{
this
.
_logger
.
error
(
'
Could not open file!
'
);
resolve
();
}
}
}
);
}
/**
...
...
core/tasks/server.js
View file @
29326400
...
...
@@ -13,19 +13,21 @@ module.exports = class Server extends Task {
* @override
*/
async
run
(
_subTask
=
null
)
{
browserSync
({
proxy
:
this
.
getUrl
(),
middleware
:
(
req
,
res
,
next
)
=>
{
var
conjunction
;
if
(
req
.
url
.
match
(
/
\?
/
))
{
conjunction
=
'
&
'
;
}
else
{
conjunction
=
'
?
'
;
}
req
.
url
=
req
.
url
+
conjunction
+
this
.
_config
.
browsersync
.
urlparams
;
next
();
},
open
:
typeof
argv
.
s
===
'
undefined
'
?
'
local
'
:
false
return
new
Promise
(
resolve
=>
{
browserSync
({
proxy
:
this
.
getUrl
(),
middleware
:
(
req
,
res
,
next
)
=>
{
var
conjunction
;
if
(
req
.
url
.
match
(
/
\?
/
))
{
conjunction
=
'
&
'
;
}
else
{
conjunction
=
'
?
'
;
}
req
.
url
=
req
.
url
+
conjunction
+
this
.
_config
.
browsersync
.
urlparams
;
next
();
},
open
:
typeof
argv
.
s
===
'
undefined
'
?
'
local
'
:
false
});
});
}
...
...
core/tasks/watch.js
View file @
29326400
...
...
@@ -15,8 +15,10 @@ module.exports = class Watch extends Task {
* @override
*/
async
run
()
{
this
.
_watchCss
();
this
.
_watchJs
();
return
new
Promise
(
resolve
=>
{
this
.
_watchCss
();
this
.
_watchJs
();
});
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment