feat: cimengine project init

This commit is contained in:
Artemy 2023-06-10 21:48:23 +03:00
parent 65f6997791
commit 441197be4e
6 changed files with 199 additions and 5 deletions

133
.npmignore Normal file
View file

@ -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.*

View file

@ -1,15 +1,15 @@
{ {
"name": "cimengine-build-tools", "name": "cimengine-build-tools",
"version": "1.0.0", "version": "1.1.0",
"description": "Geojson data processing tools for CIMEngine", "description": "Geojson data processing tools for CIMEngine",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"bin": { "bin": {
"cimengine-build": "./GeoBuilder.js", "cimengine-build": "./tools/GeoBuilder.js",
"cimengine-country-fix": "./CountryFixer.js", "cimengine-country-fix": "./tools/CountryFixer.js",
"cimengine-init": "./ProjectInit.js" "cimengine-init": "./tools/ProjectInit.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -1 +0,0 @@
//todo

62
tools/ProjectInit.js Normal file
View file

@ -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!");