From 2453c5c8b77030d1b675b2f52c08e244a4a20793 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 30 Nov 2016 17:06:33 -0500 Subject: [PATCH] Eliminate symlinks in repository - shelljs/shx can make them (closes #3545) --- .gitignore | 7 ++++ README.md | 7 ++-- build.js | 55 ++++++++++++++++++---------- css/img | 1 - fixWinSymlinks.bat | 91 ---------------------------------------------- img | 1 - land.html | 1 - test/css | 1 - test/img | 1 - 9 files changed, 46 insertions(+), 119 deletions(-) delete mode 120000 css/img delete mode 100644 fixWinSymlinks.bat delete mode 120000 img delete mode 120000 land.html delete mode 120000 test/css delete mode 120000 test/img diff --git a/.gitignore b/.gitignore index c3fd22f29..c2925d6a7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,10 @@ dist/mapillary-js/ node_modules/ npm-debug.log transifex.auth + +# autogenerated symlinks +land.html +img +css/img +test/css +test/img diff --git a/README.md b/README.md index e035487cb..519c88586 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,9 @@ Come on in, the water's lovely. More help? Ping `jfire` or `bhousel` on: To run the current development version of iD on your own computer: 1. Create a local `git clone` of the project, then `cd` into the project folder -2. (Windows Only) Run `fixWinSymlinks.bat`. This script will prompt for Administrator rights. see also: http://stackoverflow.com/questions/5917249/git-symlinks-in-windows -3. Run `npm install` (this will run the `prepublish` script that builds everything) -4. Run `npm start` -5. Open `http://localhost:8080/` in a web browser +2. Run `npm install` (this will run the `prepublish` script that builds everything) +3. Run `npm start` +4. Open `http://localhost:8080/` in a web browser For guidance on building a packaged version, running tests, and contributing to development, see [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/build.js b/build.js index d50523bc5..5551318e2 100644 --- a/build.js +++ b/build.js @@ -1,15 +1,34 @@ /* eslint-disable no-console */ -var _ = require('lodash'); -var fs = require('fs'); -var path = require('path'); -var glob = require('glob'); -var YAML = require('js-yaml'); -var jsonschema = require('jsonschema'); +const _ = require('lodash'); +const fs = require('fs'); +const glob = require('glob'); +const jsonschema = require('jsonschema'); +const path = require('path'); +const shell = require('shelljs'); +const YAML = require('js-yaml'); + +const fieldSchema = require('./data/presets/schema/field.json'); +const presetSchema = require('./data/presets/schema/preset.json'); +const suggestions = require('name-suggestion-index/name-suggestions.json'); + + +// Create symlinks if necessary.. { 'target': 'source' } +const symlinks = { + 'land.html': 'dist/land.html', + 'img': 'dist/img', + 'css/img': '../dist/img', + 'test/css': '../css', + 'test/img': '../dist/img' +}; + +for (const target of Object.keys(symlinks)) { + if (!shell.test('-L', target)) { + console.log(`Creating symlink: ${target} -> ${symlinks[target]}`); + shell.ln('-sf', symlinks[target], target); + } +} -var fieldSchema = require('./data/presets/schema/field.json'); -var presetSchema = require('./data/presets/schema/preset.json'); -var suggestions = require('name-suggestion-index/name-suggestions.json'); // Translation strings var tstrings = { @@ -20,12 +39,14 @@ var tstrings = { // Start clean -unlink('data/presets/categories.json'); -unlink('data/presets/fields.json'); -unlink('data/presets/presets.json'); -unlink('data/presets.yaml'); -unlink('data/taginfo.json'); -unlink('dist/locales/en.json'); +shell.rm('-f', [ + 'data/presets/categories.json', + 'data/presets/fields.json', + 'data/presets/presets.json', + 'data/presets.yaml', + 'data/taginfo.json', + 'dist/locales/en.json' +]); var categories = generateCategories(); var fields = generateFields(); @@ -54,10 +75,6 @@ fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4)); process.exit(); -function unlink(f) { - try { fs.unlinkSync(f); } catch (e) { /* noop */ } -} - function read(f) { return JSON.parse(fs.readFileSync(f, 'utf8')); } diff --git a/css/img b/css/img deleted file mode 120000 index a5e0e5adb..000000000 --- a/css/img +++ /dev/null @@ -1 +0,0 @@ -../dist/img/ \ No newline at end of file diff --git a/fixWinSymlinks.bat b/fixWinSymlinks.bat deleted file mode 100644 index 6932c6686..000000000 --- a/fixWinSymlinks.bat +++ /dev/null @@ -1,91 +0,0 @@ -@echo. -@echo For converting Git symlink files to Windows file symlinks. -@echo * Run in repository root as Administrator. -@echo * Handling of folder symlinks is not implemented. -@echo * Intended for windows versions Vista and above (Win 7,8) -@echo. -@echo Thanks to: http://stackoverflow.com/a/5930443/1031870 -@echo v1.02 (c) 2015 Robert Benko (Quazistax), License: MIT -@echo. - -@echo off -pushd "%~dp0" -setlocal EnableDelayedExpansion -call :raiseUACIfNotAdmin || exit /B 1 -for /f "tokens=3,*" %%e in ('git ls-files -s ^| findstr /R /C:"^120000"') do ( - call :processFirstLine %%f -) -REM pause -goto :eof - -:processFirstLine -@echo. -@echo FILE: %1 - -dir "%~f1" | find "" >NUL && ( - @echo FILE already is a symlink - goto :eof -) - -for /f "usebackq tokens=*" %%l in ("%~f1") do ( - @echo LINK TO: %%l - - del "%~f1" - if not !ERRORLEVEL! == 0 ( - @echo FAILED: del - goto :eof - ) - - setlocal - call :expandRelative linkto "%1" "%%l" - mklink "%~f1" "!linkto!" - endlocal - if not !ERRORLEVEL! == 0 ( - @echo FAILED: mklink - @echo reverting deletion... - git checkout -- "%~f1" - goto :eof - ) - - git update-index --assume-unchanged "%1" - if not !ERRORLEVEL! == 0 ( - @echo FAILED: git update-index --assume-unchanged - goto :eof - ) - @echo SUCCESS - goto :eof -) -goto :eof - -:: param1 = result variable -:: param2 = reference path from which relative will be resolved -:: param3 = relative path -:expandRelative - pushd . - cd "%~dp2" - set %1=%~f3 - popd -goto :eof - -:raiseUACIfNotAdmin -:: Quick test for Windows generation: UAC aware or not ; all OS before NT4 ignored for simplicity -:: Original from: http://stackoverflow.com/a/14729312/1031870 - -(ver | findstr /IL "5." > NUL || ver | findstr /IL "4." > NUL) && ( - @echo ERROR: Symlinks are not supported on this version of Windows. - exit /B 1 -) - -:: Test if Admin -call net session >NUL 2>&1 -if not !ERRORLEVEL! == 0 ( - :: Start batch again with UAC - echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" - echo UAC.ShellExecute "cmd.exe", "/K ""cd /d %~dp0 && %~s0""", "%~dp0", "runas", 1 >> "%temp%\getadmin.vbs" - @echo Requesting administrative privileges... - "%temp%\getadmin.vbs" - del "%temp%\getadmin.vbs" - exit /B 2 -) -exit /B 0 -goto :eof diff --git a/img b/img deleted file mode 120000 index aab814b92..000000000 --- a/img +++ /dev/null @@ -1 +0,0 @@ -dist/img \ No newline at end of file diff --git a/land.html b/land.html deleted file mode 120000 index 45f5c6cc8..000000000 --- a/land.html +++ /dev/null @@ -1 +0,0 @@ -dist/land.html \ No newline at end of file diff --git a/test/css b/test/css deleted file mode 120000 index d2d7c52c8..000000000 --- a/test/css +++ /dev/null @@ -1 +0,0 @@ -../css \ No newline at end of file diff --git a/test/img b/test/img deleted file mode 120000 index a5e0e5adb..000000000 --- a/test/img +++ /dev/null @@ -1 +0,0 @@ -../dist/img/ \ No newline at end of file