Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocerquone committed Mar 8, 2021
1 parent eca6535 commit ed227fe
Show file tree
Hide file tree
Showing 9 changed files with 1,105 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
}
};
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-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

# 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 variables file
.env
.env.test

# 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

# 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.*
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# graphcms-markdown-migrator

This package aims to help the migration from static markdown files to graphcms for your SSG blog (or website).
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const chalk = require("chalk");
const { buildGqlClient } = require("./utils");

const argv = hideBin(process.argv);

yargs(argv)
.command(
"migrate [path] [url] [token]",
"start the migration of the md files in the specified path.",
(yargs) => {
return yargs
.positional("path", {
describe: "Path of the folder of the md files to migrate.",
})
.option("url", {
alias: "u",
type: "string",
description: "Your graphCMS URL",
})
.option("token", {
alias: "t",
type: "string",
description: "Your graphCMS token",
});
},
async (argv) => {
if (argv.verbose) console.info(`start server on :${argv.port}`);
// serve(argv.port);
if (!argv.path) {
return console.error(chalk.red("You must specify a path"));
}

if (!argv.url) {
return console.error(chalk.red("You must specify your graphcms url"));
}
if (!argv.token) {
return console.error(chalk.red("You must specify your graphcms token"));
}

buildGqlClient(argv.url, argv.token);

console.log(argv);
}
)
.option("verbose", {
alias: "v",
type: "boolean",
description: "Run with verbose logging",
}).argv;
3 changes: 3 additions & 0 deletions migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const migrate = () => {};

module.exports = migrate;
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"md-to-graph": "./index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/giacomocerquone/graphcms-markdown-migrator.git"
Expand All @@ -24,5 +27,16 @@
"bugs": {
"url": "https://github.com/giacomocerquone/graphcms-markdown-migrator/issues"
},
"homepage": "https://github.com/giacomocerquone/graphcms-markdown-migrator#readme"
"homepage": "https://github.com/giacomocerquone/graphcms-markdown-migrator#readme",
"dependencies": {
"chalk": "^4.1.0",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0",
"node-fetch": "^2.6.1",
"prompts": "^2.4.0",
"yargs": "^16.2.0"
},
"devDependencies": {
"eslint": "^7.21.0"
}
}
7 changes: 7 additions & 0 deletions queries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { gql } = require("graphql-request");

const postModelCreation = gql``;

module.exports = {
postModelCreation,
};
27 changes: 27 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { GraphQLClient } = require("graphql-request");
const queries = require("./queries");

let client;

const getGqlClient = () => client;

const buildGqlClient = (endpoint, token) => {
client = new GraphQLClient(endpoint, {
headers: { Authorization: `Bearer ${token}` },
});
};

const createPostModel = async () => {
try {
const data = await client.request(queries.postModelCreation);
console.log(data);
} catch (e) {
console.log(e);
}
};

module.exports = {
getGqlClient,
buildGqlClient,
createPostModel,
};
Loading

0 comments on commit ed227fe

Please sign in to comment.