From 441197be4e9e705abfdf80a7404342623b46616f Mon Sep 17 00:00:00 2001 From: Artemy Date: Sat, 10 Jun 2023 21:48:23 +0300 Subject: [PATCH] feat: cimengine project init --- .npmignore | 133 +++++++++++++++++++++++ package.json | 8 +- projectInit.js | 1 - CountryFixer.js => tools/CountryFixer.js | 0 GeoBuilder.js => tools/GeoBuilder.js | 0 tools/ProjectInit.js | 62 +++++++++++ 6 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 .npmignore delete mode 100644 projectInit.js rename CountryFixer.js => tools/CountryFixer.js (100%) rename GeoBuilder.js => tools/GeoBuilder.js (100%) create mode 100644 tools/ProjectInit.js diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..86d515c --- /dev/null +++ b/.npmignore @@ -0,0 +1,133 @@ +# npm only +file_templates/ +# npm only + + + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/package.json b/package.json index 1fa46b5..dceeca4 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "cimengine-build-tools", - "version": "1.0.0", + "version": "1.1.0", "description": "Geojson data processing tools for CIMEngine", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "bin": { - "cimengine-build": "./GeoBuilder.js", - "cimengine-country-fix": "./CountryFixer.js", - "cimengine-init": "./ProjectInit.js" + "cimengine-build": "./tools/GeoBuilder.js", + "cimengine-country-fix": "./tools/CountryFixer.js", + "cimengine-init": "./tools/ProjectInit.js" }, "repository": { "type": "git", diff --git a/projectInit.js b/projectInit.js deleted file mode 100644 index 593252c..0000000 --- a/projectInit.js +++ /dev/null @@ -1 +0,0 @@ -//todo diff --git a/CountryFixer.js b/tools/CountryFixer.js similarity index 100% rename from CountryFixer.js rename to tools/CountryFixer.js diff --git a/GeoBuilder.js b/tools/GeoBuilder.js similarity index 100% rename from GeoBuilder.js rename to tools/GeoBuilder.js diff --git a/tools/ProjectInit.js b/tools/ProjectInit.js new file mode 100644 index 0000000..97919c4 --- /dev/null +++ b/tools/ProjectInit.js @@ -0,0 +1,62 @@ +#!/usr/bin/env node + +const yargs = require("yargs/yargs"); +const { hideBin } = require("yargs/helpers"); +const args = yargs(hideBin(process.argv)).argv; + +const fs = require("fs"); +const path = require("path"); + +let geojsonTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "geojson.geojson") +); + +let configTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "config.yaml") +); + +let propertiesTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "properties.yaml") +); + +let layersTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "layers.yaml") +); + +let countriesTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "countries.json") +); + +let roadSizesTemplate = fs.readFileSync( + path.join(__dirname, "file_templates", "roadSizes.json") +); + +let name = args.name || "cime-project"; + +let currpath = path.join(process.cwd(), name, "src"); + +fs.mkdirSync(path.join(currpath, "countries"), { recursive: true }); +fs.mkdirSync(path.join(currpath, "nature"), { recursive: true }); +fs.mkdirSync(path.join(currpath, "roads"), { recursive: true }); + +fs.writeFileSync(path.join(currpath, "config.yaml"), configTemplate); +fs.writeFileSync(path.join(currpath, "properties.yaml"), propertiesTemplate); +fs.writeFileSync(path.join(currpath, "layers.yaml"), layersTemplate); +fs.writeFileSync(path.join(currpath, "countries.json"), countriesTemplate); + +fs.writeFileSync(path.join(currpath, "roads", "sizes.json"), roadSizesTemplate); + +let geoTemplateFiles = [ + path.join("roads", "orange.geojson"), + path.join("roads", "white.geojson"), + path.join("roads", "yellow.geojson"), + path.join("nature", "grass.geojson"), + path.join("nature", "sand.geojson"), + path.join("nature", "water.geojson"), +]; + +for (let geoFile of geoTemplateFiles) { + fs.writeFileSync(path.join(currpath, geoFile), geojsonTemplate); +} + +console.log("Done!");