Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
1fced430
Unverified
Commit
1fced430
authored
Sep 27, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding installer script to un ignore the package-lock.json file from npm
parent
410fab4d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
0 deletions
+74
-0
InstallCommand.php
Modules/Core/Console/InstallCommand.php
+1
-0
UnignorePackageLock.php
...s/Core/Console/Installers/Scripts/UnignorePackageLock.php
+73
-0
No files found.
Modules/Core/Console/InstallCommand.php
View file @
1fced430
...
@@ -67,6 +67,7 @@ class InstallCommand extends Command
...
@@ -67,6 +67,7 @@ class InstallCommand extends Command
\Modules\Core\Console\Installers\Scripts\ModuleAssets
::
class
,
\Modules\Core\Console\Installers\Scripts\ModuleAssets
::
class
,
\Modules\Core\Console\Installers\Scripts\ThemeAssets
::
class
,
\Modules\Core\Console\Installers\Scripts\ThemeAssets
::
class
,
\Modules\Core\Console\Installers\Scripts\UnignoreComposerLock
::
class
,
\Modules\Core\Console\Installers\Scripts\UnignoreComposerLock
::
class
,
\Modules\Core\Console\Installers\Scripts\UnignorePackageLock
::
class
,
\Modules\Core\Console\Installers\Scripts\SetInstalledFlag
::
class
,
\Modules\Core\Console\Installers\Scripts\SetInstalledFlag
::
class
,
])
->
install
(
$this
);
])
->
install
(
$this
);
...
...
Modules/Core/Console/Installers/Scripts/UnignorePackageLock.php
0 → 100644
View file @
1fced430
<?php
namespace
Modules\Core\Console\Installers\Scripts
;
use
Illuminate\Console\Command
;
use
Modules\Core\Console\Installers\SetupScript
;
class
UnignorePackageLock
implements
SetupScript
{
const
PACKAGE_LOCK
=
'package-lock.json'
;
/**
* Fire the install script
*
* @param Command $command
* @return mixed
*/
public
function
fire
(
Command
$command
)
{
$gitignorePath
=
base_path
(
'.gitignore'
);
if
(
!
$this
->
gitignoreContainsPackageLock
(
$gitignorePath
))
{
return
;
}
$removePackageLock
=
$command
->
confirm
(
'Do you want to remove package-lock.json from .gitignore ?'
,
true
);
if
(
$removePackageLock
)
{
$out
=
$this
->
getGitignoreLinesButPackageLock
(
$gitignorePath
);
$this
->
writeNewGitignore
(
$gitignorePath
,
$out
);
}
}
/**
* @param $gitignorePath
* @return bool
*/
private
function
gitignoreContainsPackageLock
(
$gitignorePath
)
{
return
file_exists
(
$gitignorePath
)
&&
strpos
(
file_get_contents
(
$gitignorePath
),
self
::
PACKAGE_LOCK
)
!==
false
;
}
/**
* @param $gitignorePath
* @return array
*/
private
function
getGitignoreLinesButPackageLock
(
$gitignorePath
)
{
$data
=
file
(
$gitignorePath
);
$out
=
[];
foreach
(
$data
as
$line
)
{
if
(
trim
(
$line
)
!==
self
::
PACKAGE_LOCK
)
{
$out
[]
=
$line
;
}
}
return
$out
;
}
/**
* @param $gitignorePath
* @param $out
*/
private
function
writeNewGitignore
(
$gitignorePath
,
$out
)
{
$fp
=
fopen
(
$gitignorePath
,
'wb+'
);
flock
(
$fp
,
LOCK_EX
);
foreach
(
$out
as
$line
)
{
fwrite
(
$fp
,
$line
);
}
flock
(
$fp
,
LOCK_UN
);
fclose
(
$fp
);
}
}
Write
Preview
Markdown
is supported
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