Skip to content

Commit

Permalink
Merge pull request #122 from clarlars/clarlars-empty-app-designer
Browse files Browse the repository at this point in the history
Create 'grunt empty' task to create an empty app-designer
  • Loading branch information
wbrunette authored Jul 30, 2019
2 parents 4a2dc4c + 5c63b90 commit 20c67cb
Show file tree
Hide file tree
Showing 6 changed files with 588 additions and 194 deletions.
95 changes: 95 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ module.exports = function (grunt) {
deviceMount: '/sdcard/opendatakit',
// The mount point of the device for odk collect forms.
formMount: '/sdcard/odk/forms',
assetsDir: 'app/config/assets',
// The directory where the 'tables' directory containing the tableId
// directories lives.
tablesDir: 'app/config/tables',
dataDir: 'app/data',
// Where the templates for a new tableId folder lives. i.e. if you want
// to add a table, the contents of this directory would be copied to
// tablesDir/tableId.
Expand Down Expand Up @@ -2066,4 +2068,97 @@ var zipAllFiles = function( destZipFile, filesList, completionFn ) {
if (set === "off") grunt.option("force", false);
if (set === "restore") grunt.option("force", previous_force_state);
});

function deleteFilesList(grunt, workingDir, toBeDeleted) {
toBeDeleted.forEach(function (fileName) {
var dirToUse = workingDir;
if (!dirToUse.endsWith('/')) {
dirToUse = dirToUse + '/';
}

var src = dirToUse + fileName;
grunt.log.writeln('deleteTopLevel: deleting ' + src);
grunt.file.delete(src, {force: true});
});
}

var deleteTopLevel = function(grunt, dirToDelete) {
var toBeDeleted = grunt.file.expand(
{cwd: dirToDelete },
'*');
deleteFilesList(grunt, dirToDelete, toBeDeleted);
};

grunt.registerTask(
'empty',
'Remove unnecessary files to make an empty app-designer',
function() {

deleteTopLevel(grunt, tablesConfig.tablesDir);
deleteTopLevel(grunt, tablesConfig.assetsDir + '/csv');
deleteTopLevel(grunt, tablesConfig.dataDir);
deleteTopLevel(grunt, tablesConfig.appDir + '/' + tablesConfig.outputCsvDir);
deleteTopLevel(grunt, tablesConfig.appDir + '/' + tablesConfig.outputDbDir);
deleteTopLevel(grunt, tablesConfig.appDir + '/' + tablesConfig.outputDebugDir);
deleteTopLevel(grunt, tablesConfig.appDir + '/' + tablesConfig.outputPropsDir);

var assetFilesToDelete = grunt.file.expand(
{filter: 'isFile',
cwd: tablesConfig.assetsDir },
'*.*',
'!favicon.ico',
'css/**',
'!css/odk-survey.css',
'csv/**',
'framework/**',
'!**/*.clean.*',
'!framework/forms/framework.clean/**',
'img/**',
'!img/play.png',
'!img/form_logo.png',
'!img/backup.png',
'!img/advance.png',
'!img/little_arrow.png',
'js/**',
'!js/util.js',
'!libs/**',
'!commonDefinitions.js',
'!index.html',
'!framework/forms/framework/formDef.json',
'!framework/forms/framework/framework.xlsx',
'!framework/frameworkDefinitions.js'
);

// Delete unnecessary files
deleteFilesList(grunt, tablesConfig.assetsDir, assetFilesToDelete);

// Find all instances of things with .clean in it
var cleanFilesToDelete = grunt.file.expand(
{ cwd: tablesConfig.assetsDir,
filter: 'isFile'},
'**/*.clean.*',
'**/*.clean/**'
);

// Copy *.clean files over to the correct directory
cleanFilesToDelete.forEach(function(fileName) {
var src = tablesConfig.assetsDir + '/' + fileName;
var dest = src;
var dest = dest.replace(new RegExp('.clean', 'g'), '');
grunt.log.writeln('copy ' + src + ' to ' + dest);
grunt.file.copy(src, dest);
});

// Delete all of the .clean files now
deleteFilesList(grunt, tablesConfig.assetsDir, cleanFilesToDelete);

// Delete all of the other framework directories
var assetsDirToDelete = grunt.file.expand(
{cwd: tablesConfig.assetsDir + '/framework/forms'},
'*',
'*.*',
'!framework/**');

deleteFilesList(grunt, tablesConfig.assetsDir + '/framework/forms', assetsDirToDelete);
});
};
18 changes: 17 additions & 1 deletion app/config/assets/commonDefinitions.clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ window.odkCommonDefinitions = {
"locale": {
"text": {
"en": "English",
"hi": "अंग्रेज़ी ",
"hi": "अंग्रेज़ी",
"es": "Inglés",
"default": "English"
}
}
Expand All @@ -23,12 +24,27 @@ window.odkCommonDefinitions = {
"text": {
"en": "Hindi",
"hi": "हिंदी",
"es": "Hindi",
"default": "Hindi"
}
}
},
"_row_num": 8,
"name": "hi"
},
{
"display": {
"locale": {
"text": {
"en": "Spanish",
"hi": "स्पेनिश",
"es": "Español",
"default": "Spanish"
}
}
},
"_row_num": 9,
"name": "es"
}
]
},
Expand Down
Loading

0 comments on commit 20c67cb

Please sign in to comment.